zoukankan      html  css  js  c++  java
  • 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就没问题了

  • 相关阅读:
    vue-element-admin中table分页改为前台处理
    vue项目如何部署到Tomcat中
    vuex之modules 热加载(hot update)
    持续学习
    css比较特殊选择器汇总(持续更新)
    关于伪元素before after总结
    ajax入门-实现省份下拉框
    super和this关键字的详解
    监听器
    当浏览器被关闭时,session是否被关闭?
  • 原文地址:https://www.cnblogs.com/dk2154/p/14101344.html
Copyright © 2011-2022 走看看