C++ 定义一个学生类Student

2025-01-08 06:42:22
推荐回答(1个)
回答1:

#include "iostream.h"
#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;
}