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

2019-08-02 01:17

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;


c++数据结构上机题及实现代码(9).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:童话的特点及教学策略(新提纲)

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: