资源简介
简单模拟一个草原生态系统,保持生态平衡。包括动态显示,和统计一段时间内草,羊,狼,鹰的数量,并用曲线图表示。
代码片段和文件信息
#include “stdafx.h“
# include
# include
# include
# include
# include
# include
# include
class blackground
{
private:
int x;
int y;
int m;
int n;
WORD w;
public:
blackground::blackground(int x0int y0int m0int n0WORD w0); //重载blackground()
display1();
display2();
display3();
display4();
display5();
display6();
display8();
};
blackground::blackground(int x0int y0int m0int n0WORD w0)
{ m=m0;
n=n0;
y=y0;
x=x0;
w=w0;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE)w);
COORD pos;
pos.X=x+m;
pos.Y=y+n;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE)pos);
}
blackground::display1()
{
printf(“ “);
}
blackground::display2()
{
printf(“兔“);
}
blackground::display3()
{
printf(“羊“);
}
blackground::display4()
{
printf(“鹰“);
}
blackground::display5()
{
printf(“狼“);
}
blackground::display6()
{
printf(“草“);
}
blackground::display8()
{
printf(“*“);
}
///////////定义羊//////////////
class sheep
{
private:
int a; // 数目
float b; // 捕食率
float c; // 增长率
float d; // 死亡率
int s; // 寿命
int n;
public:
sheep::sheep1(int a0float b0float c0float d0int s0); //重载blackground()
int num()
{ n=a*(c-d+1);
return n;
}
};
sheep::sheep1(int a0float b0float c0float d0int s0)
{ a= a0;
b= b0;
c= c0;
d= d0;
s= s0;
}
class wolf
{
private:
int a; // 数目
float b2; float b3; // 捕食率
float c; // 增长率
float d; // 死亡率
int s; // 寿命
int n;
public:
wolf::wolf1(int a0float b02float b03float c0float d0int s0); //重载blackground()
int num()
{ n=a*(c-d+1);
return n;
}
};
wolf::wolf1(int a0float b02float b03float c0float d0int s0)
{ a= a0;
b2= b02; b3= b03;
c= c0;
d= d0;
s= s0;
}
class rabbit
{
private:
int a; // 数目
float b; // 捕食率
float c; // 增长率
float d; // 死亡率
int s; // 寿命
int n;
public:
rabbit::rabbit1(int a0float b0float c0float d0int s0); //重载blackground()
int num()
{ n=a*(c-d+1);
return n;
}
};
rabbit::rabbit1(int a0float b0float c0float d0int s0)
{ a= a0;
b= b0;
c= c0;
d= d0;
s= s0;
}
class hawk
{
private:
int a; // 数目
float b; // 捕食率
float c; /
- 上一篇:ymodem发送代码(c语言)
- 下一篇:中国邮路问题c语言代码
评论
共有 条评论