📄 hw5-1.cpp
字号:
#include <iostream.h>
#include <string.h>
class Student {
char name[10];
float math, comp, eng, avg;
static float allscore;
static int num;
public:
Student(char *sn, float m, float c, float e) {
strcpy(name, sn);
math = m;
comp = c;
eng = e;
avg = (m + c + e) / 3;
allscore += avg;
num ++;
}
void Show() {
cout << "姓名:" << name << " 平均成绩:" << avg << endl;
}
static void AllAverage() {
cout << "\n总平均值是:" << allscore / num << endl << endl;
}
};
float Student::allscore = 0;
int Student::num = 0;
void main() {
Student stu[5] = { Student("黎 明", 78, 89, 82),
Student("张学友", 85, 97, 87),
Student("刘德华", 67, 92, 83),
Student("郭富成", 64, 78, 75),
Student("张国荣", 84, 92, 90) };
for(int i = 0; i < 5; i ++)
stu[i].Show();
Student::AllAverage();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -