C++ 定义一个学生类Student
数据成员包括:学号、姓名、C++成绩、数学成绩、语文成绩,各成员函数的功能要求如下:定义构造函数实现对数据成员的初始化;定义析构函数;SetStuInfo()成员函数实现...
数据成员包括:学号、姓名、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;
} 展开
定义构造函数实现对数据成员的初始化;
定义析构函数;
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;
} 展开
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:"<<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;
}
#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;
}
追问
还是有错误!!再帮忙改下可以吗?
追答
//那估计你用的编译器版本很新,没有iostream.h了,那就把开头换成这样:
//你那个图太小了,根本看不清,我估计是这样的,如果还不行的话把错误文字贴上来不要弄图
// 我这里是没问题的
#include
#include
using namespace std;
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>Num;
cout>Name;
cout>C;
cout>math;
cout>Chinese;
}
int GetStuSum()
{
return (C+Chinese+math);
}
int GetStuAvg()
{
return (C+Chinese+math)/3;
}
void DisplayStu()
{
coutsetstuInfo();
zh->DisplayStu();
coutGetStuSum()GetStuAvg()<<endl;
delete zh;
return 0;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询