c++定义一个学生类 实现学生对象计数器。 求大佬帮忙

2025-12-18 06:45:24
推荐回答(1个)
回答1:

#include "string.h"
class student
{
private:
string Num;
string Name;
int C;
int math;
int Chinese;
public:
student()
{
Num=" ";
Name=" " ;
C=0;
math=0;
Chinese=0;
}

~student()
{
}

void setstuInfo()
{
cout<<"Input student Num:";
cin>>Num;
cout<<"Input student Name:";
cin>>Name;
cout<<"Input C:";
cin>>C;
cout<<"Input math:";
cin>>math;
cout<<"Input Chinese:";
cin>>Chinese;
}

int GetStuSum()
{
return (C+Chinese+math);
}

int GetStuAvg()
{
return (C+Chinese+math)/3;
}
void DisplayStu()
{
cout<<"Name:"<<<"Num: "<<<"C: "<<<"Math:"<<<"Chinese:"<}
};

int main()
{
student *zh;
zh=new student;
zh->setstuInfo();
zh->DisplayStu();
cout<<"Sum:"<GetStuSum()<cout<<"Ave:"<GetStuAvg()<delete zh;
return 0;
}