dsdfsdfzs 2019-10-17 23:15 采纳率: 0%
浏览 261
已采纳

一道C++的类与对象问题

设计一个类student

private:
admno int
sname 20 char
eng,math,science float
total float
ctotal() 计算eng+math+science with float return type

public:
takedata() function to accept value for all the value above
showdata() function to display all the data members

  • 写回答

2条回答

  • Varible 2020-03-17 21:28
    关注

    我把整个代码写下来了,测试过了。

    /*
    # 一道C++的类与对象问题 5Cbuy
    设计一个类student
    
    private:
    admno int
    sname 20 char
    eng,math,science float
    total float
    ctotal() 计算eng+math+science with float return type
    
    public:
    takedata() function to accept value for all the value above
    showdata() function to display all the data members
    */
    #include <iostream>
    using namespace std;
    class student {
     public:
      void takedata();
      void showdata();
     private:
      int admno;
      char sname[21];//20 + '\0'
      float eng,math,science;
      float total;
      float ctotal();
    };
    int main(int argc,char **argv) {
     student stu;
     stu.takedata();
     stu.showdata();
     return 0;
    }
    float student::ctotal() {
     return this->eng + this->math + this->science;
    }
    void student::takedata() {
     cin >> this->admno >> this->sname >> this->eng >> this->math >> this->science;
     this->total = this->ctotal();
     return;
    }
    void student::showdata() {
     cout << this->admno << ' ' << this->sname << ' ' << this->eng << ' ' << this->math << ' ' << this->science << ' ' << this->total << endl;
     return;
    }
    
    

    解决后请点下采纳!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作