[凡鸽鸽]《课内学习05》设计学生类Student

课内学习04

设计学生类Student:

设计学生类Student,成员变量包括ID(学号),Name(姓名),Age(年龄),AverageScore(平均分),成员方法包括4形参更新学生的属性方法Update(),将接口的值分别更新为学生相应成员变量的新值;计算学生的奖学金方法StudentBonus();显示学生的全部信息的方法(包括学号、姓名、年龄、平均分、奖学金)ShowInformation()。本例中奖学金计算方法:
(1)平均分不超过80分(含80分)的学生,奖学金为0,即没有奖学金;
(2)平均分在81~90之间的学生,奖学金计算公式为(平均分 - 80)*50;
(3)平均分在91~100之间的学生,奖学金计算公式为(平均分 – 80)*100;
(4)在主方法中,声明2个学生,分别调用Update()方法更新学生的全部信息,调用ShowInformation()方法显示学生的全部信息。

由于题目太过简单,直接上代码:
#include<iostream>
#include<string>
using namespace std;

class Student
  {
   public:
   Student(void);
   ~Student(void);
   void ShowInformation(void);
   int Num, Age, Update(int id, string name, int age, double average);
   string Name;
   double AverageScore;
   
   double StudentBonus(double average);
  };

Student::Student(void)	: Num(0){}

Student::~Student(void){}

int Student::Update(int num, string name, int age, double average)//更新学生的信息
  {
   Num = num;
   Name = name;
   Age = age;
   AverageScore = average;
   return 0;
  }


void Student::ShowInformation(void)//显示学生的全部信息
  {
   cout << "学号:" << Num << "  姓名:" << Name << "  年龄:" << Age << "  平均分:" << AverageScore << "  奖学金:" << StudentBonus (AverageScore) << endl;
  }


double Student::StudentBonus(double average)//奖学金 
  {
   if(average >= 91 && average <= 100)return (average - 80 ) * 100;
   else if(average >= 81 && average <= 90)return (average - 80) * 50;
   else return 0;	
  }
  
int main()
  {
  	system("color F0"); 
   Student student;
   string name;
   int num,age;
   double average;
   cout << "请输入学生的学号、姓名、年龄、平均分:" << endl;
   cin >> num >> name >> age >> average;
   cout << "更新前的学生信息是 ";
   student.Update(num,name,age,average);student.ShowInformation();
   cout << "更新后的学生信息是 ";
   student.Update(201408,"王敏",18,89);student.ShowInformation();
   system("pause"); 
   return 0;
  }
测试运行结果如图:

测试

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值