类与对象练习题
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,即没有奖 学金; 平均分在81-90之间的,奖学金计算公式为(平均分-80 )*50; 平均分在91-100之间的,奖学金计算公式为(平均分-80 )*100; 在主函数中,声明2个对象并利用show_information() 函数显示个人全部信息。 #include #include using namespace std; class Student private: int ID; /学号 s
2、tring Name; /姓名 int Age; /年龄 double AverageScore; /平均分 public: Student(int _id,string _name,int _age,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; int Student:get_ID()/返回学号 return ID; int Student:get_Age()/返回年龄 return Age; string Student:get_Name(
3、)/返回姓名 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() hour=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;
《类与对象练习题》由会员xzh****18分享,可在线阅读,更多相关《类与对象练习题》请在金锄头文库上搜索。
爱心树活动教案
世界文化之旅0
七年级学年知识归纳
七年级历史下册第二单元第12课《蒙古的兴起和元朝的建立》课件人教新课标版
一片美丽的叶子
非谓语动词 (6)
[中学联盟]江苏省太仓市第二中学七年级英语上册教学课件:Unit3READING1 (2)
“数与代数”教材修订说明
2014年7月师院培训
字理教学快捷入门之一20140521s
议论文写作指导之新材料作文审题立意 (2)
压缩语段 (2)
琵琶行课件 (2)
2014年各年级的教学计划和建议
(苏教版)五年级数学下册找规律第二课时
秋姑娘的信 (5)
苏教版数学五年级上册《复式条形统计图》课件 (2)
【名校课时通】2014届九年级化学全册第二单元探秘水世界第三节原子的构成名师教学课件鲁教版
《逻辑与语文》课件2
《检阅》[1]
2024-04-20 16页
2024-04-20 15页
2024-04-20 15页
2024-04-20 8页
2024-04-09 10页
2024-04-09 14页
2024-04-09 16页
2024-04-08 17页
2023-12-14 7页
2023-12-14 10页