如果觉得有用的话点赞加收藏哦~后续会添加文件、密码加密、修改密码功能
#define _CRT_SECURE_NO_WARNINGS 1 #include#include #include #include using namespace std; class Student { public: string m_name; string m_id; int m_age; string m_phone; string m_address; }; class Manager { public: void menu(); void InsertNewStudent(vector & CQUT, Student& p); void Output(vector & CQUT); void print(Student& p); Student SearchByName(vector & CQUT, const string& name_id); void Modify(vector & CQUT,Student& p); void DeleteStudent(vector & CQUT, string name_id); }; void Manager::menu() { printf("*********************************************************n"); printf("t欢迎使用学生管理系统!n"); printf("t1.录入学生信息n"); printf("t2.查询全部学生信息n"); printf("t3.查找学生信息n"); printf("t4.修改学生信息n"); printf("t5.删除学生信息n"); printf("t6.退出系统n"); printf("*********************************************************n"); printf("请选择:"); } void Manager::InsertNewStudent(vector & CQUT, Student& p) { cout << "请输入新加学生的姓名" << endl; cin >> p.m_name; cout << "请输入新加学生的学号" << endl; cin >> p.m_id; cout << "请输入新加学生的年龄" << endl; cin >> p.m_age; getchar(); cout << "请输入新加学生的电话" << endl; cin >> p.m_phone; cout << "请输入新加学生的住址" << endl; cin >> p.m_address; getchar(); CQUT.push_back(p); } void Manager::Output(vector & CQUT) { for (vector ::iterator it = CQUT.begin(); it != CQUT.end(); it++) { cout << (*it).m_name << "t"; cout << (*it).m_id << "t"; cout << (*it).m_age << "t"; cout << (*it).m_phone << "t"; cout << (*it).m_address << endl; } } vector CQUT; void Manager::print(Student& p) { cout << p.m_name << "t"; cout << p.m_id << "t"; cout << p.m_age << "t"; cout << p.m_phone << "t"; cout << p.m_address << endl; } Student Manager::SearchByName(vector & CQUT, const string& id) { vector ::iterator it; for (it = CQUT.begin(); it != CQUT.end(); it++) { if (it->m_id == id) { return *it; } } if (it == CQUT.end()) { cout << "查无此人!" << endl; } } void Manager::Modify(vector & CQUT,Student& p) { cout << "请输入新的姓名" << endl; cin >> p.m_name; cout << "请输入新的学号" << endl; cin >> p.m_id; cout << "请输入新的年龄" << endl; cin >> p.m_age; getchar(); cout << "请输入新的电话" << endl; cin >> p.m_phone; cout << "请输入新的住址" << endl; cin >> p.m_address; getchar(); CQUT.push_back(p); } void Manager::DeleteStudent(vector & CQUT, string name_id) { vector ::iterator it; for (it = CQUT.begin(); it != CQUT.end(); it++) { if (it->m_id == name_id) { CQUT.erase(it); } } } void Run() { int op = 0; int choice; Manager m; Student p; while(true) { system("mode con cols=57 lines=50");//调整控制台大小 system("color F4"); //字体颜色与背景 m.menu(); cin >> op; switch (op) { case 1: m.InsertNewStudent(CQUT, p); break; case 2: m.Output(CQUT); break; case 3: cout << "请输入您要查找的学生的学号:"; cin >> p.m_id; p = m.SearchByName(CQUT, p.m_id); m.print(p); cout << "1.修改 2.删除 3.退出" << endl; cin >> choice; if (choice == 1) { m.Modify(CQUT, p); } else if (choice == 2) { m.DeleteStudent(CQUT, p.m_id); } else { break; } break; case 4: cout << "请输入您要修改的学生的学号:"; cin >> p.m_id; p = m.SearchByName(CQUT, p.m_id); m.print(p); m.Modify(CQUT, p); break; default: break; } system("pause"); system("cls"); } } int main() { int numbers = 3;//给用户三次机会输入密码 string account = "123"; //账号 string password = "123"; //密码 string input1;//接收用户输入的账号 string input2;//接收用户输入的密码 char ch; while (numbers) { cout << "请输入账号:"; cin >> input1; cout << "请输入密码:"; cin >> input2; if (input1 == password &&input2 == account ) { cout << "正在登陆..." << endl; Sleep(2000); Run(); } else { cout << "账号/密码错误!" << endl; numbers--; } } if (numbers == 3) { cout << "您已输错三次,程序自动退出!" << endl; } return 0; }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)