汇编编程题.docVIP

  • 10
  • 0
  • 约2.46万字
  • 约 15页
  • 2018-06-20 发布于河南
  • 举报
汇编编程题

C++面向对象程序设计基础 1、定义平面直角坐标系上的一个点类CPoint作为基类,派生出一条直线类CLine和一个矩形类CRect,并求出两点间距离和矩形的面积。 #include iostream.h #include math.h class CPoint {protected: double a,b; public: CPoint(float m,float n){ a=m;b=n;} ~CPoint(){} }; class Cline:public CPoint { private: double c,d; public: Cline(float x1,float y1,float x2,float y2):CPoint(x1,y1) {c=x2;d=y2;} void Distance(); }; void Cline:: Distance() {double dis; dis=sqrt((c-a)*(c-a)+(d-b)*(d-b)); cout两点间距离为:disendl; } class CRect:public CPoint { public: CRect(float x,float y):CPoint(x,y){} void Area() {coutThe area is:a*bendl;} }; void main() { Cline c1(2,2,4,4); c1.Distance(); CRect c2(2,4); c2.Area(); } 2、学生和教师数据输入和显示程序,学生数据有编号、姓名、班号和成绩,教师数据有编号、姓名、职称和部门。要求将编号、姓名输入和显示设计成一个类person,并作为学生数据操作类student和教师数据操作类teacher的基类。 #includeiostream.h ?class person ?{ protected: ?????? ?int num; ?????? ?char name[20]; ????public: ?????? ?void input() ?????? ?{?????cout输入编号:;???cinnum; ????????????? cout输入姓名:;?????cinname;????????????? ???????????? ?} ?????? ?void output() ???? {? cout编号为:numendl; ????????????? ?cout姓名为:nameendl; } };???????????? ?? class student:public person ?? {??protected: ?????? ?? int classnum; float grade; ?? public: ?????? ?? void input1() ?????? ?? { cout输入学生数据:endl;input(); ????????????? ?cout输入班号:;???cinclassnum; ????????????? ?cout输入成绩:;? cingrade;? } ?????? ?? void output1() ?????? ?? {cout输出学生的数据:endl; ????????????? output(); ?????? ?? cout班号为:classnumendl; ?????? ?? cout成绩为:gradeendl; } }; ?? class teacher: public person { ?? protected: ?????? ?? char n[10],m[20]; ?????? ?? ?? public:???? ?? ?????? ?void input2() ?????? ?? { cout输入教师的数据:endl; input(); ?????? ?? cout输入职称:; cinn; ?????? ?? cout输入部门:;? cinm;? ?? } ?????? ?? void output2() ?????? ?? {cout输出教师的数据:endl; ?????? ?? output(); ?????? ?? cout职称为:nendl; ?????? ?? cout部门为:mendl; } }; ?? void main() ?? { student s;??s.input1();?s.output1();? teacher t; t.input2();? t

文档评论(0)

1亿VIP精品文档

相关文档