教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 精品文档 > 资格考试 >

c++数据结构上机题及实现代码(2)

来源:网络收集 时间:2026-01-24
导读: 定义学生类student,类的结构如下 class student { public: student(int,char *,int,float);//需提示\~student();//需提示\void printstu(); private: int id; char *name; int age; float score; }; 将类定义完整

定义学生类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 #include using namespace std; class student

{

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 #include using namespace std; class stu

{

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<num<<\ if(H<10) cout<<\ 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 #include

…… 此处隐藏:245字,全部文档内容请下载后查看。喜欢就下载吧 ……
c++数据结构上机题及实现代码(2).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wendang/411995.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)