求助:问题出在哪?(C++学生成绩管理系统)
我的这个程序有时运行起来会出现不同的问题,例如:
1.删除后在输出,有时却只输出0,但查询时,学生数据却没有消失。
2.插入成员后,输出就会有问题,但插入是成功的。
3.查询时,有的成员却查不到。
……
请大家多多帮忙,在下不胜感激!^_^
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
const int m=8;
int n=0;
struct student
{
int num;
string name;
int age;
char sex;
int score[4];
int sum;
}stu[m];
int main()
{cout < < " ~ 欢迎进入学生成绩管理系统! ~ " < <endl;
cout < < " **** 学生成绩管理系统 **** " < <endl;
cout < < " " < <endl;
cout < < " 制作人:06电信(2)班24号 " < <endl;
cout < < " 黄元汶 " < <endl;
cout < <endl;
cout < < " 指导老师: 黄建华院长 " < <endl;
cout < <endl;
q:
{
cout < < " 请选择数字1-7进行操作: " < <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 < < " ************************** " < <endl;
}
void input_date();
void output_date();
void shanchu();
void chaxun();
void charu();
void xiugai();
void charu();
int p;int flag=0;
cin> > p;
do
{if(1 <=p&&p <=7)
flag=1;
else
{cout < < " 您输入的指令有误,请重新输入! " < <endl;
flag=0;goto q;
flag=1;}
}while(flag==0);
switch(p)
{
case 1:
{cout < < "您现在进行的操作是:输入数据 " < <endl;
char b;
cout < < "确认要进行此操作吗(y/n)? " < <endl;
cin> > b;
if(b!= 'n '&&b!= 'y ')
{cout < < " 您的输入有误,请重新输入! " < <endl;
cin> > b;}
if(b== 'n ')
{goto q;}
if(b== 'y ')
{input_date();
cout < <endl;
goto q;
}
break;
}
case 2:
{cout < < "您现在选择的操作是:输出数据 " < <endl;
char b;
cout < < "确认要进行此操作吗(y/n)? " < <endl;
cin> > b;
if(b!= 'n '&&b!= 'y ')
{cout < < " 您的输入有误,请重新输入! " < <endl;
cin> > b;}
if(b== 'n ')
{goto q;}
if(b== 'y ')
{output_date();
cout < <endl;
goto q;
}
break;
}
case 3:
{cout < < "您现在进行的操作是:删除成员 " < <endl;
char b;
cout < < "确认要进行此操作吗(y/n)? " < <endl;
cin> > b;
if(b!= 'n '&&b!= 'y ')
{cout < < " 您的输入有误,请重新输入! " < <endl;
cin> > b;}
if(b== 'n ')
{goto q;}
if(b== 'y ')
{shanchu();
cout < <endl;
goto q;
}break;}
case 4:
{cout < < "您现在进行的操作是:信息查询 " < <endl;
char b;
cout < < "确认要进行此操作吗(y/n)? " < <endl;
cin> > b;
if(b!= 'n '&&b!= 'y ')
{cout < < " 您的输入有误,请重新输入! " < <endl;
cin> > b;}
if(b== 'n ')
{goto q;}
if(b== 'y ')
{chaxun();
cout < <endl;
goto q;
}break;}
case 5:
{cout < < "您现在进行的操作是:修改信息 " < <endl;
char b;
cout < < "确认要进行此操作吗(y/n)? " < <endl;
cin> > b;
if(b!= 'n '&&b!= 'y ')
{cout < < " 您的输入有误,请重新输入! " < <endl;
cin> > b;}
if(b== 'n ')
{goto q;}
if(b== 'y ')
{xiugai();
cout < <endl;
goto q;
}break;}
case 6:
{cout < < "您现在进行的操作是:插入成员 " < <endl;
char b;
cout < < "确认要进行此操作吗(y/n)? " < <endl;
cin> > b;
if(b!= 'n '&&b!= 'y ')
{cout < < " 您的输入有误,请重新输入! " < <endl;
cin> > b;}
if(b== 'n ')
{goto q;}
if(b== 'y ')
{charu();
cout < <endl;
goto q;
}break;}
case 7:
{
cout < < " * 欢迎使用 * " < <endl;
cout < < " byebye " < <endl;
exit(0);
}
default:cout < <endl;
}
return 0;
}
(见下个提问)
[解决办法]
下次把代码贴到相应区域,容易看些~
[解决办法]
goto?少见