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

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

来源:网络收集 时间:2026-01-24
导读: if(p1.salary>=p2.salary) return p1; else return p2; } int main() { int s; char n[30]; cin>>n>>s; STAFF one(n,s); cin>>n>>s; STAFF two(n,s); cin>>n>>s; STAFF three(n,s); one.show1(); two.show1(); thre

if(p1.salary>=p2.salary) return p1; else return p2; }

int main() { int s; char n[30]; cin>>n>>s; STAFF one(n,s); cin>>n>>s; STAFF two(n,s); cin>>n>>s; STAFF three(n,s); one.show1(); two.show1(); three.show1(); STAFF::show2(); STAFF A=JUDGE(one,two); STAFF B=JUDGE(A,three); B.show3(); return 0; }

20:统计学生信息

Time/Memory Limit:1000 MS/32768 K

Submitted: 78 Accepted: 49

Problem Description

现如今人人都已经统计完了综测分而轻松,然而LP却接到学委赋予的伟大任务而手忙脚乱:统计班级综测分的情况,好吧,你懂的,他在向你求助。

Input

输入的数据有多行,每行为一个同学的姓名,学号及个人综测分,输入至文件尾结束。

Output

对于每行输入的数据都进行输出,每次输出的数据有2行: 第一行为该同学的姓名,学号及综测分;

第二行为当前已统计的同学人数及当前已统计的所有同学的平均综测分。 (具体输出详见Sample)

Sample Input

Linping 1200008625 80 Jinkun 1200008645 100

Sample Output

Name:Linping No:1200008625 Score:80 Count:1 Ave:80

Name:Jinkun No:1200008645 Score:100 Count:2 Ave:90

#include #include using namespace std; class student {

private: string name; string num; double score; static int count; static double sum; static double ave; public: student(string name=\ { this->name=name; this->num=num; this->score=score; count++; sum=sum+this->score; ave=sum/count; } void showone() { cout<<\ } static void showtwo() { cout<<\ }

};

int student::count=0; double student::sum=0.0; double student::ave=0.0; int main() { string num; string name; double s; while(cin>>name>>num>>s) { student one(name,num,s); one.showone(); student::showtwo(); } return 0; }

21:学生成绩等级

Time/Memory Limit:1000 MS/32768 K

Submitted: 56 Accepted: 47

Problem Description

有一个学生类student,包括学生姓名、成绩,设计一个友元函数,输出成绩对应的等级:大于等于90:A;80~90:B;70~79:C;60~69:D;小于60:E。

Input

先输入数据n,表示有n个学生,接下是n个学生信息,包括姓名和成绩。

Output

对于所有的输入数据,输出学生数据(包括姓名、成绩和等级)。

Sample Input

5

st1 67 st2 80 st3 90 st4 56 st5 88

Sample Output

st1 67 D st2 80 B st3 90 A st4 56 E st5 88 B

#include #include using namespace std; class student {

private: string name; double score; public: student(string name=\ { this->name=name; this->score=score; } void showone() { cout<name<<\ } friend void JUDGE(student &); };

void JUDGE(student &p) { if(p.score>=90) cout<<\ else if(p.score>=80) cout<<\ else if(p.score>=70) cout<<\ else if(p.score>=60) cout<<\ else cout<<\}

int main() { string name; double s;

}

int n; cin>>n; while(n--) { cin>>name>>s; student one(name,s); one.showone(); JUDGE(one); }

return 0;

22:类的继承——定义学生类及其派生类

Time/Memory Limit:1000 MS/32768 K

Submitted: 85 Accepted: 49

Problem Description

定义一个学生类Student,它包括学生名、住址和出生年份等私有数据以及输出函数show(),从它派生出一个大学生Academician类及一个小学生类

Primary_scholar。在大学生类中增加数据成员大学校名university_name,在小学生类中所增加的数据成员是两门课的成绩,两个派生类所有有关的输出都由函数show()来实现。

Input

输入数据有多行,第一行有两个整数n和m,分别代表大学生对象的个数n和小学生对象的个数m,接下来的n行为大学生的数据信息,m行为小学生的数据信息

Output

输出每个学生的信息,一个学生一行

Sample Input

2 3

zhang Fuzhou 1988 ZhangzhouNormalUniversity li Xiamen 1987 FuzhouUniversity wang Zhangzhou 1998 75 89 su Quanzhou 1997 90 90 wu Putian 1996 78 87

…… 此处隐藏:664字,全部文档内容请下载后查看。喜欢就下载吧 ……
c++数据结构上机题及实现代码(8).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)