设计一个学生类student,它具有的私有数据成员是:学号、姓名、数学、英语、计算机成绩;具有的公有成员函数是:求3门课总成绩的函数sum;求3门课平均成绩的函数average;显示学生数据信息的函数。C++
时间: 2024-06-10 15:06:26 浏览: 27
++ 代码如下:
```
class student {
private:
int num; // 学号
char name[20]; // 姓名
float math; // 数学成绩
float english; // 英语成绩
float computer; // 计算机成绩
public:
void sum(); // 求3门课总成绩
void average(); // 求3门课平均成绩
void display(); // 显示学生数据信息
};
void student::sum() {
float total;
total = math + english + computer;
cout << "总成绩 :" << total << endl;
}
void student::average() {
float total;
total = math + english + computer;
cout << "平均成绩 :" << total / 3 << endl;
}
void student::display() {
cout << "学号 :" << num << endl;
cout << "姓名 :" << name << endl;
cout << "数学成绩 :" << math << endl;
cout << "英语成绩 :" << english << endl;
cout << "计算机成绩 :" << computer << endl;
}
```
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![java](https://img-home.csdnimg.cn/images/20210720083646.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![cpp](https://img-home.csdnimg.cn/images/20210720083646.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)