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

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

来源:网络收集 时间:2026-01-24
导读: Sample Output Name:zhang,Address:Fuzhou,Year:1988,University_Name:ZhangzhouNormalUniversity Name:li,Address:Xiamen,Year:1987,University_Name:FuzhouUniversity Name:wang,Address:Zhangzhou,Year:1998,Sco

Sample Output

Name:zhang,Address:Fuzhou,Year:1988,University_Name:ZhangzhouNormalUniversity

Name:li,Address:Xiamen,Year:1987,University_Name:FuzhouUniversity Name:wang,Address:Zhangzhou,Year:1998,Score:75 89 Name:su,Address:Quanzhou,Year:1997,Score:90 90 Name:wu,Address:Putian,Year:1996,Score:78 87

#include #include using namespace std; class Student {

private: string name; string Address; int age; public: Student(string name1,string Address1,int age1) { name=name1; Address=Address1; age=age1; } void show() { cout<<\ } };

class Academician:public Student {

private: string university_name; public: Academician(string name1,string Address1,int university_name1):Student(name1,Address1,age1) { university_name=university_name1; } void show() { Student::show(); cout<<\ } };

age1,string

class Primary_scholar:public Student {

private: double score1,score2; public: Primary_scholar(string name1,string Address1,int s2):Student(name1,Address1,age1) { score1=s1; score2=s2; } void show() { Student::show(); cout<<\ } };

int main() { int n,m; string n1,A1,u1; int a1; double s1,s2; while(cin>>n>>m) { while(n--) { cin>>n1>>A1>>a1>>u1; Academician one(n1,A1,a1,u1); one.show(); } while(m--) { cin>>n1>>A1>>a1>>s1>>s2; Primary_scholar two(n1,A1,a1,s1,s2); two.show(); } } return 0; }

age1,double s1,double

23:类的继承——定义点类及其派生的圆类

Time/Memory Limit:1000 MS/32768 K

Submitted: 64 Accepted: 51

Problem Description

定义一个点类point,它带有两个私有数据成员:x,y(整数);还有构造函数(x和y的默认值为0),显示坐标函数;point类共有派生出圆类circle,circle类具备point类的全部特征,同时自身也有自己的特点:圆有半径成员(可以是小数),求面积成员函数,显示成员函数,该显示函数可以显示圆的圆心坐标,半径,和圆的面积。在主函数中对circle类进行测试。

Input

输入数据有多行,第一行有一个整数n,表示一共有n个圆对象,接下来的n行,每行包括一共圆对象的圆心坐标和它的半径。

Output

输出有n行,每行为一个圆对象的圆心坐标、半径和它的面积。

Sample Input

3

0 0 2 1 2 3 2 3 6.5

Sample Output

Centre:(0,0) Radius:2 Area:12.56 Centre:(1,2) Radius:3 Area:28.26

Centre:(2,3) Radius:6.5 Area:132.665 #include using namespace std; class point {

private: int x,y; public: point(int x1=0,int y1=0) { x=x1; y=y1; } void show() { cout<<\

} };

class circle:public point {

private: double r; public: circle(int x1=0,int y1=0,double r1=0.0):point(x1,y1) { r=r1; } double SS() { return 3.14*r*r; } void show() { point::show(); cout<<\ } };

int main() { int n,x1,y1; double r1; while(cin>>n) { while(n--) { cin>>x1>>y1>>r1; circle one(x1,y1,r1); one.show(); } } return 0; }

24:类的继承

Time/Memory Limit:1000 MS/32768 K

Submitted: 67 Accepted: 49

Problem Description

编写一个学生和教师数据输入和显示程序,学生数据有编号、姓名、班号和成绩,教师数据有编号、姓名、职称和部门。要求设计一个Person类,包含编号、姓名数据成员及构造和显示成员函数,该类作为学生类和教师类的基类。

Input

输入包括两行,第一行是学生的相关信息,第二行是教师的相关信息

Output

输出包括两行,第一行是学生的相关信息,第二行是教师的相关信息

Sample Input

2009050102 Marry Computer(1) 89 02017 Tomy Lecturer Computer

Sample Output

Num:2009050102 Name:Marry Class:Computer(1) Score:89

Num:02017 Name:Tomy profession:Lecturer Department:Computer #include #include using namespace std; class person {

private: string num; string name; public: person(string num1,string name1) { num=num1;name=name1; } void show() { cout<<\ } };

class student:public person {

private: string no; double score;

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