求大神修改一下这个程序,自己写了半天但是没弄好
#include<iostream>#include<string.h>
using namespace std;
struct SUBJECT //课程信息结构体
{
char name[64]; //课程名称
int level; //课程等级
};
class STUDENT
{
public:
STUDENT(int nMax); //参数nMax的值传给成员变量m_nMax
virtual ~STUDENT();
void AddNewSubject(SUBJECT &szSub); //添加新课程
SUBJECT* GetSubject(int nIndex); //获取指定编号的课程
int GetSubjectCount(); //获取当前课程数目
private:
int m_nSubjectCount; //当前课程数目
int m_nMax; //最大课程数目
SUBJECT* pSubject; //课程结构体指针
SUBJECT* buffer;
};
STUDENT::STUDENT(int nMax)
{
m_nMax=nMax;;
buffer=new SUBJECT[m_nMax];
if(buffer!=NULL)
{
pSubject=buffer;
}
else
{
exit(1);
}
cout<<"栈空间已成功建立!"<<endl;
}
STUDENT::~STUDENT()
{
delete []pSubject;
cout<<"内存清理完毕!"<<endl;
}
void STUDENT::AddNewSubject(SUBJECT &szSub)
{
cout<<"当输入的课程等级为0时,输入终止"<<endl;
m_nSubjectCount=2;
int i=m_nSubjectCount;
//pSubject[i-1].name[64]=szSub.name[64];
//pSubject[i-1].level=szSub.level;
while(szSub.level != 0)
{
*pSubject= szSub;
cout<<"请输入课程名称"<<endl;
cin>>szSub.name;
cout<<"请输入课程等级"<<endl;
cin>>szSub.level;
i++;
}
}
SUBJECT*STUDENT::GetSubject(int nIndex)
{
if(nIndex<10)
{
cout<<"查询的科目为:"<<endl;
cout<<&pSubject[nIndex]<<endl;
return 0;
}
else
{
cout<<"输入的课程编号错误,请重新输入!"<<endl;
return NULL;
}
}
int STUDENT::GetSubjectCount()
{
cout<<"当前课程数目为:"<<endl;
cout<<m_nSubjectCount<<endl;
return 0;
}
int main(void)
{
SUBJECT pSubject[2]={"大学物理",120,"大学英语",121};
STUDENT(10);
STUDENT stu(10);
SUBJECT szSub;
cout<<"请输入课程名称"<<endl;
cin>>szSub.name;
cout<<"请输入课程等级"<<endl;
cin>>szSub.level;
stu.AddNewSubject(szSub);
int n;
cout<<"请输入要查找的课程编号为:"<<endl;
cin>>n;
stu.GetSubject(n);
stu.GetSubjectCount();
return 0;
}