C课后习题复习题

上传人:c** 文档编号:291141036 上传时间:2022-05-11 格式:DOCX 页数:7 大小:17.79KB
返回 下载 相关 举报
C课后习题复习题_第1页
第1页 / 共7页
C课后习题复习题_第2页
第2页 / 共7页
C课后习题复习题_第3页
第3页 / 共7页
C课后习题复习题_第4页
第4页 / 共7页
C课后习题复习题_第5页
第5页 / 共7页
点击查看更多>>
资源描述

《C课后习题复习题》由会员分享,可在线阅读,更多相关《C课后习题复习题(7页珍藏版)》请在金锄头文库上搜索。

1、本文格式为Word版,下载可任意编辑C课后习题复习题 P106:5-9、定义学生类,属性包括姓名、学号,c#、英语和数学劳绩,方法包括设置姓名和学号、设置三门课的劳绩和输出相关学生的信息,结果求出总劳绩和平均劳绩。 class student /创造学生类 public string name, stunumber; /姓名、学号属性 public double csharp,math,english;/三门劳绩 public void setstudent(string name, string number) /设置姓名,学号 this.name = name; this.stunumbe

2、r = number; public void setscore(double csharp, double math, double english)/设置分数 this.csharp = csharp; this.math = math; this.english = english; public void show() /显示信息 Console.WriteLine(the score of the student:nc#:2,math:3,english:4 /*创造学生类完成*/ static void Main(string args) /入口函数 double fullscor

3、e; /总分 double avescore; /平均分 student s1 = new student(); /创造一个学生对象s1 s1.setstudent( s1.setscore(98,98,98.7); s1.show(); /现实学生信息 fullscore = s1.csharp + s1.math + s1.english; avescore = fullscore / 3; /算出平均分 Console.WriteLine(students fullscore :0naverage score :1,6:f2 P106:5-10、定义一个人员类clsPerson,包括属性

4、:姓名、编号、性别和用于输入输出地方法,在此根基上派生出学生类clsStudent(增加劳绩)和教师类clsTeacher(增加教龄),并实现对学生和教师的信息的输入输出。 class clsPerson public string name,number,sex; /属性 public void input(string name, string number,string sex)/输入信息 this.name = name; this.number = number; this.sex = sex; public void output() Console.WriteLine(输出信息

5、class clsStudent:clsPerson/继承person public double score; public void input(string name, string number, string sex, double score) base.input( name, number, sex);/继承基类输入 this.score = score; public void output() base.output();/继承基类输出 Console.WriteLine( class clsTeacher : clsPerson/继承person public int t

6、chage; public void input(string name, string number, string sex, int tchage) base.input(name, number, sex); this.tchage = tchage; public void output() base.output(); Console.WriteLine( static void Main(string args)/入口函数 clsStudent s1 = new clsStudent(); /创造一个学生类对象s1 clsTeacher t1 = new clsTeacher();

7、 /创造一个教师类对象t1 s1.input(范朦 s1.output(); t1.input( t1.output(); (复习重点)P106:5-11、设有一个描述坐标点的clsPoint类,其私有变量x和y代表一个点的x,y坐标值。编写程序实现以下功能:利用构造函数传递参数,并设其默认参数值为60和75,利用方法display()输出这一默认的值;利用公有方法setPoint()将坐标值修改为(100,120),并利用方法输出修改后的坐标值。 class clsPoint/创造类 int x, y;/属于私有属性,此处private 省略 public clsPoint(int x, i

8、nt y)/构造函数,就是对一个对象的初始化 this.x = x; this.y = y; public void setpoint(int x,int y)/公有方法设置坐标值 this.x=x; this.y=y; public void show()/显示坐标 Console.WriteLine( static void Main(string args)/入口函数 clsPoint p1 = new clsPoint(60,75);/与int i=0作用一致,就是使对象有初始值 p1.show(); p1.setpoint(100,200); Console.WriteLine( p

9、1.show(); (复习重点)P106:5-12、把定义平面直角坐标系上的一个点的类clsPoint作为基类,派生出描述一条直线的类clsLine,再派生出一个矩形类clsRect。要求方法能求出两点间的距离,矩形的周长和面积等。设计一个测试程序,并构造出完整的程序。(考察get()set()和继承) class clsPoint /创造类 protected double x, y; public double X get /getset 的作用是将养护类型的属性转换为隐形可继承 用对象继承(考点) return this.x; set this.x=value; public doubl

10、e Y get return this.y; set this.y= value; public clsPoint() /定义空的构造函数,增加程序严谨性 public clsPoint(double x, double y) this.x = x; this.y = y; public void show() Console.WriteLine(/输出点坐标 class clsLine:clsPoint/创造clsLine类,继承clsPoint public clsPoint p = new clsPoint(); /定义一个点对象 public clsLine() public clsL

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 大杂烩/其它

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号