在这里插入代码片
#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;
}
本文发布于:2024-02-01 01:16:12,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170672137232782.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |