- 面向对象上机考试题—宠物进笼
- 发布日期时间:2007-1-14 来源:网络 点击数: 作者:佚名
nbsp; for (i=0; i<4; i++)
sum[i]=0;
}
int push_cat(Cat &cat, int n)
{
cats[n] = cat;
if (cage[n]!=NONE) return 0;
else {
sum[0]++;
return cage[n]=CAT;
}
}
int push_dog(Dog &dog, int n)
{
dogs[n]=dog;
if (cage[n]!=NONE) return 0;
else{
sum[1]++;
return cage[n]=DOG;
}
}
int push_snake(Snake &snake, int n)
{
snakes[n]=snake;
if (cage[n]!=NONE) return 0;
else {
sum[2]++;
return cage[n]=SNAKE;
}
}
void del(int n)
{
if (cage[n]==CAT) sum[0]--;
if (cage[n]==DOG) sum[1]--;
if (cage[n]==SNAKE) sum[2]--;
if (cage[n]==NONE)
cout<<"笼子里没有动物"<<endl;
else
{
cage[n]=NONE;
cout<<"已删除笼子里的动物"<<endl;
}
cout<<endl;
}
void seek(int n)
{
if (cage[n]==NONE) cout<<"第"<<n<<"个笼子里没有动物"<<endl;
if (cage[n]==CAT)
{
cout<<"第"<<n<<"个笼子里的动物为猫,";
cats[n].ShowMe();
}
if (cage[n]==DOG)
{
cout<<"第"<<n<<"个笼子里的动物为狗,";
dogs[n].ShowMe();
}
if (cage[n]==SNAKE)
{
cout<<"第"<<n<<"个笼子里的动物为蛇,";
snakes[n].ShowMe();
}
cout<<endl;
}
void count()
{
cout<<"笼子里的猫总共有:"<<sum[0]<<"只"<<endl;
cout<<"笼子里的狗总共有:"<<sum[1]<<"只"<<endl;
cout<<"笼子里的蛇总共有:"<<sum[2]<<"只"<<endl;
cout<<endl;
}
};
void main()
{
char c;
Cat cat;
Dog dog;
Snake snake;
Shelves shelves;
int i=1,j;
cout<<"这是关于往笼子里放动物的问题: "<<endl;
cout<<endl;
cout<<" 1: 往笼子里放猫;"<<endl;
cout<<" 2: 往笼子里放狗;"<<endl;
cout<<" 3: 往笼子里放蛇;"<<endl;
cout<<" 4: 查询笼子里的动物;"<<endl;
cout<<" 5: 删除笼子里的动物;"<<endl;
cout&l
sum[i]=0;
}
int push_cat(Cat &cat, int n)
{
cats[n] = cat;
if (cage[n]!=NONE) return 0;
else {
sum[0]++;
return cage[n]=CAT;
}
}
int push_dog(Dog &dog, int n)
{
dogs[n]=dog;
if (cage[n]!=NONE) return 0;
else{
sum[1]++;
return cage[n]=DOG;
}
}
int push_snake(Snake &snake, int n)
{
snakes[n]=snake;
if (cage[n]!=NONE) return 0;
else {
sum[2]++;
return cage[n]=SNAKE;
}
}
void del(int n)
{
if (cage[n]==CAT) sum[0]--;
if (cage[n]==DOG) sum[1]--;
if (cage[n]==SNAKE) sum[2]--;
if (cage[n]==NONE)
cout<<"笼子里没有动物"<<endl;
else
{
cage[n]=NONE;
cout<<"已删除笼子里的动物"<<endl;
}
cout<<endl;
}
void seek(int n)
{
if (cage[n]==NONE) cout<<"第"<<n<<"个笼子里没有动物"<<endl;
if (cage[n]==CAT)
{
cout<<"第"<<n<<"个笼子里的动物为猫,";
cats[n].ShowMe();
}
if (cage[n]==DOG)
{
cout<<"第"<<n<<"个笼子里的动物为狗,";
dogs[n].ShowMe();
}
if (cage[n]==SNAKE)
{
cout<<"第"<<n<<"个笼子里的动物为蛇,";
snakes[n].ShowMe();
}
cout<<endl;
}
void count()
{
cout<<"笼子里的猫总共有:"<<sum[0]<<"只"<<endl;
cout<<"笼子里的狗总共有:"<<sum[1]<<"只"<<endl;
cout<<"笼子里的蛇总共有:"<<sum[2]<<"只"<<endl;
cout<<endl;
}
};
void main()
{
char c;
Cat cat;
Dog dog;
Snake snake;
Shelves shelves;
int i=1,j;
cout<<"这是关于往笼子里放动物的问题: "<<endl;
cout<<endl;
cout<<" 1: 往笼子里放猫;"<<endl;
cout<<" 2: 往笼子里放狗;"<<endl;
cout<<" 3: 往笼子里放蛇;"<<endl;
cout<<" 4: 查询笼子里的动物;"<<endl;
cout<<" 5: 删除笼子里的动物;"<<endl;
cout&l
文章转载请注明来源于:汕头自考网
网友评论
|
|



