c语言学生籍贯信息记录簿
#include<iostream.h> #include<string.h>
#include<fstream.h>
#include<stdlib.h>
class stu
{
char name[20];
int number;
char bornplace[50];
public:
stu()
{
}
stu(char n[20],int num,char born[50])
{
strcpy(name,n);
number=num;
strcpy(bornplace,born);
}
friend void main();
};
void main()
{
cout<<"请选择您需要的操作!"<<endl;
cout<<" 操作:"<<endl;
cout<<"(0)数据录入"<<endl;
cout<<"(1)增加人员"<<endl;
cout<<"(2)删除人员"<<endl;
cout<<"(3)修改数据"<<endl;
cout<<" 查询:"<<endl;
cout<<"(4)按姓名查询"<<endl;
cout<<"(5)按学号查询"<<endl;
cout<<"(6)输出所有学生的籍贯信息"<<endl;
cout<<"(7)按籍贯查询"<<endl;
cout<<"选择相关操作请输入相对的括号里的阿拉伯数字!"<<endl;
char p;char w;
stu *s[50];
ofstream *file[50];
int i=0;
int j=0;
bool flag2=0;
do
{
cin>>p;
if((p>='0'&&p<='6'))
flag2=1;
else
cout<<"指令错误!请重新输入:"<<endl;
}while(flag2==0);
do{
switch(p)
{
case '0':
{
char c;
char name[20],bornplace[50];int number;
do{
cout<<"请输入姓名"<<endl;
cin>>name;
cout<<"请输入学号:"<<endl;
cin>>number;
cout<<"请输入籍贯:"<<endl;
cin>>bornplace;
file[j]=new ofstream("d:\\document.txt",ios::ate);
*file[j]<<"姓名"<<name<<"学号"<<number<<"籍贯"<<bornplace <<endl;
j++;
s[i]=new stu(name,number,bornplace);
i++;
cout<<"数据录入成功,想继续录入吗(y/n)"<<endl;
cin>>c;
flag2=0;
do
{
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<<endl;
cin>>c;
}
else
flag2=1;
}
while(flag2==0);
}
while(c=='y');
break;
}
case '4':
{
char t[20];
char c;
do
{
int flag1=0;
cout<<"请输入你要查询学生的姓名"<<endl;
cin>>t;
for(int q=0;q<i;q++)
{
if(strcmp((*s[q]).name,t)==0)
{
flag1=1;
cout<<"您要查询的学生是:"<<(*s[q]).name<<"学号是:"<<(*s[q]).number<<"籍贯是:"<<(*s[q]).bornplace<<endl;
}
}
if(flag1==0)
cout<<"对不起!您要查询的学生不存在!"<<endl;
cout<<"您想继续查询吗?(y/n)"<<endl;
cin>>c;
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<<endl;
cin>>c;
}
}
while(c=='y');
break;
}
case '5':
{
int n ;int j=0;char c;
do{
int flag=0;
cout<<"请输入你要查询的学生学号:"<<endl;
cin>>n;
for(int j=0;j<i;j++)
{ int no=((*s[j]).number);
if(no==n)
{
flag=1;
cout<<"您要查询的学生是:"<<(*s[j]).name<<endl;
cout<<"籍贯是:"<<(*s[j]).bornplace<<endl;
}
}
if(flag==0)
cout<<"对不起!您要查询的学生不存在!"<<endl;
cout<<"您想继续查询吗?(y/n)"<<endl;
cin>>c;
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<<endl;
cin>>c;
}
}
while(c=='y');
break;
}
case '7':
{
char m[20];int j=0;char c;
do{
int flag=0;
cout<<"请输入你要查询籍贯:"<<endl;
cin>>m;
for(int w=0;w<i;w++)
{
if(strcmp((*s[w]).bornplace,m)==0)
{
flag=1;
cout<<"您要查询的学生是:"<<(*s[w]).name<<endl;
cout<<"学号是:"<<(*s[w]).number<<endl;
}
}
if(flag==0)
cout<<"对不起!您要查询的学生不存在!"<<endl;
cout<<"您想继续查询吗?(y/n)"<<endl;
cin>>c;
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<<endl;
cin>>c;
}
}
while(c=='y');
break;
}
case '1':
{
char name[20],bornplace[50];int number;
char c;
do
{
cout<<"请输入您要增加的学生的姓名:"<<endl;
cin>>name;
cout<<"请输入学号:"<<endl;
cin>>number;
cout<<"请输入籍贯:"<<endl;
cin>>bornplace;
file[j]=new ofstream("d:\\document",ios::ate);
*file[j]<<"姓名"<<name<<"学号"<<number<<"籍贯"<<bornplace<<endl;
j++;
s[i]=new stu(name,number,bornplace);
i++;
cout<<"数据录入成功,想继续录入吗(y/n)"<<endl;
cin>>c;
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<<endl;
cin>>c;
}
}while(c=='y');
break;
}
case '2':
{
char name[20];bool flag3=0;char c;
do{
cout<<"请输入您要删除的学生姓名:"<<endl;
cin>>name;
for(int h=0;h<i;h++)
{
if(strcmp(name,s[h]->name)==0)
{
flag3=1;
i--;
do{
s[h]=s[h+1];
h++;
}while(h<=i);
}
}
if(flag3==0)
cout<<"您要求删除的对象本来就不存在!请检查输入的正确性!";
cout<<"要继续删除吗?(y/n)"<<endl;
cin>>c;
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<<endl;
cin>>c;
}
}while(c=='y');
break;
}
case '3':
{
char name[20],born[50];int num;;flag2=0;
char c;
do
{
cout<<"请输入您要修改的学生的姓名:"<<endl;
cin>>name;
for(int h=0;h<i;h++)
{
if(strcmp(name,s[h]->name)==0)
{
flag2=1;
cout<<"请输入新的学号:"<<endl;
cin>>num;
cout<<"请输入新的籍贯:"<<endl;
cin>>born;
s[h]->number=num;
strcpy(s[h]->bornplace,born);
cout<<"数据修改成功!";
}
}
if(flag2==0)
{
cout<<"您要修改的学生本来就不存在!请检查重新输入!"<<endl;
}
cout<<"想继续修改吗(y/n)"<<endl;
cin>>c;
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<<endl;
cin>>c;
}
}while(c=='y');
break;
}
case '6':
{
cout<<"本系统所有学生的籍贯信息如下:"<<endl;
if(i==0)
cout<<"管理系统中没有录入数据或者数据已经被删除!"<<endl;
for(int k=0;k<i;k++)
{
cout<<k+1<<" "<<"姓名:"<<" "<<s[k]->name<<" "<<
"学号:"<<" "<<s[k]->number<<" "<<"籍贯:"<<" "<<s[k]->bornplace
<<endl;
}
break;
}
}
cout<<"您想继续进行其他操作吗?(y/n)"<<endl;
bool flag4=0;
do
{
cin>>w;
if(w!='y'&&w!='n')
cout<<"指令错误!请重新输入!"<<endl;
else
flag4=1;
}while(flag4==0);
if(w=='y')
{cout<<"请选择您需要的操作!"<<endl;
cout<<" 操作:"<<endl;
cout<<"(0)数据录入"<<endl;
cout<<"(1)增加人员"<<endl;
cout<<"(2)删除人员"<<endl;
cout<<"(3)修改数据"<<endl;
cout<<" 查询:"<<endl;
cout<<"(4)按姓名查询"<<endl;
cout<<"(5)按学号查询"<<endl;
cout<<"(6)输出所有学生的籍贯信息"<<endl;
cout<<"(7)按籍贯查询"<<endl;
cout<<"选择相关操作请输入相对的括号里的阿拉伯数字!"<<endl;
}
cin>>p;
}while(w=='y');
for(int x=0;x<i;x++)
{
delete s[x];
cout<<"delete all members!"<<endl;
}
}
怎么改