📄 temp.cpp
字号:
class Trade
{
private:
int Trade_code;
int quantity;
char item[20];
public:
Trade()
{
item[0]=NULL;
}
void getdata();
void showdata();
char *rtnname() {return item;}
};
class Guest
{
private:
char Guest_name[10];
int Guest_code;
char Phone_NO[10];
int quantity;
Trade trd[9];
void getdata();
void showdata();
public:
void add();
void remove();
void search();
void showag();
};
void Trade::getdata()
{
switch(lgwg)
{
case 1:
cout<<"\n\nEnter Item Name ";
cin.ignore();
cin.getline(item,20);
cout<<"\nEnter Trade Code ";
cin>>Trade_code;
cout<<"\nEnter Item Quantity ";
cin>>quantity;
break;
case 2:
cout<<"\n\n请输入物品名称: ";
cin.ignore();
cin.getline(item,20);
cout<<"\n请输入物品编号: ";
cin>>Trade_code;
cout<<"\n请输入物品数量: ";
cin>>quantity;
}
}
void Trade::showdata()
{
switch(lgwg)
{
case 1:
cout<<"\n\nItem Name : "; cout<<item;
cout<<"\n\nTrade Code : "; cout<<Trade_code;
cout<<"\n\nItem Quantity : "; cout<<quantity<<endl;
break;
case 2:
cout<<"\n\n物品名称 : "; cout<<item;
cout<<"\n\n物品编号 : "; cout<<Trade_code;
cout<<"\n\n物品数量 : "; cout<<quantity<<endl;
}
}
void Guest::getdata()
{
switch(lgwg)
{
case 1:
cout<<"\nEnter Guest Name ";
cin.ignore();
cin.getline(Guest_name,10);
cout<<"\nEnter Guest Code ";
cin>>Guest_code;
cout<<"\nEnter Phone Number ";
cin.ignore();
cin.getline(Phone_NO,10);
cout<<"\nEnter The Quantity of Traded Item ";
cin>>quantity;
cout<<"\nEnter The Number of Sort (Less than nine) ";
cin>>num;
for(i=0;i<num;i++)
{
cout<<"\n\nEnter Item "<<i+1;
trd[i].getdata();
}
i=0;
break;
case 2:
cout<<"\n请输入客户名称: ";
cin.ignore();
cin.getline(Guest_name,10);
cout<<"\n请输入客户序号: ";
cin>>Guest_code;
cout<<"\n请输入联系电话: ";
cin.ignore();
cin.getline(Phone_NO,10);
cout<<"\n请输入交易物品总数: ";
cin>>quantity;
cout<<"\n请输入种类个数(九个以内): ";
cin>>num;
for(i=0;i<num;i++)
{
cout<<"\n\n请输入第"<<i+1<<"种物品数据: ";
trd[i].getdata();
}
i=0;
}
}
void Guest::showdata()
{
switch(lgwg)
{
case 1:
cout<<"\n\n\t\tGuest Data";
cout<<"\n\nGuest Name : ";
cout<<Guest_name;
cout<<"\n\nGuest Code : ";
cout<<Guest_code;
cout<<"\n\nPhone Number : ";
cout<<Phone_NO;
cout<<"\n\nQuantity of Traded Item: ";
cout<<quantity;
cout<<"\n\nPress Enter to continue.";cin.get(pause);
while(*trd[i].rtnname())
{
cout<<"\n\nItem "<<i+1<<endl; trd[i].showdata();
i++;
cout<<"\n\nPress Enter to continue.";cin.get(pause);
}
i=0;
break;
case 2:
cout<<"\n\n\t\t客户数据";
cout<<"\n\n客户名称 : ";
cout<<Guest_name;
cout<<"\n\n客户序号 : ";
cout<<Guest_code;
cout<<"\n\n联系电话 : ";
cout<<Phone_NO;
cout<<"\n\n交易物品总数 : ";
cout<<quantity;
cout<<"\n\n按回车继续";cin.get(pause);
while(*trd[i].rtnname())
{
cout<<"\n\n第"<<i+1<<"种物品\n"; trd[i].showdata();
i++;
cout<<"\n\n按回车继续";cin.get(pause);
}
i=0;
}
}
void Guest::add()
{
ofstream file( "TGS.txt", ios::out |ios::ate );
if(!file)
{
if(lgwg==1) cout<<"Error Could Not Open File.\n\nPress Enter to continue.";
else cout<<"错误!无法打开文件。\n\n按回车继续";
cin.ignore();cin.get(pause);
exit(1);
}
Guest p1;
p1.getdata();
file.write(reinterpret_cast <const char *> (&p1),sizeof(Guest) );
}
void Guest::showag()
{
system("cls");
ifstream file( "TGS.txt" ,ios::in);
if(!file)
{
if(lgwg==1) cout<<"Error Could Not Open File.\n\nPress Enter to continue.";
else cout<<"错误!无法打开文件。\n\n按回车继续";
cin.ignore();cin.get(pause);
exit(1);
}
Guest p1;
file.read(reinterpret_cast<char *>(&p1),sizeof(Guest));
cin.ignore();
while(!file.eof())
{
p1.showdata() ;
file.read(reinterpret_cast<char *> (&p1),sizeof(Guest));
}
}
void Guest::search()
{
node3:
char name1[10]={NULL};
int code=-1;
int option;
system("cls");
if(lgwg==1) cout<<"\n(1)Search By Name\n(2)Search By Code\n(3)Search By Phone Number\n(4)Back ";
else cout<<"\n(1)按客户名称搜索\n(2)按客户序号搜索\n(3)按联系电话搜索\n(4)返回 ";
cin>>option;
cin.ignore();
switch(option)
{
case 1:
if(lgwg==1) cout<<"\nEnter Guest name ";
else cout<<"\n请输入客户名称 :";
cin.getline(name1,10);
break;
case 2:
if(lgwg==1) cout<<"\nEnter Guest Code ";
else cout<<"\n请输入客户序号 : ";
cin>>code;
cin.ignore();
break;
case 3:
if(lgwg==1) cout<<"\nEnter The Price ";
else cout<<"\n请输入联系电话 : ";
cin.getline(name1,10);
break;
case 4:
system("cls");
return;
default:
goto node3;
}
fstream file( "TGS.txt" ,ios::in);
if(!file)
{
if(lgwg==1) cout<<"Error Could Not Open File.\n\nPress Enter to continue.";
else cout<<"错误!无法打开文件。\n\n按回车继续";
cin.ignore();cin.get(pause);
exit(1);
}
char flag='a';
Guest p1;
file.read(reinterpret_cast<char *>(&p1),sizeof(Guest));
while(!file.eof())
{
if((strcmp(p1.Guest_name,name1)==0)||(p1.Guest_code==code)||(strcmp(p1.Phone_NO,name1)==0))
{
p1.showdata();
flag='z';
break;
}
file.read(reinterpret_cast<char *> (&p1),sizeof(Guest));
}
if(flag !='z')
{
if(lgwg==1) cout<<"Guest Not Found.\n\nPress Enter to continue.";
else cout<<"未找到匹配档案。\n\n按回车继续";
cin.get(pause);
}
goto node3;
}
void Guest::remove()
{
node4:
char name1[10]={NULL};
int code;
int option;
system("cls");
if(lgwg==1) cout<<"\n(1)Delete By Name\n(2)Delete By Code\n(3)Back ";
else cout<<"\n(1)按名称清除\n(2)按序号清除\n(3)返回 ";
cin>>option;
switch(option)
{
case 1:
if(lgwg==1) cout<<"\nEnter Guest name ";
else cout<<"\n请输入客户名称 :";
cin.ignore();
cin.getline(name1,10);
code=0;
break;
case 2:
if(lgwg==1) cout<<"\nEnter Guest Code ";
else cout<<"\n请输入客户序号 :";
cin>>code;
cin.ignore();
break;
case 3:
system("cls");
return;
default:
goto node4;
}
ifstream file( "TGS.txt" ,ios::in );
ofstream temp( "deleteG.txt", ios::trunc);
if(!file||!temp)
{
if(lgwg==1) cout<<"Error Could Not Open File.\n\nPress Enter to continue.";
else cout<<"错误!无法打开文件。\n\n按回车继续";
cin.ignore();cin.get(pause);
exit(1);
}
file.seekg(0);
temp.seekp(0);
Guest p1;
file.read(reinterpret_cast<char *> (&p1),sizeof(Guest));
char flag='a';
while(!file.eof())
{
if((strcmp(name1,p1.Guest_name)==0)||(code==p1.Guest_code))
{
file.read(reinterpret_cast<char *> (&p1),sizeof(Guest));
flag='z';
}
else
{
temp.write(reinterpret_cast<char *> (&p1),sizeof(Guest));
file.read(reinterpret_cast<char *> (&p1),sizeof(Guest));
}
}
file.close();
temp.close();
ifstream temp1("deleteG.txt",ios::in);
ofstream file1("TGS.txt", ios::trunc);
temp1.seekg(0);
file1.seekp(0);
temp1.read(reinterpret_cast<char *> (&p1),sizeof(Guest));
while(!temp1.eof())
{
file1.write(reinterpret_cast<char *> (&p1),sizeof(Guest) );
temp1.read(reinterpret_cast<char *> (&p1),sizeof(Guest) );
}
temp1.close();
file1.close();
if(flag=='z')
{
if(lgwg==1) cout<<"Deleted.\n\nPress Enter to continue.";
else cout<<"已删除。\n\n按回车继续";
cin.get(pause);
}
else
{
if(lgwg==1) cout<<"Guest Not Found.\n\nPress Enter to continue.";
else cout<<"未找到匹配档案。\n\n按回车继续";
cin.get(pause);
}
goto node4;
}
void welcome()
{
int choice;
system("cls");
cout<<"\n\n\n\t\t Please Choice The Language(请选择语言):\n\t\t (1)English(英文)\t (2)Chinese(中文)\n\t\t\t\t\t";
cin>>lgwg;
while(lgwg!=1&&lgwg!=2)
{
cout<<"\t\tBad Command.Please Choice Again.(无效!情重新输入)\n\t\t\t\t\t";
cin>>lgwg;
}
system("cls");
if(lgwg==1)
{
cout"\n\nPlease Choice The Program:\n(1)The Inventory System (TIS) Ver.1\n(2)The Guest System (TGS) Ver.1\n";
cin>>choice;
}
else
{
cout"\n\n请选择程序:\n(1)物品库存管理程序 第一版\n(2)客户管理程序 第一版\n";
cin>>choice;
}
switch(choice)
{
case 1: TIS();break;
case 2: TGS();break;
}
}
void TGS()
{
system("cls");
switch(lgwg)
{
case 1:
cout<<"\t\t*************************************************\n";
cout<<"\t\t* *\n";
cout<<"\t\t* Welcome to The Guest System (TGS) Ver.1 *\n";
cout<<"\t\t* *\n";
cout<<"\t\t* Projected by: Fan Jingyu *\n";
cout<<"\t\t* *\n";
cout<<"\t\t* Class:03042101 Code:03304578 *\n";
cout<<"\t\t* *\n";
cout<<"\t\t*************************************************\n\n";
break;
case 2:
cout<<"\t\t*************************************************\n";
cout<<"\t\t* *\n";
cout<<"\t\t* 欢迎使用客户管理程序 第一版 *\n";
cout<<"\t\t* *\n";
cout<<"\t\t* 设计者: 樊劲宇 *\n";
cout<<"\t\t* *\n";
cout<<"\t\t* 班级:03042101 学号:03304578 *\n";
cout<<"\t\t* *\n";
cout<<"\t\t*************************************************\n\n";
}
if(lgwg==1) cout<<"\n\n\t\t\tPress Enter to continue.";
else cout<<"\n\n\t\t\t\t按回车继续";
cin.ignore();cin.get(pause);
Guest n;
int choice;
while(1)
{
system("cls");
if(lgwg==1)
{
cout<<"\n\n(1)Add Guest\n\n(2)Show All The Guest\n\n(3)Search Guest\n\n(4)Remove Guest\n\n(5)Back\n\n(6)Exit TGS";
cout<<"\n\nEnter Choice ";
}
else
{
cout<<"\n\n(1)增加客户\n\n(2)显示所有客户\n\n(3)查找客户\n\n(4)清除客户\n\n(5)返回\n\n(6)退出程序";
cout<<"\n\n请输入选择项: ";
}
cin>>choice;
switch(choice)
{
case 1:
n.add();
break;
case 2:
n.showag();
break;
case 3:
n.search();
break;
case 4:
n.remove();
break;
case 5:
welcome();
break;
case 6:
exit(1);
default:
{
if(lgwg==1) cout<<"Bad Command.Please Choice Again.\n";
else cout<<"无效!情重新输入\n";
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -