没写完的代码

在这里插入代码片
#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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值