定义学生类student,类的结构如下 class student {
public:
student(int,char *,int,float);//需提示\~student();//需提示\void printstu(); private: int id; char *name; int age; float score; };
将类定义完整,并在主函数中进行测试。
Input
输入数据有多行。
Output
对于每个测试数据,输出有多行。
Sample Input
1 zhangsan 19 80 2 lisi 20 91 3 wangwu 18 85
Sample Output
Constructing...
Num:1 Name:zhangsan Age:19 Score:80 Destructing... Constructing...
Num:2 Name:lisi Age:20 Score:91 Destructing... Constructing...
Num:3 Name:wangwu Age:18 Score:85 Destructing... #include
{
private: int id; char *name; int age; float score; public: student(int i=0,char *na=NULL,int a=0,float s=0.0) { id=i; if(na!=NULL) { name=new char[strlen(na)+1]; strcpy(name,na); } else name=NULL; age=a;score=s; cout<<\ } ~student() { if(name!=NULL) delete []name; cout<<\ } void printstu() { if(name!=NULL) cout<<\Score:\ } };
int main() { int i,a; float s; char n[30]; while(cin>>i>>n>>a>>s) { student one(i,n,a,s); one.printstu(); } return 0;
Name:\Age:\
}
4:打卡机
Time/Memory Limit:1000 MS/32768 K
Submitted: 42 Accepted: 27
Problem Description
LPRJ小工厂是刚兴起不久的标准工厂,每天早上八点开始上班,每天工作八小时,但是由于LPRJ小工厂近来员工懈怠于工作,经常迟到,于是经理LP决定用考勤打卡机来记录员工的上班时间,经理为了整顿一下员工的上班态度,决定员工每迟到半小时将扣除10元的工资,若不迟到员工每天的工资有80元,计算每位员工在今天可获得的工资。(要求用类完成)
Input
输入数据有多组,每组第一行输入一个整数T,代表接下去有T行员工测试数据 每位员工的资料包含工号,姓名,打卡时间(hh:mm);
Output
输出每位员工的信息以及当天可获得的工资。
Sample Input
3
12078 LP 07:45 12080 shik 08:00 12012 junl 08:31 2
12078 LP 07:45 12080 shik 08:00
Sample Output
12078 LP 07:45 80 12080 shik 08:00 80 12012 junl 08:31 60 12078 LP 07:45 80 12080 shik 08:00 80 #include
{
private: string num; string name; int H,M; public: stu(string num=\ { this->num=num;this->name=name; H=hh;M=mm; } int SS() { int salary; if(H<8||(H==8&&M==0)) salary=80; else { if(M0!=0) salary=80-(H-8)*2*10-(M/30+1)*10; else salary=80-(H-8)*2*10-M/30*10; } if(salary<=0) salary=0; return salary; } void show() { cout< int main() { int T,hh,mm; string num; string name; char c1,c2; } while(cin>>T) { while(T--) { cin>>num>>name>>hh; cin.get();cin>>mm; stu one(num,name,hh,mm); one.show(); } } return 0; 5:找出每组数据中的最大值(函数重载) Time/Memory Limit:1000 MS/32768 K Submitted: 68 Accepted: 46 Problem Description 定义函数Max实现找出每组测试数据中的最大值,在主函数中进行调用,要求Max函数能够实现分别在2个int型数据、2个字符串(不包括空格,长度不超过50)、3个double型数据中找到最大值。 Input 输入数据有三组,每组占一行。 Output 对于每组输入数据,输出一行。 Sample Input 1 2 55.6 25.7 88.8 good morning Sample Output max:2 max:88.8 max:morning #include