在这里插入代码片
#include<iostream>
using namespace std;
class Group
{
protected:
int length;char type;
public:
virtual void play()=0;
virtual void set()=0;
Group(){}
Group(char type,int length):
type(type),length(length){
}
};
class BoyGroup:public Group
{
int amount;
static int limit1,limit2;
public:
void play()
{
if(type=='C')
{
if(amount!=1)
cout<<amount<<" cats, ";
else if(amount==1)
cout<<amount<<" cat, ";
}
else if (type=='D')
{
if(amount!=1)
cout<<amount<<" dogs, ";
else if(amount==1)
cout<<amount<<" dog, ";
}
if(length==1)
{
cout<<"1 minute"<<endl;
}
else
{
cout<<length<<" minutes"<<endl;
}
}
BoyGroup(char type,int amount,int length):
Group(type,length),amount(amount)
{
}
void set()
{
if(type=='C')
{
if(length<limit1) length=limit1;
else if(length>=limit1) limit1=length;
}
else if(type=='D')
{
if(length<limit2) length=limit2;
else if(length>=limit2) limit2=length;
}
}
};
int BoyGroup::limit1=0;int BoyGroup::limit2=0;
class GirlGroup:public Group
{
static int limit3,limit4;
public:
GirlGroup(char type,int length):
Group(type,length)
{
}
void set()
{
if(type=='S')
{
if(length<limit3) length=limit3;
else if(length>=limit3) limit3=length;
cout<<"length= "<<length<<"limit3="<<limit3<<endl;
}
else if(type=='D')
{
if(length<limit4) length=limit4;
else if(length>=limit4) limit4=length;
}
cout<<"checklength="<<length<<endl;
}
void play()
{
cout<<"checklength="<<length<<endl;
if(type=='S')
{
cout<<"sing, ";
}
else if (type=='D')
{
cout<<"dance, ";
}
if(length==1)
{
cout<<"1 minute"<<endl;
}
else
{
cout<<length<<" minutes"<<endl;
}
}
};
int GirlGroup::limit3=0;int GirlGroup::limit4=0;
int main()
{
Group *g[20];
char type,type1;int amount,length,cc=0,num;
while(1)
{
cin>>type;
if(type=='E') break;
if(type=='B')
{
cin>>type1>>amount>>length;
g[cc]=new BoyGroup(type1,amount,length);
cc++;
}
else if(type=='A')
{
cin>>type1>>length;
g[cc]=new GirlGroup(type1,length);
cc++;
}
}
while(1)
{
cin>>num;
if(num==0) break;
g[num-1]->play();
}
return 0;
}
没写完的代码
最新推荐文章于 2021-07-26 09:55:51 发布