C++ 食堂管理系统
此食堂管理系统的C++项目包括顾客和产品的搜索、显示、更改和删除功能。该程序在用户提交订单之前对文件中保存的客户信息进行搜索。该软件适用于需要跟踪数据并拥有有限顾客和物品数量的小食堂。
此外,顾客可以选择购买商品。如果顾客选择是,他们将有机会输入每件商品的价格,并在过程结束时打印所购买商品的发票,并从取货中心备份所购买的商品。管理员现在将仅负责查看最终账单并提供对新客户和现有客户的协助。
C++食堂管理系统的特点
- 顾客菜单: 在顾客菜单中,管理员可以添加顾客信息,显示所有顾客,搜索记录,编辑记录和删除顾客记录。
- 产品菜单: 产品菜单中有五个部分,允许管理员添加新产品,查看已有产品,搜索记录,编辑产品信息和删除产品。
- 产品报告生成器: 顾客输入产品编号,然后输入每个商品的数量,程序计算税后总额。
程序情况解析
struct order
{
int prodid1 ;
char pname1 [ 50 ] ;
char compy1 [ 50 ] ;
int qty1 ;
float price1 , dis1 ;
} o1 [ 50 ] ;
上述代码将成为我们餐厅管理系统中项目的结构,该项目将包括产品id、产品名称、产品公司和产品价格。
int orderk = 0 ;
void middleadminmenu ( ) ;
void copyme ( int k , order order1 [ ] , int q1 , int & c2 ) ;
void intromain ( ) ;
int getproduct ( ) ;
int getcustomers ( ) ;
void display_all ( ) ;
void display_all_cust ( ) ;
void prod_tabular ( ) ;
void modify_record ( int n ) ;
void delete_record ( int n ) ;
void againopenandclose ( ) ;
void againopenandclosecust ( ) ;
int search ( int p ) ;
void changeqty ( int pr1 , int q11 ) ;
void gotoxy ( int x , int y )
{
static HANDLE h = NULL ;
if ( !h )
h = GetStdHandle ( STD_OUTPUT_HANDLE ) ;
COORD c = { x , y } ;
SetConsoleCursorPosition ( h , c ) ;
}
上述的预定义功能将会在我们的大学食堂管理系统中存在,例如,要修改记录,我们有modify_record,它将帮助修改系统中的记录,delete_record将允许用户删除系统中的一条记录等等。
class customer
{
int cust_id ;
char cname [ 25 ] ;
char address [ 35 ] ;
char phno [ 15 ] ;
public :
void modifycust_data ( int n1 , char nm [ 15 ] , char add [ 15 ] , char q [ 15 ] ) ;
int getcustid ( )
{ return cust_id ; }
char * getcustnm ( )
{ return cname ; }
char * getcustadd ( )
{ return address ; }
char * getphno ( )
{ return phno ; };
您可以通过选择管理员模块来访问客户菜单,该菜单被分为五个选项。第一个选项是创建客户详细信息。第三个选项是搜索记录(查询),第四个选项是修改客户记录,第五个选项是删除客户记录。第二个选项是显示所有客户详细信息。
void show_cust ( )
{
gotoxy ( 5 , 7 ) ;
cout < < " = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = " ;
gotoxy ( 10 , 8 ) ;
cout < < " CUST NO : " ;
gotoxy ( 25 , 8 ) ;
cout < < cust_id ;
gotoxy ( 35 , 8 ) ;
cout < < " NAME OF CUST : " ;
gotoxy ( 54 , 8 ) ;
cout < < cname ;
gotoxy ( 10 , 9 ) ;
cout < < " ADDRESS: " ;
gotoxy ( 25 , 9 ) ;
cout < < address ;
gotoxy ( 10 , 10 ) ;
cout < < " PHONE NO.: " ;
gotoxy ( 25 , 10 ) ;
cout < < phno ;
gotoxy ( 5 , 12 ) ;
cout < < " = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = " ;
}
上述代码将用于显示客户输入的客户详情。包括客户的姓名、电话号码和地址。
void customer : : modifycust_data ( int n1 , char nm [ 15 ] , char add [ 15 ] , char q [ 15 ] )
{
char tmpnm [ 40 ] , tmpnm2 [ 40 ] , tmpnm3 [ 15 ] ;
gotoxy ( 5 , 14 ) ;
cout < < " = = = = = = = = = = = = = = = WANT TO MODIFY = = = = = = = = = = = = = = " ;
gotoxy ( 10 , 15 ) ;
cout < < " CUST NO : " ;
cust_id = n1 ;
gotoxy ( 25 , 15 ) ;
cout < < cust_id ;
gotoxy ( 40 , 15 ) ;
strcpy ( cname , nm ) ;
cout < < " NAME OF CUST : " ;
gotoxy ( 60 , 15 ) ;
cout < < cname ;
gotoxy ( 10 , 17 ) ;
cout < < " Want to change the name of customer " ;
gotoxy ( 50 , 17 ) ;
int flag = 0 ;
while ( 1 )
{
gets ( tmpnm ) ;
if ( strlen ( tmpnm ) != 0 )
{
flag = 1 ;
break ;
}
if ( strlen ( tmpnm ) == 0 )
{ flag = 0 ;
break ;
}
}
if ( flag == 1 )
{ strcpy ( cname , tmpnm ) ;
}
else
{
}
gotoxy ( 1 , 18 ) ;
strcpy ( address , add ) ;
// * * * * * * * * * * * * NAME TO BE MODIFY
cout < < " CUSTOMER ADDRESS : " ;
gotoxy ( 20 , 18 ) ;
cout < < address ;
gotoxy ( 45 , 18 ) ;
cout < < " Want to change the address " ;
gotoxy ( 70 , 18 ) ;
flag = 0 ;
while ( 1 )
{
gets ( tmpnm2 ) ;
if ( strlen ( tmpnm2 ) != 0 )
{
flag = 1 ;
break ;
}
if ( strlen ( tmpnm2 ) == 0 )
{ flag = 0 ;
break ;
}
}
if ( flag == 1 )
{ strcpy ( address , tmpnm2 ) ;
}
// * * * * * * * * * * * * * COMPANY NAME TO BE MODIFIED ENDS HERE
gotoxy ( 5 , 19 ) ;
strcpy ( phno , q ) ;
// * * * * * * * * * * * * * * * * phone no. TO BE MODIFY
cout < < " CUSTOMER PHONE NO. : " ;
gotoxy ( 20 , 18 ) ;
cout < < phno ;
gotoxy ( 45 , 18 ) ;
cout < < " Want to change the phone no. " ;
gotoxy ( 70 , 18 ) ;
flag = 0 ;
while ( 1 )
{
gets ( tmpnm3 ) ;
if ( strlen ( tmpnm3 ) != 0 )
{
flag = 1 ;
break ;
}
if ( strlen ( tmpnm3 ) == 0 )
{ flag = 0 ;
break ;
}
}
if ( flag == 1 )
{ strcpy ( phno , tmpnm3 ) ;
}
// * * * * * * * * * * * * * * * * * MODIFIED ENDS HERE
gotoxy ( 5 , 20 ) ;
cout < < " = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = " ;
}
客户还可以编辑他们之前输入的数据,例如客户的姓名、电话号码和地址,上述代码将帮助完成这些任务。
void cust_tabular ( )
{
int r = 0 , col = 10 ;
customer cust ;
ifstream inFile ;
inFile.open ( " customer.dat " , ios::binary ) ;
if ( !inFile )
{
cout < < " File could not be open !! Press any Key... " ;
getch ( ) ;
return ;
}
display_all_cust ( ) ;
while ( inFile.read ( ( char * ) &cust , sizeof ( customer ) ) )
{
if ( r <= 12 )
{
r + + ;
cust.showallcust ( col ) ;
col + + ;
}else
{
gotoxy ( 20 , 30 ) ;
cout < < " - - - - - - - - - - - press any key - - - - - - - - - - - - - " ;
getch ( ) ;
system ( " cls " ) ;
display_all_cust ( ) ;
col = 10 ;
r = 0 ;
}
}
inFile.close ( ) ;
getch ( ) ;
}
通过上述代码的帮助,客户数据的更改将以表格形式显示。
void display_all_cust ( )
{
system ( " cls " ) ;
intromain ( ) ;
gotoxy ( 1 , 5 ) ;
cout < < " * * * * * * * * * * * * * * * * * CUSTOMER DETAILS * * * * * * * * * * * * * * * * * * * * * * * " ;
gotoxy ( 1 , 6 ) ;
cout < < " = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = " ;
gotoxy ( 1 , 7 ) ;
cout < < " CUST.NO " < < setw ( 10 ) < < " NAME " < < setw ( 15 ) < < " ADDRESS " < < setw ( 30 ) < < " PHONE NO " ;
gotoxy ( 1 , 8 ) ;
cout < < " * * * * * * * * * * * * * * * * * CUSTOMER DETAILS * * * * * * * * * * * * * * * * * * * * * * * " ;
}
系统将显示在餐厅管理系统中的所有顾客,上述代码将帮助打印或显示详细信息。
void modify_cust_record ( int n )
{
customer cust,temp ;
char tmpnm [ 50 ] , tmpaddress [ 50 ] ;
ifstream inFile ;
int fpos1 = -1 ;
inFile.open ( " customer.dat " , ios::binary ) ;
if ( !inFile )
{
cout < < " File could not be open !! Press any Key... " ;
getch ( ) ;
return ;
}
int flag = 0 ;
while ( inFile.read ( ( char * ) & cust , sizeof ( customer ) ) )
{
if ( cust.getcustid ( ) == n )
{ system ( " cls " ) ;
intromain ( ) ;
cust.showcustdatamulti ( ) ;
flag = 1 ;
}
}
inFile.close ( ) ;
if ( flag == 0 )
cout < < " \ n \ n record not exist " ;
else
{
// * * * * * * * modifying the records starts here
fstream File ;
File.open ( " customer.dat " , ios::binary | ios::in | ios::out ) ;
if ( !File )
{
cout < < " File could not be open !! Press any Key... " ;
getch ( ) ;
return ;
}
while ( File.read ( ( char * ) & cust , sizeof ( customer ) ) )
{
if ( cust.getcustid ( ) == n )
{ fpos1 = ( int ) File.tellg ( ) ;
break ;
}
如果管理员希望修改客户记录,如果记录文件中存在,则可以通过上述代码来完成,否则系统将报告错误,表示记录不存在。
void deletecust_record ( int n )
{
customer cust ;
ifstream inFile ;
inFile.open ( " customer.dat " , ios::binary ) ;
if ( !inFile )
{
cout < < " File could not be open !! Press any Key... " ;
getch ( ) ;
return ;
}
int flag = 0 ;
while ( inFile.read ( ( char * ) & cust , sizeof ( customer ) ) )
{
if ( cust.getcustid ( ) == n )
{ system ( " cls " ) ;
intromain ( ) ;
cust.showcustdatamulti ( ) ;
flag = 1 ;
}
}
inFile.close ( ) ;
char ch ;
if ( flag == 0 )
cout < < " \ n \ n record not exist " ;
else
{
// * * * * * * * deletion of the records starts from here
gotoxy ( 1 , 15 ) ;
cout<<" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * " ;
gotoxy ( 5 , 16 ) ;
cout < < " = = = = = = DO YOU WANT TO DELETE THE RECORDS GIVEN ABOVE[YES(Y) OR NO (N) = = = = = = = = " ;
gotoxy ( 2 , 17 ) ;
cin > > ch ;
if ( toupper ( ch ) == ' Y ' )
{
ofstream outFile ;
outFile.open ( " Temp2.dat " , ios::binary ) ;
ifstream objiff ( " customer.dat " , ios::binary ) ;
objiff.seekg ( 0 , ios::beg ) ;
while ( objiff.read ( ( char * ) & cust , sizeof ( customer ) ) )
{
if ( cust.getcustid ( ) != n )
{
outFile.write ( ( char * ) & cust , sizeof ( customer ) ) ;
}
}
outFile.close ( ) ;
objiff.close ( ) ;
remove ( " customer.dat " ) ;
rename ( " Temp2.dat " , " customer.dat " ) ;
againopenandclosecust ( ) ;
gotoxy ( 30 , 20 ) ;
cout < < " - - - - - - - - - - - - - - - - - - - - - - - - Record Deleted - - - - - - - - - - - - - - - - - - - - - - " ;
}
}
getch ( ) ;
}
//* * * * * * * * * * * * * * * * * * * delete record ends * * * * * * * * * * * * * * * * * *
如果管理员想从数据集中删除特定记录,则可以使用上面的代码。首先,要删除的记录将在记录文件中进行搜索,然后系统会弹出一个消息,询问是否要删除上述记录[是(Y)或否(N)],然后记录将被删除。
int searchcust ( int p )
{
customer cust ;
int tmprt = 0 ;
ifstream inFile ;
inFile.open ( " customer.dat " , ios::binary ) ;
if ( !inFile )
{
cout < < " File could not be open !! Press any Key... " ;
getch ( ) ;
return -1 ;
}
int flag = 0 ;
while ( inFile.read ( ( char * ) & cust , sizeof ( customer ) ) )
{
if ( cust.getcustid ( ) == p )
{ system ( " cls " ) ;
intromain ( ) ;
cust.showcustdatamulti ( ) ;
flag = 1 ;
tmprt = ( int ) inFile.tellg ( ) ;
break ;
}
}
inFile.close ( ) ;
if ( flag == 0 )
return 1 ;
//cout < < " \ n \ n record not exist " ;
else
{
return tmprt ;
}
}
如果管理员想要检查客户记录是否存在于客户记录文件中,则可以使用上述代码来完成。如果客户记录不存在于记录文件中,则系统会标记一条记录不存在的消息。
class product
{
int prodid ;
char name [ 50 ] ;
char company [ 50 ] ;
int qty ;
float price , dis ;
public :
product ( )
{
qty = 0 ;
price = 0 ;
dis = 0 ;
}
上述类是针对食堂中的产品。该产品菜单分为五个选择,可以在管理员模块中找到。创建产品,显示所有可用产品,搜索记录,修改产品和删除产品是前四个操作。
输出:
* * * * * * * * * * * * * * * * CANTEEN-MANAGEMENT* * * * * * * * * * * * * * * * *
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
* * * * * * * * * * * * * * * * * S = Y = S = T = E = M * * * * * * * * * * * * * * * * * *
PROJECT:
- - - - - - - - - - - - - - SCHOOL : STATE ENGINEERING UNIVERSITY - - - - - - - - - - - - - - -
* * * * * CANTEEN * * * * MANAGEMENT * * * * SYSTEM * * * * PROJECT * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
= = = = == = = = = MAIN MENU = = = = = = = = = = =
01. PRODUCTS REPORT GENERATOR
02. ADMINISTRATOR
03. EXIT
= = = = == = = = = = = = = = = = = = = = = = = = = = = =
Please Select Your Option (1-3)
= = = = = = = = = = = = = = = = = ADMIN MENU = = = = = = = = = = = = = = = = = = = =
1.CREATE PRODUCTS
2.DISPLAY ALL PRODUCTS AVAILABLE
3.SEARCH RECORD(QUERY)
4.MODIFY PRODUCTS
5.DELETE PRODUCTS
6.BACK TO MAIN MENU
Please Enter Your Choice (1-6) 1
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
PROD NO: 2 NAME OF PROD: Sandwich
COMPANY: Smith&Johns QUANTITY 10
PROD PRICE 45 DISCOUNT 5
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
* * * * * * * * * * * * * * * PRODUCTS RECORD SAVED * * * * * * * * * * * * * * *
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
PROD NO: 65 NAME OF PROD: Samosa
COMPANY: Canteen QUANTITY 14
PROD PRICE 10 DISCOUNT 0
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
PROD NO: 1 NAME OF PROD: Tea
COMPANY: Tata QUANTITY 30
PROD PRICE 15 DISCOUNT 0
* * * * * * * * * * * * * * * PRODUCTS RECORD SAVED * * * * * * * * * * * * * * *
**********************PRODUCTS DETAILS***************************
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
PROD.NO NAME COMPANY PRICE QUANTITY DISCOUNT
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
1 Sandwich Smith PHP0 0 0%
2 SandwichSmith&Johns PHP1.19209e-007 2573-1.08421e-019%
16704 PHP1.0842e-019 35849.10844e-044%
256 PHP1.58456e+029 76809.10844e-044%
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
PROD NO: 1 NAME OF PROD: Tea
COMPANY: Tata PROD PRICE: 15
DISCOUNT: 0% QUANTITY: 1
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =