//操纵类的实现
#include<iostream>
#include<iomanip>
#include<fstream>
#include<string>
#include<conio.h>
#include"Operater.h"
using namespace std;
//操纵类构造函数
Operater::Operater(void)
{
infChanged=false;
}
/////////////////////////////////菜单/////////////////////////////////////
//主菜单
void Operater::MainMenu()
{
char choice,savechoice;
do
{
system("cls");
cout<<endl<<endl<<endl;
cout<<"\t\t\t┇ 欢迎进入 ┇ "<<endl;
cout<<"\t\t\t┇学生信息管理系统┇ "<<endl;
cout<<"\t\t\t┍┅┅┅┅┅┅┅┅┑"<<endl;
cout<<"\t\t\t┆1---读取学生信息┆"<<endl;
cout<<"\t\t\t┆2---显示所有姓名┆"<<endl;
cout<<"\t\t\t┆3---添加学生信息┆"<<endl;
cout<<"\t\t\t┆4---查询学生信息┆"<<endl;
cout<<"\t\t\t┆5---修改学生信息┆"<<endl;
cout<<"\t\t\t┆6---删除学生信息┆"<<endl;
cout<<"\t\t\t┆7---保存学生信息┆"<<endl;
cout<<"\t\t\t┆0---退出本系统 ┆"<<endl;
cout<<"\t\t\t┕┅┅┅┅┅┅┅┅┙"<<endl;
cout<<"\t\t\t请输入您的选择[0-6]:";
choice=getche();
cout<<endl;
switch(choice)
{
case '1':ReadInf();break;
case '2':
system("cls");
ShowAllName(stuList);
cout<<"\n\t\t 按任意键返回";
getch();
break;
case '3':AddInf();break;
case '4':SearchMenu();break;
case '5':CorrectMenu();break;
case '6':DeleteMenu();break;
case '7':WriteInf();break;
case '0':
if(infChanged)
{
cout<<"\n\n\t\t\t是否保存改动?(Y/N)";
do
{
savechoice=getche();
}while(savechoice!='Y'&&savechoice!='y'&&savechoice!='N'&&savechoice!='n');
cout<<endl;
if(savechoice=='Y'||savechoice=='y')
WriteInf();
}
cout<<endl;
cout<<"\t ┌┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┐"<<endl;
cout<<"\t ┆感谢您的使用Y(^_^)Y 09计本一 刘青┆"<<endl;
cout<<"\t └┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┘";
getch();
exit(1);
default:cout<<"\n\t\t\t无效的选项,请重新输入。"<<endl;
}
}while(choice!='0');
}
//删除菜单
void Operater::DeleteMenu(void)
{
char choice;
if(stuList.ListEmpty())
{
system("cls");
cout<<"\n\n\n\n\n\n\n\t\t暂无任何学生信息,按任意键返回。";
getch();
return;
}
do
{
system("cls");
ShowAllName(stuList);
cout<<endl;
cout<<"\t┏┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┓"<<endl;
cout<<"\t┇ 删除学生信息 ┇"<<endl;
cout<<"\t┠┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┨"<<endl;
cout<<"\t┇1.按编号删除 2.按姓名删除 3.删除所有学生信息 4.返回 ┇"<<endl;
cout<<"\t┗┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┛"<<endl;
cout<<"\t 请选择[1-4]:";
choice=getche();
cout<<endl;
switch(choice)
{
case '1':
DeleteInfByNum();
break;
case '2':
DeleteInfByName();
break;
case '3':
stuList.ClearList();
cout<<"\n\t\t\t所有学生信息已清空。";
getch();
break;
case '4':break;
default:cout<<"\n\t\t\t无效的选择。";break;
}
}while(choice!='4');
}
//修改菜单
void Operater::CorrectMenu(void)
{
char choice;
if(stuList.ListEmpty())
{
system("cls");
cout<<"\n\n\n\n\n\n\n\t\t暂无任何学生信息,按任意键返回。"<<endl;
getch();
return;
}
do
{
system("cls");
ShowAllName(stuList);
cout<<endl;
cout<<"\t\t┎────────────────────┒"<<endl;
cout<<"\t\t┃ 修改学生信息 ┃"<<endl;
cout<<"\t\t┠────────────────────┨"<<endl;
cout<<"\t\t┃1.按编号修改 2.按姓名修改 3.返回┃"<<endl;
cout<<"\t\t┖────────────────────┚"<<endl;
cout<<"\t\t 请选择[1-3]:";
choice=getche();
cout<<endl;
switch(choice)
{
case '1':CorrectInfByNum(stuList);break;
case '2':CorrectInfByName();break;
case '3':break;
default:cout<<"\n\t\t\t\t无效的选择。"<<endl;
}
}while(choice!='3');
}
//查询菜单
void Operater::SearchMenu(void)
{
char choice;
if(stuList.ListEmpty())
{
system("cls");
cout<<"\n\n\n\n\n\n\n\t\t暂无任何学生信息,按任意键返回。"<<endl;
getch();
return;
}
do
{
system("cls");
ShowAllName(stuList);
cout<<endl;
cout<<"\t\t\t ┎────────┒"<<endl;
cout<<"\t\t\t ┃查询学生详细信息┃"<<endl;
cout<<"\t\t\t ┠────────┨"<<endl;
cout<<"\t\t\t ┃ 1.按编号 ┃"<<endl;
cout<<"\t\t\t ┃ 2.按姓名 ┃"<<endl;
cout<<"\t\t\t ┃ 3.按性别 ┃"<<endl;
cout<<"\t\t\t ┃ 4.按出生日期 ┃"<<endl;
cout<<"\t\t\t ┃ 5.返回 ┃"<<endl;
cout<<"\t\t\t ┖────────┚"<<endl;
cout<<"\t\t\t 请选择[1-5]:";
choice=getche();
cout<<endl;
switch(choice)
{
case '1':SearchInfByNum();break;
case '2':SearchInfByName();getch();break;
case '3':SearchInfBySex();getch();break;
case '4':SearchInfByBirth();getch();break;
case '5':break;
default:cout<<"\n\t\t\t无效的选择。"<<endl;
}
}while(choice!='5');
}
//////////////////////////////////显示/////////////////////////////////////
//显示学生总数
void Operater::ShowAllName(List<Student> &p)
{
if(p.ListEmpty())
{
cout<<"\n\n\n\n\n\n\n\t\t 暂无任何学生信息。"<<endl;
return;
}
int num=1;
Student p0;
p.Reset();
cout<<"\n\t\t 学生总数:"<<p.ListNodeSum()<<endl;
cout<<setiosflags(ios_base::left);
cout<<"\t\t *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"<<endl;
cout<<"\t\t "<<setw(6)<<"编号"<<setw(10)<<"姓名"<<setw(7)<<"性别"<<setw(13)<<"出生日期"<<endl;
while(!p.EndOfList())
{
p0=p.Data();
cout<<"\t\t "<<setw(6)<<num<<setw(10)<<p0.name<<setw(7)<<p0.sex<<setw(13)<<p0.birthday<<endl;
p.Next();
num++;
}
cout<<"\t\t *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"<<endl;
cout<<resetiosflags(ios_base::left);
}
//显示单个学生信息
void Operater::ShowSingleInf(const Student &p)
{
cout<<setiosflags(ios_base::left)<<endl;
cout<<"\t\t┏━━━━━━━━━━━━━━━━━━━━┓"<<endl;
cout<<"\t\t┃-*-*-*-*-*-*-*-个人信息-*-*-*-*-*-*-*-*-┃"<<endl;
cout<<"\t\t┃"<<setw(10)<<"姓名:"<<setw(30)<<p.name<<"┃"<<endl;
cout<<"\t\t┃"<<setw(10)<<"性别:"<<setw(30)<<p.sex<<"┃"<<endl;
cout<<"\t\t┃"<<setw(10)<<"民族:"<<setw(30)<<p.nation<<"┃"<<endl;
cout<<"\t\t┃"<<setw(10)<<"国籍:"<<setw(30)<<p.nationality<<"┃"<<endl;
cout<<"\t\t┃"<<setw(10)<<"学历:"<<setw(30)<<p.degree<<"┃"<<endl;
cout<<"\t\t┃"<<setw(10)<<"地址:"<<setw(30)<<p.address<<"┃"<<endl;
cout<<"\t\t┃"<<setw(10)<<"出生日期:"<<setw(30)<<p.birthday<<"┃"<<endl;
cout<<"\t\t┃-*-*-*-*-*-*-*-联系方式-*-*-*-*-*-*-*-*-┃"<<endl;
cout<<"\t\t┃"<<setw(10)<<"手机:"<<setw(30)<<p.tel<<"┃"<<endl;
cout<<"\t\t┃"<<setw(10)<<"家庭电话:"<<setw(30)<<p.homephone<<"┃"<<endl;
cout<<"\t\t┃"<<setw(10)<<"学校电话:"<<setw(30)<<p.schoolphone<<"┃"<<endl;
cout<<"\t\t┃-*-*-*-*-*-*-*-学科成绩-*-*-*-*-*-*-*-*-┃"<<endl;
cout<<"\t\t┃"<<setw(10)<<"语文:"<<setw(30)<<p.chinese<<"┃"<<endl;
cout<<"\t\t┃"<<setw(10)<<"数学:"<<setw(30)<<p.math<<"┃"<<endl;
cout<<"\t\t┃"<<setw(10)<<"英语:"<<setw(30)<<p.english<<"┃"<<endl;
cout<<"\t\t┃"<<setw(10)<<"物理:"<<setw(30)<<p.physics<<"┃"<<endl;
cout<<"\t\t┗━━━━━━━━━━━━━━━━━━━━┛"<<endl;
cout<<resetiosflags(ios_base::left);
}
//////////////////////////////操纵///////////////////////////////////////
//添加学生信息
void Operater::AddInf()
{
Student p;
char sexchoice;
do
{
system("cls");
cout<<"\n\t\t---------<请输入新增的学生信息>---------"<<endl;
cout<<"\n\t\t姓名(不超过4个字,输入 0 返回):";
cin>>setw(9)>>p.name;
cout<<endl;
if(strcmp(p.name,"0")==0)return;
do
{
cout<<"\t\t性别(1.男 2.女):";
sexchoice=getche();
cout<<endl;
}while(sexchoice!='1' && sexchoice!='2');
if(sexchoice=='1')
strcpy(p.sex,"男");
else
strcpy(p.sex,"女");
cout<<endl;
cout<<"\t\t民族(不超过5个字):";
cin>>setw(11)>>p.nation;
cout
C++课程设计 学生信息管理 源代码
4星 · 超过85%的资源 需积分: 11 86 浏览量
2010-08-31
15:49:02
上传
评论 4
收藏 8KB RAR 举报
carlos23
- 粉丝: 13
- 资源: 10
- 1
- 2
前往页