c++第八章课后题

题目:定义一个学生成绩类 Score,描述学生的私有数据成员为学号(No)、姓名 (Name[8])、数学(Math)、物理(Phi)、英语(Eng)。定义能输入学生成绩的公有成员函数 Input()、 能计算学生总分的公有成员函数 Sum()、能显示输出学生成绩的公有成员函数 Show()

源码:

#include<iostream>

#include<string>

using namespace std;

class Score

{

       int No;

       string Name;

       double Math, Phi, Eng;

public:

       Score(long no, string name)

       {

              No = no;

              Name=name;

       }

       void Input(int m, int p, int e)

       {

              Math = m;

              Phi = p;

              Eng = e;

       }

       double Sum()

       {

              double sum=0;

              sum =Math + Phi + Eng;

              return sum;

       }

       void Show()

       {

              cout << "Math:" << Math << " " << "Phi:" << Phi << " " << "Eng:" << Eng;

       }

};

int main()

{

       Score s1(11011, "张三");

       s1.Input(80, 90, 88);

       s1.Show();

       return 0;

}

遇到的问题:

1、一开始Math、Phi、Eng用的是整形,然后调试的时候有警告

问了老师之后把int改成double就没问题了

原文地址:https://www.cnblogs.com/dk2154/p/14101344.html