📄 funtion.cpp
字号:
#include <iostream> //标准输入输出流
#include "Funtion.h"
//#include <sstream>
#include <fstream> //写入文件
#include <string>
#include <conio.h> //GETCHAR()
#include "Stu.h"
#include "Tea.h"
#include <cassert>
using namespace std;
//输出空格使其处于屏幕中间
void Nothing_Cout()
{
cout << " ";
cout << " ";
cout << " ";
cout << " ";
cout << " ";
cout << " ";
cout << " ";
cout << " 2008届海南大学应用技术学院计算机科学与技术通讯录 ";
cout << " ";
cout << " ";
cout << " ";
}
//显示第一层窗体
void Form1_Show()
{ system("cls");
cout << " ";
cout << " 2008届海南大学应用技术学院计算机科学与技术通讯录 ";
cout << " ";
cout << " ";
cout << " 0 返回 DOS 1 新增同学 2 新增老师 3 查询同学 ";
cout << " 4 查询老师 5 修改同学 6 修改老师 7 打印所有 ";
cout << " 8 删除学生 9 删除老师 A 所有同学 B 所有老师 ";
cout << endl;
char n; //窗体选择的操作
n=getch();
Form1_Select(n);
cout <<endl<< " [海南大学08计算机同学录] ";
//暂停
system("pause");
system("cls");
Form1_Show();
}
//第一层窗体的操作选择
int Form1_Select(char n1)
{
switch(n1)
{
case '0':
system("cls");
cout<<endl<<" 已成功退出同学录系统进入DOS系统"<<endl;
cout<<endl<<" 输入(EXIT)退出系统(HELP)查看帮助"<<endl<<endl<<endl;
system("cmd.exe");
return 0;
case '1':
AddStu();
break;
case '2':
AddTea();
break;
case '3':
//查询同学信息
Stu_search();
Form1_Show();
break;
case '4':
Tea_search();
Form1_Show();
break;
case '5':
//修改同学信息
stu_alter();
break;
case '6':
Tea_alter();
break;
case '7':
system("print stu\\123.txt");
Form1_Show();
//ShowAll();
break;
case '8':
StuDel();//删除同学
Form1_Show();
break;
case '9':
TeaDel();//删除老师
Form1_Show();
break;
case 'A':
ShowAll();
break;
case 'B':
TeaShowAll();
break;
default:
cout << "对不起你选择的结果有误!"<<endl;
return 0;
}
return 0;
}
//新增学生
void AddStu()
{
//显示出入信息模块
string name1;
string sex1;
string Birth1;
string Address1;
string Tel1;
string Home1;
string QQ1;
string PID1;
string StuID1; //学号
string speciality1;//专业
string ClassName1; //班级
string College1; //学院
string word1;//留言
cout<<" 请输入姓名: ";
cin>>name1;
cout<< endl <<" 请输入学号: ";
cin>>StuID1;
if(StuSelect(StuID1))
{
cout<<"对不起你输入的学号已存在请重新输入:"<<endl;
system("pause");
system("cls");
Form1_Show();
}
cout<<endl<<" 请输入性别: ";
cin>>sex1;
cout<<endl<<" 请输入出生年月: ";
cin>>Birth1;
cout<<endl<<" 请输入电话: ";
cin>>Tel1;
cout<<endl<<" 请输入出生地: ";
cin>>Home1;
cout<<endl<<" 请输入宿舍: ";
cin>>Address1;
cout<<endl<<" 请输入qq: ";
cin>>QQ1;
cout<<endl<<" 请输入身份证号: ";
cin>>PID1;
cout<<endl<<" 请输入专业: ";
cin>>speciality1;
cout<<endl<<" 请输入班级: ";
cin>>ClassName1;
cout<<endl<<" 请输入学院: ";
cin>>College1;
cout<<endl<<" 请输入留言: ";
cin>>word1;
Stu p1(name1,sex1,Birth1,Tel1,Home1,QQ1,PID1,speciality1,ClassName1,College1,word1,Address1);
//把学生的学号写入文件stu.dat中
ofstream save1("stu.dat",ios::app);
save1<<StuID1<<endl;
save1.close();
//把整个学生信息保存到记事本中文件名为学号
string txtname="stu\\"+StuID1+".txt";
p1.StuSave(txtname.c_str());
cout <<"信息存储完毕!!!!" <<endl <<endl;
system("pause");
}
//新增老师
void AddTea()
{
//显示出入信息模块
string name1;
string sex1;
string Birth1;
string Address1;
string Tel1;
string Home1;
string QQ1;
string PID1;
string WorkID1; //学号
string Kemu1;//专业
string word1;//留言
cout<<" 请输入姓名: ";
cin>>name1;
cout<< endl <<" 请输入工号: ";
cin>>WorkID1;
if(StuSelect(name1))
{
cout<<"对不起你输入的老师已存在请重新输入:"<<endl;
system("pause");
system("cls");
Form1_Show();
}
cout<<endl<<" 请输入性别: ";
cin>>sex1;
cout<<endl<<" 请输入出生年月: ";
cin>>Birth1;
cout<<endl<<" 请输入电话: ";
cin>>Tel1;
cout<<endl<<" 请输入出生地: ";
cin>>Home1;
cout<<endl<<" 请输入住址: ";
cin>>Address1;
cout<<endl<<" 请输入qq: ";
cin>>QQ1;
cout<<endl<<" 请输入身份证号: ";
cin>>PID1;
cout<<endl<<" 请输入学院: ";
cin>>Kemu1;
cout<<endl<<" 请输入留言: ";
cin>>word1;
Tea t1(name1,sex1,Birth1,Tel1,Home1,QQ1,PID1,WorkID1,Kemu1,word1,Address1);
//把学生的学号写入文件stu.dat中
ofstream save1("tea.dat",ios::app);
save1<<name1<<endl;
save1.close();
//把整个学生信息保存到记事本中文件名为学号
string txtname="tea\\"+name1+".txt";
t1.Teasave(txtname.c_str());
cout <<"信息存储完毕!!!!" <<endl <<endl;
system("pause");
}
//查询学生
void Stu_search()
{
cout<<"请输入你要查找的学号:"<<endl;
string sname;
cin>>sname;
//查找函数传递参数sanme
if(!StuSelect(sname))
{
cout<<"对不起你查询的学号不存在!"<<endl;
system("pause");
system("cls");
Form1_Show();
}
string txtname="Type stu\\"+sname+".txt";
cout<<"--------------------------------------------------------------------------------"<<endl;
system(txtname.c_str());
cout<<"--------------------------------------------------------------------------------"<<endl;
cout <<"查询完毕!!!!" <<endl <<endl;
system("pause");
return;
}
//查询老师
void Tea_search()
{
cout<<"请输入你要查找的老师姓名:"<<endl;
string sname;
cin>>sname;
//查找函数传递参数sanme
if(!TeaSelect(sname))
{
cout<<"对不起你查询的老师不存在!"<<endl;
system("pause");
system("cls");
Form1_Show();
}
string txtname="Type tea\\"+sname+".txt";
cout<<"--------------------------------------------------------------------------------"<<endl;
system(txtname.c_str());
cout<<"--------------------------------------------------------------------------------"<<endl;
cout <<"查询完毕!!!!" <<endl <<endl;
system("pause");
return;
}
//显示所有老师
void TeaShowAll()
{
int i(1);
string number;
ifstream stuFile("tea.dat");
assert(stuFile);
while (stuFile >>number)
{
number = "Type tea\\"+number+".txt";
cout<<" 第 ["<< i <<"] 个老师姓名: "<<number<<" 信息如下: "<<endl;
cout<<"--------------------------------------------------------------------------------";
cout<<"--------------------------------------------------------------------------------";
system(number.c_str());
cout<<"--------------------------------------------------------------------------------";
i++;
}
system("pause");
Form1_Show();
}
//显示所有同学
void ShowAll()
{ int i(1);
string number;
ifstream stuFile("stu.dat");
assert(stuFile);
while (stuFile >>number)
{
number = "Type stu\\"+number+".txt";
cout<<" 第 ["<< i <<"] 个同学学号: "<<number<<" 息如下: "<<endl;
cout<<"--------------------------------------------------------------------------------";
cout<<"--------------------------------------------------------------------------------";
system(number.c_str());
cout<<"--------------------------------------------------------------------------------";
i++;
}
system("pause");
Form1_Show();
}
//判断学生是否存在存在返回真
bool StuSelect(string StuID1)
{
string number;
ifstream stuFile("stu.dat");
assert(stuFile);
while (stuFile >>number)
{
if (StuID1 == number)
{
return true;
}
}
return false;
}
//判断老师是否存在存在返回真
bool TeaSelect(string name)
{
string number;
ifstream stuFile("tea.dat");
assert(stuFile);
while (stuFile >>number)
{
if (name == number)
{
return true;
}
}
return false;
}
//删除学生页面
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -