由于上学期 决策不当,和lql大佬两个人做了个十分简单的五子棋小游戏,导致含泪拿
中
,所以这学期一个人肝了个400行的高校师生信息管理系统。
设计流程图:
部分运行界面截图:
代码如下:
#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <windows.h>
#include <algorithm>
using namespace std;
int teacher_counter = 1, student_counter = 1;
class PERSON //person类,作为student类和teacher类的父类
{
public:
string Name, Professional, ID, Gender, Telephone;
int Age;
} person[1000000];
class STUDENT : public PERSON //student类,公有继承person类
{
public:
int Math, PE, C_Language, English;
STUDENT()
{
Math = PE = C_Language = English = 0;
}
void out_student1()
{
printf("姓名:%s\n职业:%s\n学号:%s\n性别:%s\n年龄:%d\n电话号码:%s\n", Name.c_str(), Professional.c_str(), ID.c_str(), Gender.c_str(), Age, Telephone.c_str());
}
void out_student2()
{
int sum = Math + PE + C_Language + English;
printf("数学:%d\n体育:%d\nC语言:%d\n英语:%d\n平均分:%.2f\n", Math, PE, C_Language, English, 1.0 * sum / 4);
}
} student[1000000];
class TEACHER : public PERSON //teacher类,公有继承person类
{
public:
string xueli;
int gonzi;
TEACHER()
{
string xueli = "大学";
gonzi = 0;
}
void out_teacher1()
{
printf("姓名:%s\n职业:%s\n学号:%s\n性别:%s\n年龄:%d\n电话号码:%s\n", Name.c_str(), Professional.c_str(), ID.c_str(), Gender.c_str(), Age, Telephone.c_str());
}
void out_teacher2()
{
printf("学历:%s\n工资:%d\n", xueli.c_str(), gonzi);
}
} teacher[1000000];
void menu() //打印菜单
{
system("cls");
printf(" —————————————————————————————\n");
printf("|****************************|\n");
printf("|*高校师生信息管理系统主菜单*|\n");
printf("|*******1.新增教师信息*******|\n");
printf("|*******2.新增学生信息*******|\n");
printf("|*******3.删除教师信息*******|\n");
printf("|*******4.删除学生信息*******|\n");
printf("|*******5.查询教师信息*******|\n");
printf("|*******6.查询学生信息*******|\n");
printf("|*******7.查询师生人数*******|\n");
printf("|*******8.安全退出系统*******|\n");
printf("|*****9.输出所有基本信息*****|\n");
printf("|*!!!使用结束务必安全退出!!!*|\n");
printf(" —————————————————————————————\n");
printf("\n ————————————————————————By.hesorchen\n\n\n");
}
void option1() //对饮操作1
{
system("cls");
string str1, str2, str3, str4, str5, str6;
int b1, b2, b3, b4, b5;
cout << "请输入姓名:\n";
cin >> str1;
cout << "请输入工号:\n";
cin >> str3;
cout << "请输入性别:\n";
cin >> str4;
cout << "请输入电话号码:\n";
cin >> str5;
cout << "请输入年龄:\n";
cin >> b1;
cout << "请输入学历:\n";
cin >> str6;
cout << "请输入工资:\n";
cin >> b3;
teacher[teacher_counter].Name = str1;
teacher[teacher_counter].Professional = "教师";
teacher[teacher_counter].ID = str3;
teacher[teacher_counter].Gender = str4;
teacher[teacher_counter].Telephone = str5;
teacher[teacher_counter].Age = b1;
teacher[teacher_counter].xueli = str6;
teacher[teacher_counter++].gonzi = b3;
cout << "教师信息录入成功!" << endl;
system("pause");
}
void option2() //对饮操作2
{
system("cls");
string str1, str2, str3, str4, str5, str6;
int b1, b2, b3, b4, b5;
cout << "请输入姓名:\n";
cin >> str1;
cout << "请输入学号:\n";
cin >> str3;
cout << "请输入性别:\n";
cin >> str4;
cout << "请输入电话号码:\n";
cin >> str5;
cout << "请输入年龄:\n";
cin >> b1;
cout << "请输入数学成绩:\n";
cin >> b2;
cout << "请输入体育成绩:\n";
cin >> b3;
cout << "请输入C语言成绩:\n";
cin >> b4;
cout << "请输入英语成绩:\n";
cin >> b5;
student[student_counter].Name = str1;
student[student_counter].Professional = "学生";
student[student_counter].ID = str3;
student[student_counter].Gender = str4;
student[student_counter].Telephone = str5;
student[student_counter].Age = b1;
student[student_counter].Math = b2;
student[student_counter].PE = b3;
student[student_counter].C_Language = b4;
student[student_counter++].English = b5;
cout << "学生信息录入成功!" << endl;
system("pause");
}
void option3() //对饮操作3
{
system("cls");
cout << "请输入要删除的教师信息的教师工号:\n";
string num;
cin >> num;
int len = num.size();
int pos = -1;
for (int i = 1; i < teacher_counter; i++)
{
if (teacher[i].ID.substr(0, len) == num)
{
pos = i;
break;
}
}
if (pos == -1)
cout << "没有该工号的教师!" << endl;
else
{
cout << "姓名:";
printf("%s\n", teacher[pos].Name.c_str());
cout << "职业:";
printf("%s\n", teacher[pos].Professional.c_str());
cout << "工号:";
printf("%s\n", teacher[pos].ID.c_str());
cout << "性别:";
printf("%s\n", teacher[pos].Gender.c_str());
cout << "电话号码:";
printf("%s\n", teacher[pos].Telephone.c_str());
cout << "年龄:";
printf("%d\n", teacher[pos].Age);
cout << "学历:";
printf("%s\n", teacher[pos].xueli.c_str());
cout << "确认删除该教师信息吗?" << endl;
cout << "输入1确认,输入2取消:\n";
int flagg = 0;
cin >> flagg;
if (flagg == 1)
{
cout << "成功删除该教师信息!" << endl;
teacher[pos].Name = "***";
}
else
cout << "取消操作!" << endl;
}
system("pause");
}
void option4() //对饮操作4
{
system("cls");
cout << "请输入要删除的学生信息的学生学号:\n";
string num;
cin >> num;
int len = num.size();
int pos = -1;
for (int i = 1; i < student_counter; i++)
{
if (student[i].ID.substr(0, len) == num)
{
pos = i;
break;
}
}
if (pos == -1)
cout << "没有该学号的学生!" << endl;
else
{
cout << "姓名:";
printf("%s\n", student[pos].Name.c_str());
cout << "职业:";
printf("%s\n", student[pos].Professional.c_str());
cout << "学号:";
printf("%s\n", student[pos].ID.c_str());
cout << "性别:";
printf("%s\n", student[pos].Gender.c_str());
cout << "电话号码:";
printf("%s\n", student[pos].Telephone.c_str());
cout << "年龄:";
printf("%d\n", student[pos].Age);
cout << "确认删除该学生信息吗?" << endl;
cout << "输入1确认,输入2取消:\n";
int flagg = 0;
cin >> flagg;
if (flagg == 1)
{
cout << "成功删除该学生信息!" << endl;
student[pos].Name = "***";
}
else
cout << "取消操作!" << endl;
}
system("pause");
}
void option5() //对饮操作5
{
system("cls");
cout << "请输入要查询的教师信息的教师工号:\n";
string num;
cin >> num;
int len = num.size();
int pos = -1;
for (int i = 1; i < teacher_counter; i++)
{
if (teacher[i].ID.substr(0, len) == num)
{
pos = i;
break;
}
}
if (pos == -1)
cout << "没有该工号的教师!" << endl;
else
{
teacher[pos].out_teacher1();
teacher[pos].out_teacher2();
}
system("pause");
}
void option6() //对饮操作6
{
system("cls");
cout << "请输入要查询的学生信息的学生学号:\n";
string num;
cin >> num;
int len = num.size();
int pos = -1;
for (int i = 1; i < student_counter; i++)
{
if (student[i].ID.substr(0, len) == num)
{
pos = i;
break;
}
}
if (pos == -1)
cout << "没有该学号的学生!" << endl;
else
{
student[pos].out_student1();
student[pos].out_student2();
}
system("pause");
}
void option7() //对饮操作7
{
system("cls");
cout << "全校共有教师" << teacher_counter - 1 << "人" << endl;
cout << " 学生" << student_counter - 1 << "人" << endl;
system("pause");
}
void option9() //对饮操作9
{
system("cls");
cout << "总共" << student_counter - 1 << "位学生信息如下:\n";
for (int i = 1; i < student_counter; i++)
{
cout << "第" << i << "位学生的基本信息:"
<< ":\n";
student[i].out_student1();
cout << endl;
}
cout << "总共" << teacher_counter - 1 << "位教师信息如下:\n";
for (int i = 1; i < teacher_counter; i++)
{
cout << "第" << i << "位教师的基本信息:"
<< ":\n";
teacher[i].out_teacher1();
cout << endl;
}
system("pause");
}
void operation() //选择操作
{
while (1) //只有退出系统才会break
{
menu();
int option;
cin >> option;
if (option == 1)
option1();
else if (option == 2)
option2();
else if (option == 3)
option3();
else if (option == 4)
option4();
else if (option == 5)
option5();
else if (option == 6)
option6();
else if (option == 7)
option7();
else if (option == 8)
{
system("cls");
cout << "感谢使用,系统已经安全退出" << endl;
return;
}
else if (option == 9)
option9();
}
}
void read() //读取文件中的师生信息
{
FILE *fp = fopen("message.txt", "a+");
char ch = fgetc(fp);
if (ch == EOF)
fprintf(fp, "*** ***\n*** ***");
fseek(fp, 0, SEEK_SET);
int ff = 0;
while (!feof(fp))
{
string str1, str2, str3, str4, str5, str6;
int b1, b2, b3, b4, b5;
str1.resize(20);
str2.resize(20);
str3.resize(20);
str4.resize(20);
str5.resize(20);
str6.resize(20);
fscanf(fp, "%s%s", &str1[0], &str2[0]);
if (str2[0] == '*')
{
ff = 1;
continue;
}
if (!ff)
{
fscanf(fp, "%s%s%s%d%d%d%d%d", &str3[0], &str4[0], &str5[0], &b1, &b2, &b3, &b4, &b5);
student[student_counter].Name = str1;
student[student_counter].Professional = str2;
student[student_counter].ID = str3;
student[student_counter].Gender = str4;
student[student_counter].Telephone = str5;
student[student_counter].Age = b1;
student[student_counter].Math = b2;
student[student_counter].PE = b3;
student[student_counter].C_Language = b4;
student[student_counter++].English = b5;
}
else if (ff && str2[0] != '*')
{
fscanf(fp, "%s%s%s%d%s%d", &str3[0], &str4[0], &str5[0], &b1, &str6[0], &b2);
teacher[teacher_counter].Name = str1;
teacher[teacher_counter].Professional = str2;
teacher[teacher_counter].ID = str3;
teacher[teacher_counter].Gender = str4;
teacher[teacher_counter].Telephone = str5;
teacher[teacher_counter].Age = b1;
teacher[teacher_counter].xueli = str6;
teacher[teacher_counter++].gonzi = b2;
}
}
fclose(fp);
fp = fopen("message.txt", "w");
fclose(fp); //清空文件重新打开文件
}
void save() //退出系统时,把程序中的信息重新写入到文件中
{
FILE *fp = fopen("message.txt", "a+");
for (int i = 1; i < student_counter; i++)
{
if (student[i].Name[0] == '*')
continue;
fprintf(fp, "%s ", student[i].Name.c_str());
fprintf(fp, "%s ", student[i].Professional.c_str());
fprintf(fp, "%s ", student[i].ID.c_str());
fprintf(fp, "%s ", student[i].Gender.c_str());
fprintf(fp, "%s ", student[i].Telephone.c_str());
fprintf(fp, "%d ", student[i].Age);
fprintf(fp, "%d ", student[i].Math);
fprintf(fp, "%d ", student[i].PE);
fprintf(fp, "%d ", student[i].C_Language);
fprintf(fp, "%d\n", student[i].English);
}
fprintf(fp, "*** ***\n");
for (int i = 1; i < teacher_counter; i++)
{
if (teacher[i].Name[0] == '*')
continue;
fprintf(fp, "%s ", teacher[i].Name.c_str());
fprintf(fp, "%s ", teacher[i].Professional.c_str());
fprintf(fp, "%s ", teacher[i].ID.c_str());
fprintf(fp, "%s ", teacher[i].Gender.c_str());
fprintf(fp, "%s ", teacher[i].Telephone.c_str());
fprintf(fp, "%d ", teacher[i].Age);
fprintf(fp, "%s ", teacher[i].xueli.c_str());
fprintf(fp, "%d\n", teacher[i].gonzi);
}
fprintf(fp, "*** ***");
fclose(fp);
}
int main()
{
read(); //读取文件信息
operation(); //对系统进行的操作
save(); //保存修改后的文件信息
return 0;
}