c++カリキュラム設計——会社設備管理システム
25924 ワード
何日かカリキュラムのデザインを書いて、やっと手が出せるようになりました!!
书き终わった后にc++の颜の対象の思想に対してまた少し新しい悟りがあると感じて、1つの言语をマスターするにはやはり多くコードを书きます!
vip管理者アカウント:adminパスワード:123456
一般管理者のアカウントはvip管理者が追加できます
书き终わった后にc++の颜の対象の思想に対してまた少し新しい悟りがあると感じて、1つの言语をマスターするにはやはり多くコードを书きます!
vip管理者アカウント:adminパスワード:123456
一般管理者のアカウントはvip管理者が追加できます
#include<iostream>
#include<string>
#include<cstring>
#include <iomanip>
#include <cstdlib>
#include<conio.h>
#include<fstream>
#include<windows.h>
using namespace std;
#define H "----------------------------------------------------------------
"
#define H1 "| | | | | |
"
#define H2 "|-----------|-----------|------------|------------|------------|
"
#define H3 "--------------------------
"
#define H4 "| | |
"
#define H5 "|-----------|------------|
"
class machine
{
public:
machine();
machine(string a,string b,string c,double d,int e);
//char inter_face();//
void add();//
void dele();//
void show();//
void alter();//
void select();//
void save_new();//
private:
string num;
string category;
string name;
double price;
int quantity;
};
class account
{
public:
account();
char home_face();
virtual void entrance();
// void enter;
private:
string id;
string password;
};
class admin:public account
{
public:
admin();
virtual void admin_enter();
void entrance();
private:
string id;
string password;
};
class vip:public admin
{
public:
vip();
void vip_enter();
void entrance();
void inter_face();//
void add();//
void dele();//
void show();//
void alter();//
void select();//
void save_new();//
private:
string id;
string password;
};
machine::machine()
{
num=" ";
category=" ";
name=" ";
price=0;
quantity=0;
}
account::account()
{
id=" ";
password=" ";
}
admin::admin()
{
id=" ";
password=" ";
}
vip::vip()
{
id="admin";
password="123456";
}
void account::entrance()
{
system("color 0b");
char n;
machine m;
while(1)
{
system("cls");
cout <<endl;
cout<<"\t\t O(∩_∩)O~~
";
cout<<"\t\t╔*☆***◎***◇***☆*** ***☆***◇***◎***☆*╗
";
cout<<"\t\t|★|\t\t \t\t\t|★|
";
cout<<"\t\t|☆|\t\t \t\t\t|☆|
";
cout<<"\t\t|★|\t\t 1. \t\t\t|★|
";
cout<<"\t\t|☆|\t\t 2. \t\t\t|☆|
";
cout<<"\t\t|★|\t\t 3. \t\t\t|★|
";
cout<<"\t\t|☆|\t\t \t\t\t|☆|
";
cout<<"\t\t|★|\t\t \t\t\t|★|
";
cout<<"\t\t|☆|\t\t \t\t\t|☆|
";
cout<<"\t\t╚*☆***◎***◇****☆****★****☆****◇***◎***☆*╝
";
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.select();
if(n=='3') return;
}
}
void admin::admin_enter()
{
string pp;
char m;
admin Admin;
system("cls");
cout<<endl<<endl<<endl;
cout<<"\t\t O(∩_∩)O~~
";
while(1)
{
ifstream inData("e:\\Document.txt",ios::in);
cout<<"\t\t :
\t\t ( , # )"<<endl;
cout<<"\t\t ";
cin>>pp;
if (!inData)
{
cout <<endl <<"
! " <<endl;
system("pause");
return;
}
if(pp=="#") return;
string qq;
l:; cout<<"\t\t :
";
cout<<"\t\t ";
while(1)
{
m=getch();
if(m==13) break;
if(m!=8) qq+=m;
if(m==8) {cout<<endl;goto l;}
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<<"
\t\t ! !!
"<<endl;
}
}
if(flag)
{
cout<<"
\t\t ! !!
"<<endl;
//system("pause");
}
}
}
void vip::vip_enter()
{
string pp;
char m;
vip VIP;
admin Admin;
system("cls");
cout<<endl<<endl;
cout<<"\t\t O(∩_∩)O~~
";
while(1)
{
cout<<"\t\t vip :
\t\t ( , # )"<<endl;
cout<<"\t\t ";
cin>>pp;
getchar();
if(pp=="#") return;
if(pp==VIP.id)
{
L:;cout<<"\t\t :"<<endl;
cout<<"\t\t ";
string qq;
while(1)
{
m=getch();
if(m==13) break;
if(m!=8) qq+=m;
if(m==8)
{
cout<<endl;goto L;
}
cerr<<"*";
}
if(qq==VIP.password)
{
VIP.entrance();
break;
}
else
{
cout<<"
\t\t ! !!
"<<endl;
}
}
else
{
cout<<"\t\t ! !!
"<<endl;
}
}
}
void admin::entrance()
{
system("color 0c");
char n;
machine Machine;
account Account;
while(1)
{
system("cls");
cout <<endl;
cout<<"\t\t O(∩_∩)O~~
";
cout<<"\t\t╔*☆***◎***◇***☆*** ***☆***◇***◎***☆*╗
";
cout<<"\t\t|★|\t\t \t\t\t|★|
";
cout<<"\t\t|☆|\t\t 1. \t\t\t|☆|
";
cout<<"\t\t|★|\t\t 2. \t\t\t|★|
";
cout<<"\t\t|☆|\t\t 3. \t\t\t|☆|
";
cout<<"\t\t|★|\t\t 4. \t\t\t|★|
";
cout<<"\t\t|☆|\t\t 5. \t\t\t|☆|
";
cout<<"\t\t|★|\t\t 6. \t\t\t\t|★|
";
cout<<"\t\t|☆|\t\t \t\t\t|☆|
";
cout<<"\t\t╚*☆***◎***◇****☆****★****☆****◇***◎***☆*╝
";
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.select();break;
case '4':Machine.alter();break;
case '5':Machine.dele();break;
case '6':return;
}
}
}
void vip::entrance()
{
system("color 0e");
char n;
machine Machine;
vip VIP;
while(1)
{
system("cls");
cout <<endl;
cout<<"\t\t O(∩_∩)O~~
";
cout<<"\t\t╔*☆***◎***◇***☆*** ***☆***◇***◎***☆*╗
";
cout<<"\t\t|★|\t\t \t\t|★|
";
cout<<"\t\t|☆|\t\t1. \t\t|☆|
";
cout<<"\t\t|★|\t\t2. \t\t|★|
";
cout<<"\t\t|☆|\t\t3. \t\t|☆|
";
cout<<"\t\t|★|\t\t4. \t\t|★|
";
cout<<"\t\t|☆|\t\t5. \t\t|☆|
";
cout<<"\t\t|★|\t\t6. \t\t|★|
";
cout<<"\t\t|★|\t\t7. \t\t|★|
";
cout<<"\t\t|☆|\t\t \t\t|☆|
";
cout<<"\t\t╚*☆***◎***◇****☆****★****☆****◇***◎***☆*╝
";
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.select();break;
case '4':Machine.alter();break;
case '5':Machine.dele();break;
case '6':VIP.inter_face();break;
case '7':return;
}
}
}
void vip::inter_face()
{
system("color 0c");
char n;
vip VIP;
account Account;
while(1)
{
system("cls");
cout <<endl;
cout<<"\t\t O(∩_∩)O~~
";
cout<<"\t\t╔*☆***◎***◇***☆*** ***☆***◇***◎***☆*╗
";
cout<<"\t\t|★|\t\t \t\t|★|
";
cout<<"\t\t|☆|\t\t 1. \t\t|☆|
";
cout<<"\t\t|★|\t\t 2. \t\t|★|
";
cout<<"\t\t|☆|\t\t 3. \t\t|☆|
";
cout<<"\t\t|★|\t\t 4. \t\t|★|
";
cout<<"\t\t|☆|\t\t 5. \t\t|☆|
";
cout<<"\t\t|★|\t\t 6. \t\t|★|
";
cout<<"\t\t|☆|\t\t \t\t|☆|
";
cout<<"\t\t╚*☆***◎***◇****☆****★****☆****◇***◎***☆*╝
";
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.select();break;
case '4':VIP.alter();break;
case '5':VIP.dele();break;
case '6':return;
}
}
}
void Get_xy(int x,int y) //
{
COORD pos;
pos.X=x;
pos.Y=y;
HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hout,pos);
}
char account::home_face()
{
system("color 0d");
char n;
system("cls");
cout <<endl;
for(int i=0;i<9;i++) //
{
Get_xy(8,4);
if(i%2==0) cout<<"\t O(∩_∩)O~~
";
else cout<<endl<<endl;
if(i%2==0) cout<<"\t\t╔*☆***◎***◇***☆*** ***☆***◇***◎***☆*╗
";
else cout<<endl;
cout<<"\t\t|★|\t\t \t\t\t|★|
";
if(i%2==0) cout<<"\t\t|☆|\t\t \t\t\t|☆|
";
else cout<<endl;
cout<<"\t\t|★|\t\t1. \t\t\t|★|
";
cout<<"\t\t|☆|\t\t2. \t\t\t|☆|
";
cout<<"\t\t|★|\t\t3.VIP \t\t\t|★|
";
cout<<"\t\t|☆|\t\t4. \t\t\t|☆|
";
if(i%2==0)cout<<"\t\t|★|\t\t \t\t\t|★|
";
else cout<<endl;
cout<<"\t\t|☆|\t\t \t\t\t|☆|
";
if(i%2==0)cout<<"\t\t╚*☆***◎***◇****☆****★****☆****◇***◎***☆*╝
";
else cout<<endl<<endl;
cout<<"\t\t (1-4): [ ]\b\b";
Sleep(50); 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=="tv_dvd") break;
else
cout<<" tv dvd tv_dvd " <<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 vip::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::dele()
{
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(10)<<num<<str<<endl;
cout<<H2;
flag = false;
break;
}
outData<<setiosflags(ios::left)<<num<<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:\\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 vip::dele()
{
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(10)<<id<<str<<endl;
cout<<H5;
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::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 vip::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::alter()
{
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(10)<<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(10)<<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 vip::alter()
{
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(10)<<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::select()
{
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(10)<<num<<str<<endl;
cout<<H2;
flag = false;
system("pause");
break;
}
}
if(flag)
{
cout <<endl <<" !" <<endl <<endl;
system("pause");
}
}
void vip::select()
{
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(10)<<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 vip::save_new()
{
ofstream outData("e:\\Document.txt", ios::app);
if (!outData)
{
cout <<endl <<" !!! !!!!" <<endl <<endl;
system("pause");
return;
}
outData<<setw(10)<<id
<<" " << setw(10) <<password <<" "<<endl;
outData.close();
}
int main()
{
machine Machine;
account Account;
admin Admin;
vip VIP;
while(1)
{
switch(Account.home_face())
{
case '1':Account.entrance();break;
case '2':Admin.admin_enter();break;
case '3':VIP.vip_enter();break;
case '4': MessageBox(NULL," Thanks for you!!
\t\t---Made by hrdv \t ","☆Bye☆Bye☆",0);return 0;//
}
}
}