This C++ application designed for managing canteens involves features such as searching for customers and products, displaying information, making modifications, and removing entries. Prior to order submission, the program conducts a search within the stored client data. It is tailored for small-scale canteens requiring efficient data management for a limited clientele and item range.
Furthermore, clients are provided with the option to make a purchase during this period. If the customer opts for yes, they will have the opportunity to enter the price for each individual item and, upon completing the process, generate invoices for the purchased items and secure their bought items from the collection point. The administrator will now be responsible for solely evaluating the final invoices and improving support for both fresh and existing customers.
Features of Canteen Management System in C++
- Customer's Menu: In the customer's menu, the administrator may add customer information, show all customers, search records, edit records, and remove records for customers.
- Product's Menu: There are five sections in the products menu that allow the administrator to add new products, view all of the products that are already available, search records in the database, edit product information, and remove products.
- Products Report Generator: The client enters the product number, followed by the amount of each item, and the program calculates the total with tax.
Program Breakdown
struct order
{
int prodid1 ;
char pname1 [ 50 ] ;
char compy1 [ 50 ] ;
int qty1 ;
float price1 , dis1 ;
} o1 [ 50 ] ;
The provided code snippet will serve as the blueprint for the item structure within the canteen management system. This structure will include fields such as product ID, product name, product manufacturer, and the price of the product.
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 ) ;
}
The specified built-in functions will be integrated into our university canteen management system. To alter a record, users can utilize the modifyrecord function to make changes within the system. Similarly, the deleterecord function enables users to remove an entry from the system.
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 ; };
You can navigate to the customers section through the administrator module, where you will find a menu with five distinct choices. The initial selection involves adding new customer information. Following that, the third option allows you to search for specific records using queries. The fourth choice permits you to make alterations to existing customer data, while the fifth option enables you to remove customer records. Lastly, the second option facilitates the display of all customer details.
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 < < " = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = " ;
}
The provided code will be utilized to showcase the information of the client that was input by the user. This will include details such as the customer's name, contact number, and address.
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 < < " = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = " ;
}
The user has the ability to modify previously entered data, including customer name, phone number, and address, using the provided code snippet.
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 ( ) ;
}
The modifications in the client information will be presented in a structured table format using the code provided above.
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 * * * * * * * * * * * * * * * * * * * * * * * " ;
}
The system will showcase all patrons within the cafeteria management system, while the aforementioned code will aid in printing or exhibiting the specifics.
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 ;
}
If the administrator wishes to update customer records that are present in the record file, they can do so using the provided code. Otherwise, the system will generate an error indicating that the record does not exist.
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 * * * * * * * * * * * * * * * * * *
If an administrator needs to remove a particular entry from the dataset, the following code can assist in accomplishing this task. Initially, the code will search for the specified record within the dataset file. Subsequently, a prompt will be triggered asking whether the user wishes to delete the identified record by confirming with either 'YES (Y)' or 'NO (N)'. Upon confirmation, the system will proceed to delete the record accordingly.
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 ;
}
}
If the administrator needs to verify the existence of a customer record within the customer record file, they can utilize the provided code. In cases where the customer record is not found in the file, the system will generate a notification indicating that the record does not exist.
class product
{
int prodid ;
char name [ 50 ] ;
char company [ 50 ] ;
int qty ;
float price , dis ;
public :
product ( )
{
qty = 0 ;
price = 0 ;
dis = 0 ;
}
The aforementioned class pertains to the items available in the cafeteria. Within the administrator module, you can locate the product menu categorized into five options. The initial four operations include generating products, showcasing all existing products, searching through records, updating products, and removing products.
Output:
* * * * * * * * * * * * * * * * 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
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =