Private data member: student name (stu Name), student number (stuNum), math score (mathSco), physics score (phiSco); • Constructor and Destructor; • Public member function: myset to modify grades, show to display information; • The friend function aver ( is used to calculate the average score. • Main function: two class objects "stul" and "stu2" are created for "Zhang San" and "Li Si". Their student numbers are 201 and 202, and their grades are as follows: Mathematics 89 and 81, physics 75.5 and 77. Then, the function show is called to display student name, student number, math score, physics score. Finally, the aver is called to calculate and display the average score. An example of the running result is as follows: Student Name: Zhang San, Student Number: 201 Math Score: 89, phi Score: 75.5 Average Score: 82. 25 Student Name: Li Si, Student Number: 202 Math Score: 81, phi Score: 77 Average Score: 79 ==>Paste the code screenshots below:
时间: 2024-02-20 07:01:01 浏览: 91
抱歉,作为一名语言模型,我无法提供代码截图。以下是符合题意的C++代码:
```cpp
#include <iostream>
#include <string>
using namespace std;
class Student {
private:
string stuName;
int stuNum;
double mathSco;
double phiSco;
public:
Student(string name, int num, double math, double phi) {
stuName = name;
stuNum = num;
mathSco = math;
phiSco = phi;
}
~Student() {}
void myset(double math, double phi) {
mathSco = math;
phiSco = phi;
}
friend double aver(Student s);
void show() {
cout << "Student Name: " << stuName << ", Student Number: " << stuNum << endl;
cout << "Math Score: " << mathSco << ", phi Score: " << phiSco << endl;
}
};
double aver(Student s) {
return (s.mathSco + s.phiSco) / 2;
}
int main() {
Student stul("Zhang San", 201, 89, 75.5);
Student stu2("Li Si", 202, 81, 77);
stul.show();
cout << "Average Score: " << aver(stul) << endl;
stu2.show();
cout << "Average Score: " << aver(stu2) << endl;
return 0;
}
```
输出结果为:
```
Student Name: Zhang San, Student Number: 201
Math Score: 89, phi Score: 75.5
Average Score: 82.25
Student Name: Li Si, Student Number: 202
Math Score: 81, phi Score: 77
Average Score: 79
```
阅读全文