#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
using namespace std;
//创建学生类
class student
{
public:
student(){} //构造函数
void insertInfo()
{
cout << "请输入学生姓名,学号,期中,期末,平时成绩" << endl;
cin >> name >> num >> qzScore >> qmScore >> psScore;
countScore = psScore*0.4 + 0.2*qzScore + qmScore*0.4;
}
void printInfo()
{
cout << "姓名:" << name << "\t" << "学号:" << num <<"\t"<< "总成绩:"<<countScore<<endl;
}
protected:
string name; //姓名
string num; //学号
float qzScore; //期中
float qmScore; //期末
float psScore; //平时
float countScore; //总成绩
};
int main()
{
//专业解答,看我头像
student mystudent;
mystudent.insertInfo();
mystudent.printInfo();
system("pause");
return 0;
}
运行截图:
![](https://video.ask-data.xyz/img.php?b=https://iknow-pic.cdn.bcebos.com/77094b36acaf2edd3bf2a89f861001e939019341?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_600%2Ch_800%2Climit_1%2Fquality%2Cq_85%2Fformat%2Cf_auto)
多个学生信息,使用结构体数组或者结构体指针动态申请,加上while循环