永发信息网

C++ 定义一个学生类Student

答案:1  悬赏:60  手机版
解决时间 2021-03-20 14:34
  • 提问者网友:山高云阔
  • 2021-03-20 07:51
数据成员包括:学号、姓名、C++成绩、数学成绩、语文成绩,各成员函数的功能要求如下:
定义构造函数实现对数据成员的初始化;
定义析构函数;
SetStuInfo( )成员函数实现从键盘输入数据成员的值;
DisplayStu( )成员函数在屏幕上显示学生的信息;
GetStuAvg( )成员函数求学生的平均成绩;
GetStuSum( )成员函数求学生的总成绩。
#include "stdafx.h"
#include "iostream.h"
#include "string.h"

calss student
{
private;
string Num;
string Name;
int C;
int math;
int Chinese;
public;
student()
{
Num=" ";
Name=" " ;
C=0;
math=0;
Chinese=0;

~student()
{
}

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

int Sum(student *stu)
{
return (stu->C + stu->Chinese + stu->English);
}

int Avg(student *stu)
{
return (stu->C + stu->Chinese + stu->English)/3;
}
};

int main()
{
student *zh;
zh=new(student);
InputData(zh);
cout<<zh->name<<"is Sum:"<<Sum(zh)<<endl;
cout<<zh->name<<"is Sum:"<<Avg(zh)<<endl;

return 0;
}
最佳答案
  • 五星知识达人网友:人類模型
  • 2021-03-20 08:11
#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:"<<Name<<endl
<<"Num: "<<Num<<endl
<<"C: "<<C<<endl
<<"Math:"<<math<<endl
<<"Chinese:"<<Chinese<<endl;
}
};

int main()
{
student *zh;
zh=new student;
zh->setstuInfo();
zh->DisplayStu();
cout<<"Sum:"<<zh->GetStuSum()<<endl;
cout<<"Ave:"<<zh->GetStuAvg()<<endl;
delete zh;
return 0;
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯