一个C++的小实验,遇到了一点问题,希望有人能帮帮忙
实验要求是输入五个学生的学号,姓名,语文成绩,数学成绩,英语成绩. 程序算出各个学生的总成绩和平均成绩,要求按成绩的高低输出所有学生的信息(我没把排序功能包含进去,不知道该怎么排) 红色字体部分就是我觉得出问题的地方,但是我不知道怎么解决.就是有关成员数组初始化的
//这是头文件student.h
# if ! defined _STUDENT_H_
# define _STUDENT_H_
#include <iostream.h>
#include <string.h>
class Student
{
public:
Student(char *id,char *name,double ch,double math,double eng);
~Student();
void Show();
private:
char *StuNum;
char *StuName;
double ScoreOfCh;
double ScoreOfMath;
double ScoreOfEng;
double ScoreOfTotal;
double ScoreOfAver;
};
# endif
//student.cpp
#include <string.h>
#include "student.h"
Student::Student(char *id,char *name,double ch,double math,double eng)
{
StuNum = new char[strlen(id) + 1];
strcmp(StuNum,id);
StuName = new char[strlen(name) + 1];
strcmp(StuName,name);
ScoreOfCh = ch;
ScoreOfMath = math;
ScoreOfEng = eng;
ScoreOfTotal = ch + math + eng;
ScoreOfAver = ScoreOfTotal / 3;
};
Student::~Student()
{
delete []StuNum;
delete []StuName;
};
void Student::Show()
{
cout<<StuNum<<'\t'<<StuName<<'\t'<<ScoreOfCh<<'\t'<<ScoreOfMath<<'\t'<<ScoreOfEng<<'\t'<<ScoreOfTotal<<'\t'<<ScoreOfAver<<endl;
};
// yfnick.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "student.h"
#include <iostream.h>
int main(int argc, char* argv[])
{
cout<<"程序功能:记录五个学生的成绩,输出成绩\n";
Student *a[5];
for(int i = 0;i < 5;i ++)
{
char *id=NULL;
char *name=NULL;
double ch,math,eng;
cin>>id>>name>>ch>>math>>eng;
Student *b = new Student(id,name,ch,math,eng);
a[i] = b;
if (a[i] == NULL)
{
cout<<"申请内存失败"<<endl;
return 0;
}
}
cout<<"学生成绩如下"<<endl;
cout<<"学号 姓名 语文成绩 数学成绩 英语成绩 总成绩 平均成绩"<<endl;
a[0]->Show();
a[1]->Show();
a[2]->Show();
a[3]->Show();
a[4]->Show();
delete[] a;
return 0;
}
请大家多多指教!