写了一个简单的学员系统.就是没有文件输入输出
#include<iostream>#include<string>
int I;
using namespace std;
struct Xue
{
unsigned int bianhao;
string name;
unsigned int yuwen;
unsigned int shuxue;
}xueyuan[100];
void caidan();
void caidan01();
char xuanze();
void fuzhi(Xue &);
void chazhao(string, Xue []);
int main()
{
char ch;
string zhao, shanchu;
caidan();
while ((ch = xuanze())<'a' || ch>'d')
{
cout << "输入错误!请输入有效选项:";
}
while (ch != 'e')
{
switch (ch)
{
case 'a':
fuzhi(xueyuan[I]);
break;
case 'b':
cout << "输入姓名:";
cin >> zhao;
chazhao(zhao, xueyuan);
break;
case 'c':
int i;
cout << "输入姓名:";
cin >> shanchu;
for (i = 0; i < I&&shanchu != xueyuan[i].name; i++)
{
continue;
}
if (shanchu == xueyuan[i].name)
{
while (i < I)
{
xueyuan[i].bianhao = xueyuan[i + 1].bianhao;
xueyuan[i].name = xueyuan[i + 1].name;
xueyuan[i].yuwen = xueyuan[i + 1].yuwen;
xueyuan[i].shuxue = xueyuan[i + 1].shuxue;
i++;
}
I--;
}
else
cout << "没有你查找的人:\n";
break;
case 'd':
for (int j = 0; j < I; j++)
{
cout << xueyuan[j].bianhao << " " << xueyuan[j].name << " "
<< xueyuan[j].yuwen << " " << xueyuan[j].shuxue << endl;
}
break;
}
caidan();
while ((ch = xuanze())<'a' || ch>'d')
{
cout << "输入错误!请输入有效选项:";
}
}
system("pause");
return 0;
}
void caidan()
{
cout << "********************学生管理系统********************\n";
cout << "a)增加学员, b)查找学员\n";
cout << "c)删除学员, d)显示所有学员. e)退出\n";
cout << "****************************************************\n选择:";
}
char xuanze()
{
char c;
cin >> c;
while (cin.get() != '\n')
continue;
return c;
}
void fuzhi(Xue &xueyuan)
{
cout << "输入学员编号:";
while (!(cin >> xueyuan.bianhao))
{
cin.clear();
cin.sync();
cout << "乖~请正确输入:";
}
cout << "输入学员姓名:";
cin.sync();
cin >> xueyuan.name;
cout << "输入语文成绩:";
cin.sync();
while (!(cin >> xueyuan.yuwen))
{
cin.clear();
cin.sync();
cout << "乖~请正确输入:";
}
cout << "输入数学成绩:";
cin.sync();
while (!(cin >> xueyuan.shuxue))
{
cin.clear();
cin.sync();
cout << "乖~请正确输入:";
}
cout << "**********学员属性**********\n";
cout << "编号: " << xueyuan.bianhao << endl;
cout << "name: " << xueyuan.name << endl;
cout << "语文: " << xueyuan.yuwen << endl;
cout << "数学: " << xueyuan.shuxue << endl;
cout << "注册学员成功.\n";
I++;
}
void caidan01()
{
cout << "********************学生管理系统********************\n";
cout << "a)修改编号, b)修改姓名\n";
cout << "c)修改语文成绩, d)修改数学成绩,e)返回主菜单.\n";
cout << "****************************************************\n选择:";
}
void chazhao(string chazhao, Xue yuan[])
{
int i;
char ch;
for (i = 0; i < I&&chazhao != yuan[i].name; i++)
{
continue;
}
if (i == I)
{
cout << "查无此人!\n";
}
else
{
cout << "**********查找的学员属性**********\n";
cout << "编号: " << yuan[i].bianhao << endl;
cout << "name: " << yuan[i].name << endl;
cout << "语文: " << yuan[i].yuwen << endl;
cout << "数学: " << yuan[i].shuxue << endl;
system("pause");
caidan01();
while ((ch = xuanze())<'a' || ch>'e')
{
cout << "输入错误!请输入有效选项:";
}
while (ch != 'e')
{
switch (ch)
{
case 'a':
cout << "输入编号:";
cin.sync();
while (!(cin >> yuan[i].bianhao))
{
cin.clear();
cin.sync();
cout << "乖~请正确输入:";
}
cout << "修改以后的编号是:" << yuan[i].bianhao << endl;
break;
case 'b':
cout << "输入姓名:";
cin.sync();
cin >> yuan[i].name;
cout << "修改以后的姓名是:" << yuan[i].name << endl;
break;
case 'c':
cout << "输入语文成绩:";
cin.sync();
while (!(cin >> yuan[i].yuwen))
{
cin.clear();
cin.sync();
cout << "乖~请正确输入:";
}
cout << "修改以后的语文成绩是:" << yuan[i].yuwen << endl;
break;
case 'd':
cout << "输入数学成绩:";
cin.sync();
while (!(cin >> yuan[i].shuxue))
{
cin.clear();
cin.sync();
cout << "乖~请正确输入:";
}
cout << "修改以后的数学成绩是:" << yuan[i].shuxue << endl;
break;
}
caidan01();
while ((ch = xuanze())<'a' || ch>'e')
{
cout << "输入错误!请输入有效选项:";
}
}
}
}