#include<iostream> #include<fstream> #include<string> #include<Windows.h> using namespace std; #define N 2 #define MAX 200 class Show { public: Show() { system("cls"); cout << "----------------------------------------------------" << endl; cout << "*★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*" << endl; cout << " 管理端: " << endl; cout << endl; cout << endl; cout << "*★☆★ " << "1.增加学生信息" << " ★☆★*" << endl; cout << "*★☆★ " << "2.删除学生信息" << " ★☆★*" << endl; cout << "*★☆★ " << "3.修改学生信息" << " ★☆★*" << endl; cout << "*★☆★ " << "4.查找学生信息" << " ★☆★*" << endl; cout << "*★☆★ " << "5.显示学生信息" << " ★☆★*" << endl; cout << "*★☆★ " << "其他任意键退出" << " ★☆★*" << endl; cout << endl; cout << endl; cout << "请选择序号" << endl; cout << "---------欢迎联系2460918833--------潇---------------" << endl; cout << "*★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*" << endl; } }; class Nstudent { public: string Sno; string Sname; string Sex; string Sclass; int Sage; string Splace; double Score[2] = { 0,0 }; double Sum_Sc = 0; string inf[9] = { "学号:","姓名:","性别:","班级:","年龄:","户籍:","语文成绩:","数学成绩:","总分:" }; }; Nstudent student[MAX]; void studentinf(int quantity); int quantity;//学生数目 class InData//写入内存 { public: InData()//写入内存 { ifstream File_cin("C:\\Users\\潇\\Desktop\\Student.txt"); File_cin >> quantity; for (int i = 0; i < quantity; i++) { File_cin >> student[i].Sno; File_cin >> student[i].Sname; File_cin >> student[i].Sex >> student[i].Sclass >> student[i].Sage >> student[i].Splace; for (int j = 0; j < N; j++) { File_cin >> student[i].Score[j]; student[i].Sum_Sc += student[i].Score[j]; } } File_cin.close(); } }; class OutData { public: OutData() { fstream File_cout("C:\\Users\\潇\\Desktop\\Student.txt"); File_cout << quantity << endl; for (int i = 0; i < quantity; i++) { File_cout << student[i].Sno << " "; File_cout << student[i].Sname << " "; File_cout << student[i].Sex << " "; File_cout << student[i].Sclass << " "; File_cout << student[i].Sage << " "; File_cout << student[i].Splace << " "; for (int j = 0; j < N; j++) { File_cout << student[i].Score[j] << " "; } File_cout << student[i].Sum_Sc; File_cout << endl; } File_cout.close(); } }; void Show_inf(); void CetData() { cout << "----------------------------------------------------" << endl; cout << "*★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*" << endl; cout << " 学生信息管理系统" << endl; cout << " 增加学生信息:" << endl; cout << " 请按提示输入" << endl; cout << " 请输入增加数量: " << endl; int nn; cin >> nn; for (int i = 0; i < nn; i++, quantity++) { system("cls"); cout << "----------------------------------------------------" << endl; cout << "*★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*" << endl; cout << " 学生信息管理系统" << endl; cout << " 增加学生信息:" << endl; cout << "请按提示输入第" << i + 1 << "个学生信息" << endl; cout << "*★☆★ " << student[quantity].inf[0]; cin >> student[quantity].Sno; cout << endl; cout << "*★☆★ " << student[quantity].inf[1] << ": "; cin >> student[quantity].Sname; cout << endl; cout << "*★☆★ " << student[quantity].inf[2] << ": "; cin >> student[quantity].Sex; cout << endl; cout << "*★☆★ " << student[quantity].inf[3] << ": "; cin >> student[quantity].Sclass; cout << endl; cout << "*★☆★ " << student[quantity].inf[4] << ":"; cin >> student[quantity].Sage; cout << endl; cout << "*★☆★ " << student[quantity].inf[5] << ":"; cin >> student[quantity].Splace; cout << endl; for (int j = 0; j < N; j++) { cout << "*★☆★ " << student[quantity].inf[6 + j] << ": "; cin >> student[quantity].Score[j]; student[quantity].Sum_Sc += student[quantity].Score[j]; cout << endl; } cout << "第" << i + 1 << "个学生信息输入完成" << endl; cout << "*★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*" << endl; cout << "----------------------------------------------------" << endl; Sleep(1500); system("cls"); } }; void Judje(); void Clien(); void DelData(); void LooData(); void ChaData(); //写入文件 int main() { ifstream Cin_file("C:\\Users\\潇\\Desktop\\root.txt"); string File_name; string File_passname; Cin_file >> File_name; Cin_file >> File_passname; Cin_file.close(); cout << "----------------------------------------------------" << endl; cout << "*★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*" << endl; cout << " 学生信息管理系统" << endl; cout << endl; cout << endl; cout << "*★☆★ " << "请输入账号:"; string name; cin >> name; if (name[0] != '1') { InData nData; for (int i = 0; i < quantity; i++) { if (name == student[i].Sno) { studentinf(i); exit(0); } } system("cls"); cout << "----------------------------------------------------" << endl; cout << "*★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*" << endl; cout << " 学生端: " << endl; for (int i = 0; i < 4; i++)cout << endl; cout << " " << "学生信息不存在" << endl; for (int i = 0; i < 4; i++)cout << endl; cout << "*★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*" << endl; cout << "----------------------------------------------------" << endl; system("pause"); exit(0); } else if (name == File_name); else { cout << "*★☆★ " << "账号不存在" << endl; cout << "结束" << endl; Sleep(3000); exit(0); } for (int i = 0; i < 15; i++) cout << ' '; cout << endl; cout << "*★☆★ " << "请输入密码:"; string password; cin >> password; if (password == File_passname) Clien(); else { cout << "*★☆★ " << "密码错误" << endl; cout << "*★☆★ " << "请输入密码:"; int count = 1; while (count < 3) { cin >> password; if (password == "exit") { cout << "程序即将退出"; Sleep(5000); exit(0); } if (password == File_passname) { Clien(); } } cout << "*★☆★ " << "密码错误次数过3,结束" << endl; cout << endl; cout << endl; cout << "*★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*" << endl; cout << "----------------------------------------------------" << endl; Sleep(3000); exit(0); } } void Clien() { system("cls"); Show show; getchar(); //程序入口 InData(); int a; cin >> a; switch (a) { case 1: system("cls"); CetData() ; Judje(); case 2: system("cls"); DelData(); Judje(); case 3: system("cls"); ChaData(); Judje(); case 4: system("cls"); LooData(); getchar(); Judje(); case 5: system("cls"); Show_inf(); getchar(); getchar(); Judje(); default: OutData outData; exit(0); break; } } void ChaData() { cout << "----------------------------------------------------" << endl; cout << "*★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*" << endl; cout << " 学生信息管理系统" << endl; cout << " 查找学生信息:" << endl; cout << " 请按提示输入" << endl; cout << " 请选择: " << endl; cout << endl; cout << endl; cout << "*★☆★ " << "1.按学号" << " ★☆★*" << endl; cout << "*★☆★ " << "2.按姓名" << " ★☆★*" << endl; cout << endl; cout << endl; cout << "请选择序号" << endl; cout << "*★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*" << endl; cout << "----------------------------------------------------" << endl; getchar(); char a = getchar(); if (a == '1') { system("cls"); cout << "----------------------------------------------------" << endl; cout << "*★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*" << endl; cout << " 学生信息管理系统" << endl; cout << " 查找学生信息:" << endl; cout << " 您选择了按学号查找: " << endl; cout << " 请输入学号" << endl; string name; cin >> name; for (int i = 0; i < quantity; i++) { if (name == student[i].Sno) { cout << "请按提示输入第" << i + 1 << "个学生信息" << endl; cout << "*★☆★ " << student[i].inf[0]; cin >> student[i].Sno; cout << endl; cout << "*★☆★ " << student[i].inf[1] << ": "; cin >> student[i].Sname; cout << endl; cout << "*★☆★ " << student[i].inf[2] << ": "; cin >> student[i].Sex; cout << endl; cout << "*★☆★ " << student[i].inf[3] << ": "; cin >> student[i].Sclass; cout << endl; cout << "*★☆★ " << student[i].inf[4] << ": "; cin >> student[i].Sage; cout << endl; cout << "*★☆★ " << student[i].inf[5] << ": "; cin >> student[i].Splace; for (int j = 0; j < N; j++) { cout << "*★☆★ " << student[i].inf[6 + j] << ": "; cin >> student[i].Score[j]; cout << endl; } cout << "*★☆★ " << student[i].inf[8] << ": "; cin >> student[i].Sum_Sc; cout << endl; } } system("cls"); cout << "----------------------------------------------------" << endl; cout << "*★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*" << endl; cout << " 学生信息管理系统 " << endl; for (int i = 0; i < 4; i++)cout << endl; cout << " " << "学生信息不存在" << endl; for (int i = 0; i < 4; i++)cout << endl; cout << "*★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*" << endl; cout << "----------------------------------------------------" << endl; getchar(); getchar(); return; } else { system("cls"); cout << "----------------------------------------------------" << endl; cout << "*★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*" << endl; cout << " 学生信息管理系统" << endl; cout << " 查找学生信息:" << endl; cout << " 您选择了按姓名查找: " << endl; cout << " 请输入姓名" << endl; string name; cin >> name; for (int i = 0; i < quantity; i++) { if (name == student[i].Sname) { cout << "请按提示输入" << endl; cout << "*★☆★ " << student[i].inf[0]; cin >> student[i].Sno; cout << endl; cout << "*★☆★ " << student[i].inf[1] << ": "; cin >> student[i].Sname; cout << endl; cout << "*★☆★ " << student[i].inf[2] << ": "; cin >> student[i].Sex; cout << endl; cout << "*★☆★ " << student[i].inf[3] << ": "; cin >> student[i].Sclass; cout << endl; cout << "*★☆★ " << student[i].inf[4] << ": "; cin >> student[i].Sage; cout << endl; cout << "*★☆★ " << student[i].inf[5] << ": "; cin >> student[i].Splace; for (int j = 0; j < N; j++) { cout << "*★☆★ " << student[i].inf[6 + j] << ": "; cin >> student[i].Score[j]; cout << endl; } cout << "*★☆★ " << student[i].inf[8] << ": "; cin >> student[i].Sum_Sc; cout << endl; } } system("cls"); cout << "----------------------------------------------------" << endl; cout << "*★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*" << endl; cout << " 学生信息管理系统 " << endl; for (int i = 0; i < 4; i++)cout << endl; cout << " " << "学生信息不存在" << endl; for (int i = 0; i < 4; i++)cout << endl; cout << "*★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*" << endl; cout << "----------------------------------------------------" << endl; getchar(); getchar(); return; } } void DelData() { cout << "----------------------------------------------------" << endl; cout << "*★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*" << endl; cout << " 学生信息管理系统" << endl; cout << " 删除学生信息:" << endl; cout << " 请按提示输入" << endl; cout << " 请选择: " << endl; cout << endl; cout << endl; cout << "*★☆★ " << "1.按学号" << " ★☆★*" << endl; cout << "*★☆★ " << "2.按姓名" << " ★☆★*" << endl; cout << endl; cout << endl; cout << "请选择序号" << endl; cout << "*★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*" << endl; cout << "----------------------------------------------------" << endl; getchar(); char a = getchar(); if (a == '1') { system("cls"); cout << "----------------------------------------------------" << endl; cout << "*★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*" << endl; cout << " 学生信息管理系统" << endl; cout << " 删除学生信息:" << endl; cout << " 您选择了按学号查找: " << endl; cout << " 请输入学号" << endl; string name; cin >> name; for (int i = 0; i < quantity; i++) { if (name == student[i].Sno) { for (int j = i; j < quantity - 1; j++) { student[i] = student[j]; } quantity--; getchar(); return; } } system("cls"); cout << "----------------------------------------------------" << endl; cout << "*★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*" << endl; cout << " 学生信息管理系统 " << endl; for (int i = 0; i < 4; i++)cout << endl; cout << " " << "学生信息不存在" << endl; for (int i = 0; i < 4; i++)cout << endl; cout << "*★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*" << endl; cout << "----------------------------------------------------" << endl; getchar(); getchar(); return; } else { system("cls"); cout << "----------------------------------------------------" << endl; cout << "*★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*" << endl; cout << " 学生信息管理系统" << endl; cout << " 查找学生信息:" << endl; cout << " 您选择了按姓名查找: " << endl; cout << " 请输入姓名" << endl; string name; cin >> name; for (int i = 0; i < quantity; i++) { if (name == student[i].Sno) { for (int j = i; j < quantity - 1; j++) { student[i] = student[j]; } quantity--; getchar(); return; } } system("cls"); cout << "----------------------------------------------------" << endl; cout << "*★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*" << endl; cout << " 学生信息管理系统 " << endl; for (int i = 0; i < 4; i++)cout << endl; cout << " " << "学生信息不存在" << endl; for (int i = 0; i < 4; i++)cout << endl; cout << "*★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*" << endl; cout << "----------------------------------------------------" << endl; getchar(); getchar(); return; } } void studentinf(int quantity) { system("cls"); cout << "----------------------------------------------------" << endl; cout << "*★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*" << endl; cout << " 学生信息管理系统 " << endl; cout << " 信息: " << endl; cout << "*★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*" << endl; for (int i = 0; i < 15; i++) cout << ' '; cout << "*★☆★ " << student[quantity].inf[0] << student[quantity].Sno << endl; for (int i = 0; i < 15; i++) cout << ' '; cout << "*★☆★ " << student[quantity].inf[1] << student[quantity].Sname<<endl; for (int i = 0; i < 15; i++) cout << ' '; cout << "*★☆★ " << student[quantity].inf[2] << student[quantity].Sex << endl; for (int i = 0; i < 15; i++) cout << ' '; cout << "*★☆★ " << student[quantity].inf[3] << student[quantity].Sclass << endl; for (int i = 0; i < 15; i++) cout << ' '; cout << "*★☆★ " << student[quantity].inf[4] << student[quantity].Sage << endl; for (int i = 0; i < 15; i++) cout << ' '; cout << "*★☆★ " << student[quantity].inf[5] << student[quantity].Splace << endl; for (int j = 0; j < N; j++) { for (int i = 0; i < 15; i++) cout << ' '; cout << "*★☆★ " << student[quantity].inf[6 + j] << student[quantity].Score[j] << " " << endl; } for (int i = 0; i < 15; i++) cout << ' '; cout << "*★☆★ " << student[quantity].inf[8] << student[quantity].Sum_Sc << endl; cout << "*★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*" << endl; cout << "----------------------------------------------------" << endl; getchar(); getchar(); return; } void LooData() { cout << "----------------------------------------------------" << endl; cout << "*★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*" << endl; cout << " 学生信息管理系统" << endl; cout << " 查找学生信息:" << endl; cout << " 请按提示输入" << endl; cout << " 请选择: " << endl; cout << endl; cout << endl; cout << "*★☆★ " << "1.按学号" << " ★☆★*" << endl; cout << "*★☆★ " << "2.按姓名" << " ★☆★*" << endl; cout << endl; cout << endl; cout << "请选择序号" << endl; cout << "*★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*" << endl; cout << "----------------------------------------------------" << endl; getchar(); char a = getchar(); if (a == '1') { system("cls"); cout << "----------------------------------------------------" << endl; cout << "*★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*" << endl; cout << " 学生信息管理系统" << endl; cout << " 查找学生信息:" << endl; cout << " 您选择了按学号查找: " << endl; cout << " 请输入学号" << endl; string name; cin >> name; for (int i = 0; i < quantity; i++) { if (name == student[i].Sno) { studentinf(i); } } system("cls"); cout << "----------------------------------------------------" << endl; cout << "*★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*" << endl; cout << " 学生信息管理系统 " << endl; for (int i = 0; i < 4; i++)cout << endl; cout << " " << "学生信息不存在" << endl; for (int i = 0; i < 4; i++)cout << endl; cout << "*★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*" << endl; cout << "----------------------------------------------------" << endl; getchar(); getchar(); return; } else { system("cls"); cout << "----------------------------------------------------" << endl; cout << "*★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*" << endl; cout << " 学生信息管理系统" << endl; cout << " 查找学生信息:" << endl; cout << " 您选择了按姓名查找: " << endl; cout << " 请输入姓名" << endl; string name; cin >> name; for (int i = 0; i < quantity; i++) { if (name == student[i].Sname) studentinf(i); } system("cls"); cout << "----------------------------------------------------" << endl; cout << "*★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*" << endl; cout << " 学生信息管理系统 " << endl; for (int i = 0; i < 4; i++)cout << endl; cout << " " << "学生信息不存在" << endl; for (int i = 0; i < 4; i++)cout << endl; cout << "*★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*" << endl; cout << "----------------------------------------------------" << endl; getchar(); getchar(); return; } cout << "----------------------------------------------------"<< endl; cout << "*★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*"<< endl; cout << " 学生信息管理系统"<< endl; for (int i = 0; i < quantity; i++) { cout<< student[i].Sno<<" "<< student[i].Sname<<" "<< student[i].Sex <<" "<< student[i].Sclass <<" "<< student[i].Sage <<" "<< student[i].Splace; for (int j = 0; j < N; j++) { cout<< student[i].Score[j]<<" "; } cout << endl; } } void Judje() { system("cls"); cout << "----------------------------------------------------" << endl; cout << "*★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*" << endl; cout << " 管理端: " << endl; cout << endl; cout << endl; cout << "*★☆★ " << "是否继续操作 y or n" << endl; char flag; cout << "*★☆★ "; cin >> flag; if (flag == 'y' || flag == 'Y') Clien(); else { cout << "*★☆★ " << "程序将自动退出" << endl; cout << endl; cout << endl; cout << endl; cout << "----------------------------------------------------" << endl; cout << "*★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★*" << endl; cout << endl; OutData(); Sleep(3000); exit(0); } } void Show_inf() { cout <<"学生数目:"<< quantity << endl; for (int i = 0; i < quantity; i++) { cout << student[i].Sno << " "; cout << student[i].Sname << ' '; cout << student[i].Sex << " "; cout << student[i].Sclass << " "; cout << student[i].Sage << " "; cout << student[i].Splace << " "; for (int j = 0; j < N; j++) { cout << student[i].Score[j] << " "; } cout << student[i].Sum_Sc; cout << endl; } }
c++写一个学生信息管理系统,不喜勿喷
猜你喜欢
转载自blog.csdn.net/xiu_2460918833/article/details/80381612
今日推荐
周排行