C++课程设计 — 公司设备管理系统
2013-12-29 21:32
645 查看
#include<iostream> #include<string> #include<cstring> #include <iomanip> #include <cstdlib> #include<conio.h> #include<fstream> #include<windows.h> #define H "-------------------------------------------------------------------\n" #define H1 "| 编号 | 类别 | 名称 | 价格 | 库存数量 |\n" #define H2 "|-------------|-----------|------------|------------|------------|\n" #define H3 "------------------------------\n" #define H4 "| 账号 | 密码 |\n" #define H5 "|-------------|--------------|\n" using namespace std; class machine { public: machine(); machine(string a,string b,string c,double d,int e); //构造函数 void Add();//添加数据 void Delete();//删除数据 void Show();//显示所有 void Modify();//修改数据 void Search();//查询数据 void Save_new();//保存新增加数据 private: string num; //设备编号 string category; //类别 string name; //名称 double price; //价格 int quantity; //库存数量 }; class user { public: user(); char home_face(); virtual void entrance(); private: string id; string password; }; class admin: public user { public: admin(); virtual void admin_enter(); void entrance(); private: string id; string password; }; class super_admin : public admin { public: super_admin(); void super_admin_enter(); void entrance(); void inter_face();//首页 void Add();//添加数据 void Delete();//删除数据 void Show();//显示所有 void Modify();//修改数据 void Search();//查询数据 void Save_new();//保存新增加数据 private: string id; string password; }; class introduce { public: void display(); }; void introduce::display() { system("color 4e"); cout << endl << "\t ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★" << endl << endl; cout << "\t ※※※※※※※※※※※※※※※※※※※※※※※※※※※" << endl; cout << "\t ※※ ※※" << endl; cout << "\t ※※ ※※" << endl; cout << "\t ※※ 欢迎访问南阳龙马家电有限公司设备管理系统! ※※" << endl; cout << "\t ※※ ※※" << endl; cout << "\t ※※ ※※" << endl; cout << "\t ※※ ※※" << endl; cout << "\t ※※ ※※" << endl; cout << "\t ※※ ***人:李远航 ※※" << endl; cout << "\t ※※ 2013.12.26 ※※" << endl; cout << "\t ※※ ※※" << endl; cout << "\t ※※※※※※※※※※※※※※※※※※※※※※※※※※※" << endl; cout << "\n\t Press 【Enter】key to continue......" << endl; getchar(); system("cls"); } machine::machine() { num = " "; category = " "; name = " "; price = 0; quantity = 0; } user::user() { id = " "; password = " "; } admin::admin() { id = " "; password = " "; } super_admin::super_admin() { id = "liyuanhang"; password = "liyuanhang"; } void user::entrance() { system("color 4a"); char n; machine m; while(1) { system("cls"); cout << endl; cout << "\t\t^__^ 欢迎进入南阳龙马家电有限公司的设备管理系统 ^__^\n\n"; cout << "\t\t╔*☆***◎***◇***☆*** 菜单 ***☆***◇***◎***☆*╗\n"; cout << "\t\t|★|\t\t \t\t\t|★|\n"; cout << "\t\t|☆|\t\t \t\t\t|☆|\n"; cout << "\t\t|★|\t\t 1.设备信息显示\t\t\t|★|\n"; cout << "\t\t|☆|\t\t 2.设备信息查询\t\t\t|☆|\n"; cout << "\t\t|★|\t\t 3.返回 \t\t\t|★|\n"; cout << "\t\t|☆|\t\t \t\t\t|☆|\n"; cout << "\t\t|★|\t\t \t\t\t|★|\n"; cout << "\t\t|☆|\t\t \t\t\t|☆|\n"; cout << "\t\t╚*☆***◎***◇****☆****★****☆****◇***◎***☆*╝\n\n"; cout << "\t\t请选择您要实现的功能选项 (1-3): [ ]\b\b"; while(1) { cin >> n; getchar(); if(n < '1' || n > '3') printf("输入错误,请您重新输入选项(1-3):[ ]\b\b"); else break; } if(n == '1') m.Show(); if(n == '2') m.Search(); if(n == '3') return; } } void admin::admin_enter() { string pp; char m; admin Admin; system("cls"); system("color 4f"); cout << endl << endl << endl; cout << "\t\t^__^ 欢迎进入南阳龙马家电有限公司的设备管理系统 ^__^\n\n"; while(1) { ifstream inData("e:\\Document.txt",ios::in); cout << "\t\t 请输入您的管理员账号:\n\t\t (若返回上一个页面,请输入#号)" << endl; cout << "\t\t "; cin >> pp; if (!inData) { cout << endl <<"\n对不起!账号不存在" << endl; system("pause"); return; } if(pp == "#") return; string qq; cout << "\t\t请输入密码:"; while(1) { m = getch(); if(m == '\r') break; qq += m; cout << "*"; } bool flag = true; string str; while (inData >> id >> password) { getline(inData, str); if (id == pp) { flag = false; if(password == qq) { Admin.entrance(); return; } else cout << "\n\t\t 对不起!密码错误!!\n" << endl; } } if(flag) cout << "\n\t\t 对不起!账号不存在!!\n" << endl; } } void super_admin::super_admin_enter() { string pp; char m; super_admin VIP; admin Admin; system("cls"); system("color 4e"); cout << endl << endl; cout << "\t\t^__^ 欢迎进入南阳龙马家电有限公司的设备管理系统 ^__^\n\n"; while(1) { cout << "\t\t 请输入您的vip管理员账号:\n\t\t (若返回上一个页面,请输入#号)" << endl; cout << "\t\t "; cin >> pp; getchar(); if(pp == "#") return; if(pp == VIP.id) { cout << "\t\t 请输入密码:"; string qq; while(1) { m = getch(); if(m == '\r') break; qq += m; cout<<"*"; } if(qq == VIP.password) { VIP.entrance(); break; } else cout << "\n\t\t 对不起!密码错误!!\n"<<endl; } else cout << "\t\t 对不起!账号不存在!!\n"<<endl; } } void admin::entrance() { system("color 4e"); char n; machine Machine; user User; while(1) { system("cls"); cout << endl; cout << "\t\t^__^ 欢迎进入南阳龙马家电有限公司的设备管理系统 ^__^\n\n"; cout << "\t\t╔*☆***◎***◇***☆*** 菜单 ***☆***◇***◎***☆*╗\n"; cout << "\t\t|★|\t\t \t\t\t|★|\n"; cout << "\t\t|☆|\t\t 1.设备信息录入\t\t\t|☆|\n"; cout << "\t\t|★|\t\t 2.设备信息显示\t\t\t|★|\n"; cout << "\t\t|☆|\t\t 3.设备信息查询\t\t\t|☆|\n"; cout << "\t\t|★|\t\t 4.设备信息修改\t\t\t|★|\n"; cout << "\t\t|☆|\t\t 5.设备信息删除\t\t\t|☆|\n"; cout << "\t\t|★|\t\t 6.返回\t\t\t\t|★|\n"; cout << "\t\t|☆|\t\t \t\t\t|☆|\n"; cout << "\t\t╚*☆***◎***◇****☆****★****☆****◇***◎***☆*╝\n\n"; cout << "\t\t请选择您要实现的功能选项 (1-6): [ ]\b\b"; while(1) { cin >> n; getchar(); if(n < '1' || n > '6') printf("输入错误,请您重新输入选项(1-6):[ ]\b\b"); else break; } switch(n) { case '1': Machine.Add(); break; case '2': Machine.Show(); break; case '3': Machine.Search(); break; case '4': Machine.Modify(); break; case '5': Machine.Delete(); break; case '6': return; } } } void super_admin::entrance() { system("color 3e"); char n; machine Machine; super_admin VIP; while(1) { system("cls"); cout << endl; cout << "\t\t^__^ 欢迎进入南阳龙马家电有限公司的设备管理系统 ^__^\n\n"; cout << "\t\t╔*☆***◎***◇***☆*** 菜单 ***☆***◇***◎***☆*╗\n"; cout << "\t\t|★|\t\t \t\t|★|\n"; cout << "\t\t|☆|\t\t1.设备信息录入 \t\t|☆|\n"; cout << "\t\t|★|\t\t2.设备信息显示 \t\t|★|\n"; cout << "\t\t|☆|\t\t3.设备信息查询 \t\t|☆|\n"; cout << "\t\t|★|\t\t4.设备信息修改 \t\t|★|\n"; cout << "\t\t|☆|\t\t5.设备信息删除 \t\t|☆|\n"; cout << "\t\t|★|\t\t6.编辑管理员信息 \t\t|★|\n"; cout << "\t\t|★|\t\t7.返回 \t\t|★|\n"; cout << "\t\t|☆|\t\t \t\t|☆|\n"; cout << "\t\t╚*☆***◎***◇****☆****★****☆****◇***◎***☆*╝\n\n"; cout << "\t\t请选择您要实现的功能选项 (1-7): [ ]\b\b"; while(1) { cin >> n; getchar(); if(n < '1' || n > '7') printf("输入错误,请您重新输入选项(1-7):[ ]\b\b"); else break; } switch(n) { case '1': Machine.Add(); break; case '2': Machine.Show(); break; case '3': Machine.Search(); break; case '4': Machine.Modify(); break; case '5': Machine.Delete(); break; case '6': VIP.inter_face(); break; case '7': return; } } } void super_admin::inter_face() { system("color 2b"); char n; super_admin VIP; user User; while(1) { system("cls"); cout << endl; cout << "\t\t^__^ 欢迎进入南阳龙马家电有限公司的设备管理系统 ^__^\n\n"; cout << "\t\t╔*☆***◎***◇***☆*** 菜单 ***☆***◇***◎***☆*╗\n"; cout << "\t\t|★|\t\t \t\t|★|\n"; cout << "\t\t|☆|\t\t 1.管理员信息录入 \t\t|☆|\n"; cout << "\t\t|★|\t\t 2.管理员信息显示 \t\t|★|\n"; cout << "\t\t|☆|\t\t 3.管理员信息查询 \t\t|☆|\n"; cout << "\t\t|★|\t\t 4.管理员信息修改 \t\t|★|\n"; cout << "\t\t|☆|\t\t 5.管理员信息删除 \t\t|☆|\n"; cout << "\t\t|★|\t\t 6.返回 \t\t|★|\n"; cout << "\t\t|☆|\t\t \t\t|☆|\n"; cout << "\t\t╚*☆***◎***◇****☆****★****☆****◇***◎***☆*╝\n\n"; cout << "\t\t请选择您要实现的功能选项 (1-6): [ ]\b\b"; while(1) { cin >> n; getchar(); if(n < '1' || n > '6') printf("输入错误,请您重新输入选项(1-6):[ ]\b\b"); else break; } switch(n) { case '1': VIP.Add(); break; case '2': VIP.Show(); break; case '3': VIP.Search(); break; case '4': VIP.Modify(); break; case '5': VIP.Delete(); break; case '6': return; } } } char user::home_face() { system("color 0a"); char n; system("cls"); cout << endl; for(int i = 0; i < 9; i++) //利用循环出现闪动效果 { if(i % 2 == 0) cout << "\t\t^__^ 欢迎进入南阳龙马家电有限公司的设备管理系统 ^__^\n\n"; else cout << endl << endl; if(i % 2 == 0) cout << "\t\t╔*☆***◎***◇***☆*** 菜单 ***☆***◇***◎***☆*╗\n"; else cout << endl; cout << "\t\t|★|\t\t \t\t\t|★|\n"; if(i % 2 == 0) cout << "\t\t|☆|\t\t \t\t\t|☆|\n"; else cout << endl; cout << "\t\t|★|\t\t 1.普通用户登录 \t\t|★|\n"; cout << "\t\t|☆|\t\t 2.管理员登录 \t\t|☆|\n"; cout << "\t\t|★|\t\t 3.超级管理员登录\t\t|★|\n"; cout << "\t\t|☆|\t\t 4.退出 \t\t|☆|\n"; if(i % 2 == 0)cout << "\t\t|★|\t\t \t\t\t|★|\n"; else cout << endl; cout << "\t\t|☆|\t\t \t\t\t|☆|\n"; if(i % 2 == 0)cout << "\t\t╚*☆***◎***◇****☆****★****☆****◇***◎***☆*╝\n\n"; else cout << endl << endl; cout << "\t\t请选择您要实现的功能选项 (1-4): [ ]\b\b"; Sleep(80); if(i < 8) system("cls"); } while(1) { cin >> n; getchar(); if(n < '1' || n > '4') printf("输入错误,请您重新输入选项(1-4):[ ]\b\b"); else return n; } } void machine::Add()//添加设备 { char m; bool flag = true; ifstream inData("e:\\pbook.txt",ios::in); do { cout << endl <<"根据下面提示添加新设备的信息" << endl << endl << "编号 : " ; cin >> num; cout << "类别 : "; do { cin >> category; if(category == "Tv" || category == "Dvd" || category == "WaMa" || category == "Retor") break; else cout << "请输入Tv或Dvd或WaMa或Retor " << endl ; }while(1); cout << "名称 : "; cin >> name; cout << "价格 : "; cin >> price; cout << "库存数量 : "; cin >> quantity; if (!inData) flag=true; string sign,str; while (inData >> sign) { getline(inData, str); if (num == sign) flag = false; } if(flag) Save_new(); else cout << endl << endl << "设备编号已经存在,不能重复添加" << endl << endl; cout << "\t是否继续添加?(y/n):[ ]\b\b"; cin >> m; if(m == 'n') break; }while(1); } void super_admin::Add()//添加管理员 { char m; bool flag = true; ifstream inData("e:\\Document.txt",ios::in); do { cout << endl << "根据下面提示添加新管理员的信息" << endl << endl << "账号 : " ; cin >> id; cout << "密码 : "; cin >> password; if (!inData) { flag = true; } string sign,str; while (inData >> sign >> str) { if (id == sign) { flag = false; } } if(flag) Save_new(); else cout << endl << endl << "管理员号已经存在,不能重复添加" << endl << endl; cout << "\t是否继续添加?(y/n):[ ]\b\b"; cin >> m; if(m == 'n') break; }while(1); } void machine::Delete()//删除设备 { ofstream outData("e:\\temp.txt", ios::out); ifstream inData("e:\\pbook.txt", ios::in); if (!inData) { cout << endl << "对不起!!!!找不到文件!!!!" << endl; system("pause"); return; } string sign; cout << endl << "你要删除设备的编号 :"; cin >> sign; string str1; bool flag = true; string str; while(inData >> num) { getline(inData,str); if(sign == num) { cout << endl << "你想删除的设备:" << endl << endl; cout << H << H1 << H2; cout << setw(15) << num << str << endl; cout << H2; flag = false; break; } outData << setiosflags(ios::left) << num << setw(15) << str << endl; } if (flag) { cout << endl << "对不起!!!没有你找的设备!!!!" << endl << endl; } else { while (getline(inData, str)) { outData << str << endl; } outData.close(); inData.close(); ofstream out("e:\\pbook.txt", ios::out); ifstream in("e:\\temp.txt", ios::in); if (!out || !in) { cout << endl << "对不起,不能打开文件!!!" << endl << endl; system("pause"); return; } while (getline(in,str)) { out << str << endl; } out.close(); in.close(); cout << endl << "这个设备的信息已经删除!!!" << endl << endl; } system("pause"); } void super_admin::Delete()//删除管理员 { ofstream outData("e:\\temp1.txt", ios::out); ifstream inData("e:\\Document.txt", ios::in); if (!inData) { cout << endl <<"对不起!!!!找不到文件!!!!" << endl; system("pause"); return; } string sign; cout << endl <<"你要删除管理员的帐号 :"; cin >> sign; string str1; bool flag = true; string str; while(inData >> id) { getline(inData,str); if(sign==id) { cout << endl << "你想删除的管理员:" << endl << endl; cout << H3 << H4 << H5; cout << setw(15) << id << str << endl; cout << H5; flag = false; break; } outData << setiosflags(ios::left) << id << setw(15) << str << endl; } if (flag) { cout << endl << "对不起!!!没有你找的管理员信息!!!!" << endl << endl; } else { while (getline(inData, str)) { outData << str << endl; } outData.close(); inData.close(); ofstream out("e:\\Document.txt", ios::out); ifstream in("e:\\temp1.txt", ios::in); if (!out || !in) { cout << endl << "对不起,不能打开文件!!!" << endl << endl; system("pause"); return; } while (getline(in,str)) { out << str << endl; } out.close(); in.close(); cout << endl << "这个管理员的信息已经删除!!!" << endl << endl; } system("pause"); } void machine::Show()//显示所有信息 { ifstream inData("e:\\pbook.txt",ios::in); if (!inData) { cout << endl << "对不起!!!!没有找到文件!!!!!" << endl; system("pause"); return; } bool flag = true; string record; while (getline(inData, record)) { if (flag) { cout << endl << "所有设备信息如下: " << endl; cout << H << H1 << H2; } cout << " " << record << " " << endl; cout << H2; flag = false; } if (flag) { cout << endl << "系统中没有设备信息!!!!!" << endl << endl; } else { cout << endl << "所有设备信息已经全部显示出来!!!!!" << endl << endl; } system("pause"); } void super_admin::Show() { ifstream inData("e:\\Document.txt",ios::in); if (!inData) { cout << endl << "对不起!!!!没有找到文件!!!!!" << endl; system("pause"); return; } bool flag = true; string record; while (getline(inData, record)) { if (flag) { cout << endl << "所有管理员信息如下: " << endl; cout << H3 << H4 << H5; } cout << record << endl; cout << H5; flag = false; } if (flag) { cout << endl << "系统中没有管理员信息!!!!!" << endl << endl; } else { cout << endl << "所有管理员信息已经全部显示出来!!!!!" << endl << endl; } system("pause"); } void machine::Modify()//修改信息 { ofstream outData("e:\\temp.txt", ios::out); ifstream inData("e:\\pbook.txt", ios::in); if (!inData) { cout << endl << "对不起!!!!找不到文件!!!!" << endl; system("pause"); return; } string sign; cout << endl << "你要修改设备的编号 :"; cin >> sign; bool flag = true; string str; while (inData >> num) { getline(inData, str); if (sign == num) { cout << endl <<"你想修改的设备信息:" << endl << endl; cout << H << H1 << H2; cout << setw(15) << num << str << endl; cout << H2; cout <<endl <<"请根据下面提示修改信息 : " << endl; cout << "编号 : " ; cin >> num; cout << "类别 : "; cin >> category; cout << "名称 : "; cin >> name; cout << "价格 : "; cin >> price; cout << "库存数量 : "; cin >> quantity; Save_new(); flag = false; break; } outData << setiosflags(ios::left) << num << setw(15) << str << endl; } if (flag) { cout << endl << "对不起!!!没有找到这个设备!!!!" << endl << endl; } else { while(getline(inData, str)) { outData << str << endl; } outData.close(); inData.close(); ofstream out("e:\\pbook.txt", ios::out); ifstream in("e:\\temp.txt", ios::in); if (!out || !in) { cout << endl <<"对不起不能打开文件!!!" << endl << endl; system("pause"); return; } while (getline(in, str)) { out << str << endl; } out.close(); in.close(); cout << endl << "这个设备的信息已经修改!!!" << endl << endl; } system("pause"); } void super_admin::Modify() { ofstream outData("e:\\temp1.txt", ios::out); ifstream inData("e:\\Document.txt", ios::in); if (!inData) { cout << endl << "对不起!!!!找不到文件!!!!" << endl; system("pause"); return; } string sign; cout << endl << "你要修改管理员的帐号 :"; cin >> sign; bool flag = true; string str; while (inData >> id) { getline(inData, str); if (sign == id) { cout << endl << "你想修改的管理员信息:" << endl << endl; cout << H3 << H4 << H5; cout << setw(15) << id << str << endl; cout << H5; cout << endl << "请根据下面提示修改信息 : " << endl; cout << "帐号 : " ; cin >> id; cout <<"密码 : "; cin >> password; Save_new(); flag = false; break; } outData << setiosflags(ios::left) << id << setw(10) << str << endl; } if (flag) { cout << endl << "对不起!!!没有找到这个管理员信息!!!!" << endl << endl; } else { while(getline(inData, str)) { outData << str << endl; } outData.close(); inData.close(); ofstream out("e:\\Document.txt", ios::out); ifstream in("e:\\temp1.txt", ios::in); if (!out || !in) { cout << endl << "对不起不能打开文件!!!" << endl << endl; system("pause"); return; } while (getline(in, str)) { out << str << endl; } out.close(); in.close(); cout << endl << "这个设备的信息已经修改!!!" << endl << endl; } system("pause"); } void machine::Search()//查询设备 { ifstream inData("e:\\pbook.txt",ios::in); if (!inData) { cout << endl << "对不起!文件找不到" << endl; system("pause"); return; } string sign; cout << endl << "输入你想查找的设备编号: "; cin >> sign; string str1; bool flag = true; string str; while (inData >> num) { getline(inData, str); if (num == sign) { cout << endl << "你要查找的设备是: " << endl << endl; cout << H << H1 << H2; cout << setw(13) << num << str << endl; cout << H2; flag = false; system("pause"); break; } } if(flag) { cout << endl <<"你要查找的设备不存在!" << endl << endl; system("pause"); } } void super_admin::Search() { ifstream inData("e:\\Document.txt",ios::in); if (!inData) { cout << endl << "对不起!文件找不到" << endl; system("pause"); return; } string sign; cout << endl << "输入你想查找的管理员帐号: "; cin >> sign; string str1; bool flag = true; string str; while (inData >> id) { getline(inData, str); if (id == sign) { cout << endl << "你要查找的管理员信息是: " << endl << endl; cout << H3 << H4 << H5; cout << setw(15) << id << str << endl; cout << H5; flag = false; system("pause"); break; } } if(flag) { cout << endl <<"你要查找的管理员信息不存在!" << endl << endl; system("pause"); } } void machine::Save_new() { ofstream outData("e:\\pbook.txt", ios::app); if (!outData) { cout << endl << "对不起!!!打开文件失败!!!!" << endl << endl; system("pause"); return; } outData << setw(10)<< num <<" " << setw(10) << category << " " << setw(10) << name << " " << setw(10) << price << " " << setw(10) << quantity << endl; outData.close(); } void super_admin::Save_new() { ofstream outData("e:\\Document.txt", ios::app); if (!outData) { cout << endl << "对不起!!!打开文件失败!!!!" << endl << endl; system("pause"); return; } outData << setw(12) << id << " " << setw(12) << password << " " << endl; outData.close(); } int main() { machine Machine; user User; admin Admin; super_admin VIP; introduce Introduce; Introduce.display(); while(1) { switch(User.home_face()) { case '1': User.entrance(); break; case '2': Admin.admin_enter(); break; case '3': VIP.super_admin_enter(); break; case '4': return 0; } } }
相关文章推荐
- c++ 课程设计 ——公司设备管理系统
- C++课程设计( 南阳康佳公司的设备管理系统 )
- 数据库课程设计_实验室管理系统_设备维修
- C++ 课程设计学生成绩管理系统源代码
- C++课程设计之水电煤气管理系统
- 数据结构课程设计-通讯录管理系统c++版(顺序表存储,折半查找,递增排序)
- C++课程设计:职工综合信息管理系统
- C++课程设计:学生成绩管理系统
- 16级C++课程设计 题目1 “高校人员信息管理系统设计”
- C++课程设计报告--通讯录管理系统
- 数据库课程设计_实验室管理系统_设备报废
- C++课程设计:学生成绩管理系统
- c++课程设计题目--"信用卡帐户管理系统"
- 数据库课程设计_实验室管理系统_设备维修查询
- 数据库课程设计_实验室管理系统_设备信息查询
- 数据库课程设计_实验室管理系统_设备报废查询
- C++课程设计-成绩管理系统
- c++课程设计——班车管理系统
- 数据结构之链表的实现-------C++课程设计-----学生选课管理系统
- c++程序课程设计的内容--职工工资管理系统