急求C++高手,C++高手赶紧来,在线等!!!

2024-10-29 02:26:08
推荐回答(2个)
回答1:

//具体实现已经给出,需要在主函数中怎么调用,自己看看就知道了
struct Score
{
float score1;
float score2;
};
class StudentMessage
{
private:
//学生信息的数据部分
int num; //学号
char name[10]; //姓名
char sex; //性别
int age; //年龄
char national[10]; //民族
char address[20]; //地址
char phone[11]; //联系方法
char major[10]; //专业
Score score; //成绩
public:
//学生信息的操作部分
StudentMessage()
{
++studentNum;
}
void EnterMessage();
void EnterScore(Score);
void ShowMessage();
void ModifyMessage(const char *addr);
int UnpassedCount();
public:
static int studentNum;
int GetNum() const {return num;}
char* GetName() {return name;}
float Getscore1() const {return score.score1;}
float Getscore2() const {return score.score2;}
};

int StudentMessage::studentNum = 0;

void StudentMessage::EnterMessage()
{
cout<<"please enter student message:"< cout<<"num:";
cin>>num;
cout<<"name:";
cin>>name;
cout<<"sex:";
cin>>sex;
cout<<"age:";
cin>>age;
cout<<"national:";
cin>>national;
cout<<"address:";
cin>>address;
cout<<"phone:";
cin>>phone;
cout<<"major:";
cin>>major;
cout<<"score1:";
cin>>score.score1;
cout<<"score2:";
cin>>score.score2;
cout<<"student message end"<}
//成员函数的定义部分
void StudentMessage::EnterScore(Score s) //输入成绩
{
//填写功能代码
score = s;
}
void StudentMessage::ShowMessage() //显示学生信息
{
//填写功能代码
cout<<"num:"< <<" phone:"<}

void StudentMessage::ModifyMessage(const char * addr) //修改学生信息,可以考虑修改联系方法
{
//填写功能代码
strcpy(address, addr);
}

int StudentMessage::UnpassedCount() //输出不及格课程门数
{
//填写功能代码
int num = 0;
if(score.score1 < 60)
++num;

if(score.score2 < 60)
++num;

return num;
}

//全局函数的定义部分
void Enter(StudentMessage* p) //输入所有学生的信息
{
//填写功能代码
if(p == NULL)
return;

for(int i = 0; i < StudentMessage::studentNum; ++i)
{
p[i].EnterMessage();
}
}

void Show(StudentMessage* p) //显示所有学生的信息
{
//填写功能代码
if(p == NULL)
return;

for(int i = 0; i < StudentMessage::studentNum; ++i)
{
p[i].ShowMessage();
}
}

StudentMessage SearchByNum(StudentMessage* p,int n) //按学号查询指定的学生信息
{
//填写功能代码
for(int i = 0; i < StudentMessage::studentNum; ++i)
{
if(p[i].GetNum() == n)
{
return p[i];
}
}
}

StudentMessage SearchByName(StudentMessage* p,char n[]) //按姓名查询指定的学生信息
{
//填写功能代码
for(int i = 0; i < StudentMessage::studentNum; ++i)
{
if(0 == strcmp(p[i].GetName(), n))
{
return p[i];
}
}
}

float Sum(StudentMessage* p) //求某门课程总成绩
{
//填写功能代码
float sum = 0;
for(int i = 0; i < StudentMessage::studentNum; ++i)
{
sum += p[i].Getscore1();
}

return sum;
}

float Average(StudentMessage* p) //求某门课程的平均成绩
{
//填写功能代码
float sum = 0;
for(int i = 0; i < StudentMessage::studentNum; ++i)
{
sum += p[i].Getscore1();
}

sum /= StudentMessage::studentNum;

return sum;
}

int main()
{
return 0;
}

回答2:

你这是mfc编程?