上面是运行遇到的错误,编译是通过的
原本186行187行是没有new的 遇到的问题是system.nullreferenceexception
不知道要如何修改了 望大佬相助
做一个人员信息管理系统
以下是源代码
#include<iostream>
#include<string>
#include<fstream>
#include<stdlib.h>
using namespace std;
void check(double x)
{if(x<0)throw x;}
class people
{public:
void print()
{cout<<"名字"<<number<<"生日"<<birthday<<"年龄"<<age<<"名字"<<name<<"性别"<<sex<<"科目"<<major<<"系别"<<department;};
int age,i,j;
string number,birthday,name,sex,major,department;
};
class student:virtual public people
{public:
friend istream& operator>>(istream &in,student &p);
friend ostream& operator<<(ostream &out,student &p);
void adddata();
void deletedata();
void updatedata();
void search();
void findmaxdata();
void displaydata();
protected:
int chinese,math,english;
};
student stu[30];
istream& operator>>(istream &in,student &p)
{in>>p.number>>p.birthday>>p.age>>p.name>>p.sex>>p.major>>p.department>>p.chinese>>p.math>>p.english;
return in;};
ostream& operator<<(ostream &out,student &p)
{out<<"名字"<<p.number<<"生日"<<p.birthday<<"年龄"<<p.age<<"名字"<<p.name<<"性别"<<p.sex<<"科目"<<p.major<<"系别"<<p.department<<"语文"<<p.chinese<<"数学"<<p.math<<"英语"<<p.english;
return out;};
void student::adddata()
{cout<<"请分别输入学号 生日 年龄 名字 性别 专业 系别 语文成绩 数学成绩 英语成绩";
cin>>stu[i];
i++;
};
void student::deletedata()
{string del;
int v=0;
cin>>del;
for(v=0;v<i;v++)
if(stu[v].number==del)
break;
for(v;v<i;v++)
stu[v]=stu[v+1];
i--;
};
void student::updatedata()
{string del;
cin>>del;
for(int v=0;v<i;v++)
if(stu[v].number==del)
break;
cout<<"请分别输入学号 生日 年龄 名字 性别 专业 系别 语文成绩 数学成绩 英语成绩";
cin>>number>>birthday>>age>>name>>sex>>major>>department>>chinese>>math>>english;
};
void student::search()
{string fi;
cin>>fi;
for(int e=0;e<i;e++)
if(stu[e].name==fi||stu[e].number==fi||stu[e].sex==fi)
cout<<stu[e]<<endl;
};
void student::findmaxdata()
{int max=0;
for(int m=0;m<i;m++)
if(stu[m].english>max)
max=stu[m].english;
cout<<max<<endl;
};
void student::displaydata()
{for(int m=0;m<i;m++)
cout<<stu[m]<<endl;
};
class teacher:virtual public people
{public:
friend istream& operator>>(istream &in,teacher &p);
friend ostream& operator<<(ostream &out,teacher &p);
void adddata();
void deletedata();
void updatedata();
void search();
void findmaxdata();
void displaydata();
protected:
string title;double salary;
};
teacher tea[30];
istream& operator>>(istream &in,teacher &p)
{in>>p.number>>p.birthday>>p.age>>p.name>>p.sex>>p.major>>p.department>>p.title>>p.salary;
return in;
};
ostream& operator<<(ostream &out,teacher &p)
{cout<<"名字"<<p.number<<"生日"<<p.birthday<<"年龄"<<p.age<<"名字"<<p.name<<"性别"<<p.sex<<"科目"<<p.major<<"系别"<<p.department<<"职称"<<p.title<<"工资"<<p.salary;
return out;
};
void teacher::adddata()
{cout<<"请分别输入学号 生日 年龄 名字 性别 专业 系别 职位 工资";
cin>>tea[j];
j++;
try
{check(salary);}
catch(...)
{cout<<"工资异常"<<endl;}
};
void teacher::deletedata()
{string del;
int v=0;
cin>>del;
for(v=0;v<j;v++)
if(tea[v].number==del)
break;
for(v;v<j;v++)
tea[v]=tea[v+1];
j--;
};
void teacher::updatedata()
{string del;
cin>>del;
for(int v=0;v<j;v++)
if(tea[v].number==del)
break;
cout<<"请分别输入学号 生日 年龄 名字 性别 专业 系别 职位 工资";
cin>>number>>birthday>>age>>name>>sex>>major>>department>>title>>salary;
try
{check(salary);}
catch(...)
{cout<<"工资异常"<<endl;}
};
void teacher::search()
{string fi;
cin>>fi;
for(int q=0;q<j;q++)
if(tea[q].name==fi||tea[q].number==fi||tea[q].sex==fi)
cout<<tea[q]<<endl;
};
void teacher::findmaxdata()
{double maxs=0;
for(int n=0;n<j;n++)
if(tea[n].salary>maxs)
maxs=tea[n].salary;
cout<<maxs<<endl;
};
void teacher::displaydata()
{for(int e=0;e<j;e++)
cout<<tea[e]<<endl;
};
int main()
{int choice,time=0,choice2,i=0,j=0;
string test,password="12345";
cout<<"请输入密码,您有三次机会(密码12345)"<<endl;
while(time<3)
{cin>>test;
if(test==password)
{time=10;system("cls");
system("color 30");
cout << "******************************************" << endl;
cout << "********* 欢迎进入学生成绩管理系统 *********" << endl;
cout << " 1.增加一位人员记录 " << endl;
cout << " 2.删除一个人员记录 " << endl;
cout << " 3.修改一个人员记录 " << endl;
cout << " 4.查找记录 " << endl;
cout << " 5.查找英语最高或工资最高成员 " << endl;
cout << " 6.显示全部人员记录 " << endl;
cout << " 7.从外部文件追加数据 " << endl;
cout << " 8.将所有数据保存到磁盘文件 " << endl;
cout << " 9.退出系统 " << endl;
cout << "******************************************" << endl;
cout << " 选择1-9数字进行操作 "<<endl;
cout << endl;
student *p=new student();
teacher *p1=new teacher();
cin>>choice;
switch(choice)
{
case 1:
{
cout<<"学生输入1,教师输入2"<<endl;
cin>>choice2;
if(choice2==1)
{p->adddata();}
else
{p1->adddata();}
}
case 2:
{cout<<"学生输入1,教师输入2"<<endl;
cin>>choice2;
if(choice2==1)
{p->deletedata();}
else
{p1->deletedata();}
}
case 3:
{cout<<"学生输入1,教师输入2"<<endl;
cin>>choice2;
if(choice2==1)
{p->updatedata();}
else
{p1->updatedata();}
}
case 4:
{cout<<"学生输入1,教师输入2"<<endl;
cin>>choice2;
if(choice2==1)
{p->search();}
else
{p1->search();}
}
case 5:{cout<<"学生输入1,教师输入2"<<endl;
cin>>choice2;
if(choice2==1)
{p->findmaxdata();}
else
{p1->findmaxdata();}
}
case 6:
{ p->displaydata();
p1->displaydata();}
default:
{break;}
}
}
else
{time++;
cout<<"您还有"<<3-time<<"次机会"<<endl;}
}
return 0;
}