没写完的代码

阅读: 评论:0

没写完的代码

没写完的代码

在这里插入代码片
#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小时内删除。

下一篇:duidie
标签:写完   代码
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23