定义一个学生信息类cstudent,描述学生成员的私有数据成员为学号(id),姓名(cha

2024年11月17日 03:33
有1个网友回答
网友(1):

这个事我以前 做过的 一个 应该差不多 也很详细的 看看吧 哈~

#include
using namespace std;
class student
{
private:
int num;
char *name;
char sex;
float g_math;
float g_english;
float g_computer;
public:
student(int n,char *na,char s,float m,float e,float c)
{
num=n;
name=na;
sex=s;
g_math=m;
g_english=e;
g_computer=c;
}
student()
{
num=0;
name=" ";
sex=' ';
g_math=0;
g_english=0;
g_computer=0;
}
~student()
{
cout<<"这个学生对象从内存中消除!"< }
void setNum(int n)
{
num=n;
}
void setName(char *na)
{
name=na;
}
void setSex(char s)
{
sex=s;
}
void setGrade(float m,float e,float c)
{
g_math=m;
g_english=e;
g_computer=c;
}
float getGrade()
{
return (g_math+g_english+g_computer);
}
void isGood()
{
if((g_math+g_english+g_computer)>=255)
cout< else
cout< }
};
void main()
{student s1(0710,"xiaoming",'m',89,98,83);
s1.isGood();
student s2(0711,"xiaohua",'w',89,90,83);
s2.isGood();
student s3(0712,"wangming",'m',80,98,83);
s3.isGood();
student s4;
s4.setGrade(100,100,100);
s4.setNum(0713);
s4.setName("ma jin");
s4.setSex('m');

s4.isGood();
student s5(0714,"cos",'w',99,98,100);
s3.isGood();
}