一个学生信息管理的程序,选择1进入输入班级名称后面就出现错误了,但是编译的时候又没错。劳烦哪位高手看看,谢谢!
#include<iostream.h>#include<string.h>
class CPerson
{
private:
char *Name;
char *IDNo;
char *Tel;
char *Addr;
public:
CPerson()
{ }
~CPerson()
{
delete Name;
delete IDNo;
delete Tel;
delete Addr;
}
void in_a()
{
char *Name1;
char *IDNo1;
cout<<"请输入学生的姓名:";
cin>>Name1;
Name=new char[strlen(Name1)+1];
strcpy(Name,Name1);
cout<<"请输入身份证号:";
cin>>IDNo1;
IDNo=new char[strlen(IDNo1)+1];
strcpy(IDNo,IDNo1);
}
void in()
{
char *Tel1;
char *Addr1;
cout<<"请输入电话号码:";
cin>>Tel1;
Tel=new char[strlen(Tel1)+1];
strcpy(Tel,Tel1);
cout<<"请输入地址:";
cin>>Addr1;
Addr=new char[strlen(Addr1)+1];
strcpy(Addr,Addr1);
}
void show()
{
cout<<" 姓名"<<" 身份证号"<<" 电话"<<" 地址";
cin>>" Name">>" IDNo">>" Tel">>" Addr";
}
};
class CStudent:public CPerson
{
private:
char *StudNo;
float Math;
float English;
float Average;
public:
CStudent()
{ }
~CStudent()
{
delete StudNo;
}
void in_a()
{
char *StudNo1;
CPerson::in_a();
cout<<"请输入学号:";
cin>>StudNo1;
StudNo=new char[strlen(StudNo1)+1];
strcpy(StudNo,StudNo1);
}
void in()
{
float Math1;
float English1;
float Average1;
CPerson::in();
cout<<"请输入数学成绩:";
cin>>Math1;
cout<<"请输入英语成绩:";
cin>>English1;
Math=Math1;
English=English1;
Average1=(Math1+English1)/2;
Average=Average1;
}
void show()
{
CPerson::show();
cout<<" 学号"<<" 数学"<<" 英语"<<" 平均分";
cin>>" StudNo">>" Math">>" English">>" Average";
}
};
class CClass
{
private:
CStudent *p[50];
char ClassName;
int i;
public:
CClass()
{}
~CClass()
{}
void in_a()
{
cout<<"请输入班级的名称:";
cin>>ClassName;
p[i]->in_a();
p[i]->in();
}
void Insert()
{
int x=1;
p[i]=NULL;
while(x==1)
{
p[i]->in_a();
p[i]->in();
cout<<"是否继续输入,是请按1";
cin>>x;
i++;
}
}
void Add()
{
Insert();
}
void Updata()
{
char *num,*StudNo1;
Print();
cout<<"请输入你要修改的学生的学号:";
cin>>num;
if(strcmp(StudNo1,num)==0)
{
cout<<"请输入你要修改的学生的数据:";
p[i]->in();
p[i]->show();
}
}
void Print()
{
p[i]->show();
}
};
void Interface()
{
cout<<"**************欢迎进入学生信息管理系统********************";
cout<<" "<<endl;
cout<<" ☆☆☆☆☆☆ののののの☆☆☆☆☆☆ "<<endl;
cout<<" "<<endl;
cout<<" 1----创建班级 2----添加学生信息 "<<endl;
cout<<" 3----修改学生信息 4----删除学生信息 "<<endl;
cout<<" 5----打印学生信息 6----退出 "<<endl;
cout<<" "<<endl;
}
void main()
{
int a,flag=1;
char d;
char *Name,*IDNo,*Tel,*Addr,*StudNo;
float Math,English;
CClass obj;
while(flag)
{
Interface();
cout<<" 请输入你的选择:";
cin>>a;
switch(a)
{
case 1: obj.in_a();obj.Insert();break;
case 2: obj.Add();break;
case 3: obj.Updata();break;
//case 4: obj.Delete();break;
case 5: obj.Print();break;
//case 6: exit().\;break;
}
cout<<"是否继续,继续请按Y或y";
cin>>d;
if(d=='n'||d=='N')
flag=0;
}
}