| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2514 人关注过本帖
标题:怎样添加一个循环实现输出的不断变换???
取消只看楼主 加入收藏
wyc04243319
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2017-5-29
收藏
 问题点数:0 回复次数:1 
怎样添加一个循环实现输出的不断变换???
我想实现一个野生猴子的繁衍,但写到现在不会写了,求帮助(希望我输出的一个数组内的公猴母猴能不断自动变换,实现猴子的交替繁衍),大神们看看我下面程序怎么补充!!!
#include<iostream>
#include<stdlib.h>
#include<time.h>
using namespace std;
class animal{
public:
int age[10][10]; //描述生物的年龄
int healthy[10][10]; //描述生物的健康指数
int size[10][10];
    bool IsLife[10][10]; //描述生物是否死亡
    friend class init;
};
class Monkey:public animal{
int power[10][10];
public:
void live();
int nCount=0;
};

class init{
private:
animal a;
int monkey[10][10];
public:
init();
void display();
};
void init::display(){
for(int i=0;i<10;i++){
  for(int j=0;j<10;j++)
  {
if(monkey[i][j]==1)
{cout<<"母";
}
else if (monkey[i][j]==2)
{cout<<"公";}
else
{cout<<" ";}

}
cout<<endl;
}
};
init::init(){
srand((unsigned)time(NULL));
for(int i=3;i<7;i++){
  for(int j=3;j<5;j++){
    monkey[i][j]=rand()%3;
  a. age[i][j]=1+rand()%3;
  a.healthy [i][j]=1+rand()%3;      
}
}
};
void Monkey::live(){
for(int i=1;i<10;i++)
for(int j=1;j<10;j++){
if (monkey[i][j]==1||monkey[i][j]=2)
nCount=12-(monkey[i-1][j]+monkey[j-1]+monkey[j+1]+monkey[i+1][j]);
switch(nCount)//对其个体的生存状态进行判别
{
}
}
int main(){
init m;
m.display();
return 0;
};
更多 0
搜索更多相关主题的帖子: power animal friend public include 
2017-05-29 09:30
wyc04243319
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2017-5-29
收藏
得分:0 
回复 2楼 rjsp
要求就是用继承派生实现猴子的繁衍变化。。。。。我希望是最后输出的结果能显示公猴母猴数组中  都在不停的自动变换  这是不是得用到一种循环啊。。。我实在不知道怎么插入这个循环了。。
2017-05-29 10:18
快速回复:怎样添加一个循环实现输出的不断变换???
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012076 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved