类与对象练习题

上传人:xzh****18 文档编号:51732313 上传时间:2018-08-16 格式:PPT 页数:15 大小:39KB
返回 下载 相关 举报
类与对象练习题_第1页
第1页 / 共15页
类与对象练习题_第2页
第2页 / 共15页
类与对象练习题_第3页
第3页 / 共15页
类与对象练习题_第4页
第4页 / 共15页
类与对象练习题_第5页
第5页 / 共15页
点击查看更多>>
资源描述

《类与对象练习题》由会员分享,可在线阅读,更多相关《类与对象练习题(15页珍藏版)》请在金锄头文库上搜索。

1、类与对象练习题void current_date:increment_date() day+; if(day 30) month+; if(month 12) year+; month = month%12; day = day%30; 设计一个学生类Student,成员变量包括ID(学号), Name(姓名),Age(年龄),AverageScore(平均分 ),成员函数包括StudentBonus()(学生奖学金) ,show_information()(显示学生的全部信息,包括学号 、姓名、年龄、平均分、奖学金),本例中奖学金计算方 法 平均分不超过80分(含80分)的,奖学金为0,即没

2、有奖 学金; 平均分在81-90之间的,奖学金计算公式为(平均分-80 )*50; 平均分在91-100之间的,奖学金计算公式为(平均分-80 )*100; 在主函数中,声明2个对象并利用show_information() 函数显示个人全部信息。 #include #include using namespace std; class Student private: int ID; /学号 string Name; /姓名 int Age; /年龄 double AverageScore; /平均分 public: Student(int _id,string _name,int _age

3、,double _average_score); /构 造函数 int get_ID(); /返回学号 string get_Name(); /返回姓名 int get_Age(); /返回年龄 double StudentBonus(); /计算学生奖学金 void show_information();/显示学生全部信息 ; Student:Student(int _id,string _name,int _age,double _average_score) /构造函数 ID=_id; Age=_age; Name=_name; AverageScore=_average_score;

4、int Student:get_ID()/返回学号 return ID; int Student:get_Age()/返回年龄 return Age; string Student:get_Name()/返回姓名 return Name; double Student:StudentBonus()/计算学生奖学金 if(AverageScore80 class Time int hour,minute,second; public: Time(); Time(int ,int ,int ); void printf_24(); void printf_12(); ; Time:Time() h

5、our=0; minute=0; second=0; Time:Time(int h,int m,int s) hour=(h=0 void Time:printf_24() couthour“:“minute“:“secondendl; void Time:printf_12() int hh=(hour=0|hour=12)?12:hour%12; couthh“:“minute“:“second(hour 12?“am“:“pm“)endl; int main() Time time1; cout“十二制时间输出:“; time1.printf_12(); cout“二十四制时间输出:“; time1.printf_24(); Time time2(14,24,24); cout“十二制时间输出:“; time2.printf_12(); cout“二十四制时间输出:“; time2.printf_24(); return 0;

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 中学教育 > 试题/考题 > 高中试题/考题

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