我是新手,求高手帮我看看下面这个程序....
程序分为以下几个部分:student.h
#ifndef SHAPE_H
#define SHAPE_H
struct credit
{
char course[20];
int hour;
char type[5];
};
class Student
{
protected:
char *name;
int student_ID;
credit credit_hour[10];
int num;
public:
Student();
virtual~Student(){};
char *getname();
virtual void InputInfo();
virtual void input_credit()=0;
virtual void displayInfo()=0;
virtual int GetStuNum();
};
class UnderGraduate:public Student
{public:
virtual void InputInfo();
virtual void Input_credit();
virtual void displayInfo();
int GetStuNum();
private:
static int StuNum;
};
class Graduate:public Student
{
public:
virtual void InputInfo();
virtual void input_credit();
virtual void displayInfo();
int GetStuNum();
private:
static int StuNum;
char *tutor;
};
#endif
student.cpp
# include <iostream>
# include<iomanip>
using namespace std;
# include "student.h"
int UnderGraduate::StuNum=0;
int Graduate::StuNum=0;
Student::Student()
{num=0;
}
void Student::InputInfo()
{
char namestr[20];
cout<<"请输入下一个学生的姓名:";
cin>>namestr;
name=new char[strlen(namestr)+1];
strcpy(name,namestr);
cout<<"输入学生的学号:";
cin>>student_ID;
}
char *Student::getname()
{return name;
}
void UnderGraduate::InputInfo()
{
Student::InputInfo();
StuNum++;
}
void UnderGraduate::Input_credit()
{
char answer;
do{cout<<"输入课程名称,学分,课程类别:必修?选修\n";
cin>>credit_hour[num].course>>credit_hour[num].hour>>credit_hour[num].type;
num++;
cout<<"继续输入课程?\n";
cin>>answer;
}
while(answer=='y');
}
int UnderGraduate::GetStuNum()
{return StuNum;
}
void UnderGraduate::displayInfo()
{
cout<<"本科学生姓名:"<<name;
cout<<" 学号: "<<student_ID<<endl;
cout<<"课程名称 学分 课程类别 \n";
for(int i=0;i<num;i++)
cout<<left<<setw(10)<<credit_hour[i].course
<<setw(10)<<credit_hour[i].hour
<<setw(10)<<credit_hour[i].type<<endl;
}
void Graduate::InputInfo()
{
char namestr[20];
Student::InputInfo();
StuNum++;
cout<<"请输入导师名字:";
cin>>namestr;
tutor=new char[strlen(namestr)+1];
strcpy(tutor,namestr);
}
void Graduate::input_credit()
{
char answer;
do
{
cout<<"输入课程的名称、学分、课程类别:学位/任选\n";
cin>>credit_hour[num].course>>credit_hour[num].hour>>credit_hour[num].type;
num++;
cout<<"还有课程要输入?";
cin>>answer;
}
while(answer=='y');
}
int Graduate::GetStuNum()
{
return StuNum;
}
void Graduate::displayInfo()
{
cout<<"研究生姓名: "<<name;
cout<<" 学号 : "<<student_ID<<endl;
cout<<"导师姓名 :"<<tutor<<endl;
cout<<"课程名称 学分 课程类别\n";
for(int i=0;i<num;i++)
cout<<left<<setw(10)<<credit_hour[i].course
<<setw(10)<<credit_hour[i].hour
<<setw(10)<<credit_hour[i].type<<endl;
}
main.cpp
# include<iostream.h>
# include<string.h>
# include "student.h"
Student**SelectStuType(Student *Array_ptr[][10]);
void creat_object(Student *Array_ptr[][10]);
void DisplayStu(Student *Array_ptr[][10]);
void InputCredit(Student *Array_ptr[][10]);
void main()
{
UnderGraduate UnderStu[10];
Graduate GraduateStu[10];
Student *Stu_ptr[2][10];
for(int i=0;i<10;i++)
Stu_ptr[0][i]=&UnderStu[i];
for(i=0;i<10;i++)
Stu_ptr[1][i]=&GraduateStu[i];
creat_object(Stu_ptr);
InputCredit(Stu_ptr);
DisplayStu(Stu_ptr);
}
Student **SelectStuType(Student *Array_ptr[][10])
{
char type;
Student **ptr=NULL;
do{
cout<<"请选择学生类型:";
cout<<"U本科生:G研究生:";
cin>>type;
switch(type)
{
case 'U':
ptr=Array_ptr[0];
break;
case 'G':
ptr=Array_ptr[1];
break;
default:cout<<"类型错误,请重新选择\n";
}
}while(ptr==NULL);
return ptr;
}
void creat_object(Student *Array_ptr[][10])
{char answer;
Student **row_ptr;
Student *ptr=NULL;
cout<<"输入学生的基本信息\n";
do
{
row_ptr=SelectStuType(Array_ptr);
ptr=*(row_ptr+(row_ptr[0])->GetStuNum());
ptr->InputInfo();
cout<<"继续输入学生基本信息(y/n)?";
cin>>answer;
}while(answer=='y');
}
void DisplayStu(Student *Array_ptr[][10])
{
char answer;
Student **row_ptr;
Student *ptr=NULL;
int StuNum;
cout<<"显示学生基本信息\n";
do
{
row_ptr=SelectStuType(Array_ptr);
ptr=*row_ptr;
StuNum=ptr->GetStuNum();
for(int i=0;i<StuNum;i++)
row_ptr[i]->displayInfo();
cout<<"继续显示学生信息(y/n)?";
cin>>answer;
}while(answer=='y');
}
void InputCredit(Student *Array_ptr[][10])
{
char answer;
Student**row_ptr;
Student *ptr=NULL;
int StuNum;
cout<<"输入已选课程、学分、课程类型\n";
do{
row_ptr=SelectStuType(Array_ptr);
ptr=*row_ptr;
StuNum=ptr->GetStuNum();
for(int i=0;i<StuNum;i++)
{cout<<"输入"<<row_ptr[i]->getname()<<"的课程和学分:\n";
row_ptr[i]->input_credit();
}
cout<<"继续输入其他类别学生的课程和学分(y/n)?";
cin>>answer;
}while(answer=='y');
}
程序有点长,求帮帮忙,小弟感激不尽...