Canteen Management System with C++

by | Jul 23, 2023 | Basic Coding, C/C++, Coding

Home » Coding » Canteen Management System with C++

In today’s busy world, managing canteens efficiently has become essential for schools, colleges, offices, and factories. Canteens play a vital role in providing meals and refreshments to people. To simplify and optimize this process, a Canteen Management System with C++ provides a practical solution. This computerized system streamlines tasks like menu planning, inventory control, and sales tracking, making canteen operations smoother and more organized.

Introduction

This canteen management system with C++ has the functionality for managing the canteen’s inventory and employee details. The login mechanism differentiates between owners and employees and provides access to their respective functionalities. This system also streamlines the process of reserving and confirming the food items.

We will learn how to write source code for the Canteen Management System with C++ and how to implement it through this project. The user can do various operations, such as order certain food items and modify the order.

Objectives

  • To order various food items conveniently
  • To manage the canteen menu by adding and deleting the available items
  • To keep employee records properly and safely
  • To lessen human error
  • To provide transparency to the system

Requirements

  • To run this project, you must have installed IDE for running and compiling the C++ source code.
  • Dev C++, Code Blocks, or VS code is recommended for a better experience.
  • Windows 10 operating system (or any latest version)

Source Code

#include<iostream>
#include<fstream>
#include<windows.h>
#include<dos.h>#include<iostream>
#include<fstream>
#include<windows.h>
#include<dos.h>
#include<stdio.h>
#include<cstdlib>
#include<string>
#include<conio.h>
using namespace std;
COORD coordinate={0,0};
void gotoxy(int x,int y)
{
coordinate.X=x;
coordinate.Y=y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coordinate);
}
class store_manage
{
public:


void store_var_page()
{
storepageandswitch();
}


int canteen_flag=0,number=0;
char canteen_index[5];
struct canteenmanage{
char ind[5],
item_id[5],
item_name[20],
cost[20],
quantity[20],
rating[5];
}can[20];
struct secind{
char item_name[20],
item_id[5],
ind[5];
}sec[20],found[20];
struct index{
char item_id[20],ind[20];
}in[20],temp;
void sort_index()
{
int i,j;
for(i=0;i<number-1;i++)
for(j=0;j<number-i-1;j++)
if(strcmp(in[j].item_id,in[j+1].item_id)>0)
{
temp =in[j];
in[j]=in[j+1];
in[j+1]=temp;
}
}
void sort_secind()
{
int i,j;
secind temp;
for(i=0;i<number-1;i++)
for(j=0;j<number-i-1;j++)
if(strcmp(sec[j].item_name,sec[j+1].item_name)>0)
{
temp =sec[j];
sec[j]=sec[j+1];
sec[j+1]=temp;
}
else if(strcmp(sec[j].item_name,sec[j+1].item_name)==0)
{
if(strcmp(sec[j].item_id,sec[j+1].item_id)>0)
{
temp =sec[j];
sec[j]=sec[j+1];
sec[j+1]=temp;
}
}
}
void ret_rec(char *ind)
{
int flag=0;
for(int i=0;i<number;i++)
{
if(strcmp(can[i].ind,ind)==0)
{
strcpy(canteen_index,ind);
canteen_flag=1;
cout<<"Your Item is found\n";
cout<<can[i].item_id<<"|"<<can[i].item_name<<"|"<<can[i].cost<<"|"<<can[i].quantity<<"|"<<can[i].rating<<"\n";
flag=1;
}
}
if(!flag)
{
cout<<"sorry the Item search has been failed\n";
}
}
void search_index(char *item_id)
{
int flag=0;
for(int i=0;i<number;i++)
{
if(strcmp(in[i].item_id,item_id)==0)
{
ret_rec(in[i].ind);
flag=1;
}
}
if(!flag)
{
cout<<"sorry Index search has been failed\n";
}
}
void search(char *it_name)
{
char it_id[20];
int flag1=0;
int k=0,i;
for(i=0;i<number;i++)
{
if(strcmp(sec[i].item_name,it_name)==0)
{
strcpy(found[k].item_id,sec[i].item_id);
strcpy(found[k].item_name,sec[i].item_name);
strcpy(found[k].ind,sec[i].ind);
flag1=1;
k++;
}
}
if(!flag1)
{
cout<<"second index search has been failed\n";
return;
}
cout<<"\n The records which are matched are:";
for(i=0;i<k;i++)
cout<<"\n"<<found[i].item_name<<" "<<found[i].item_id;
cout<<"\n Please select an Item ID ";
cin>>it_id;
flag1=0;
for(i=0;i<k;i++)
if(strcmp(found[i].item_id,it_id)==0)
{
search_index(it_id);
flag1=1;
}
if(!flag1)
{
cout<<"Wrong item ID entered search has been failed\n";
}
}
int search_item(char *it_id,int j)
{
int flag=0;
for(int i=0;i<j;i++)
{
if(strcmp(can[i].item_id,it_id)==0)
{
flag=1;
break;
}
}
if(flag)
return 1;
else
return -1;
}
void del(char *it_name)
{
canteen_flag=0;
int fr=0;
search(it_name);
if(!canteen_flag)
{
cout<<"Sorry Deletion has failed\n";
return;
}
for(int i=0;i<number;i++)
{
if(strcmp(can[i].ind,canteen_index)==0)
{
fr=i;
break;
}
}
for(int i=fr;i<number-1;i++)
{
can[i]=can[i+1];
char str[3];
sprintf(str,"%d",i);
strcpy(can[i].ind,str);
}
number--;


fstream f1,f2,f3;
f1.open("canteen1.txt",ios::out);
f2.open("index.txt",ios::out);
f3.open("secind.txt",ios::out);
for(int i=0;i<number;i++)
{
strcpy(sec[i].item_name,can[i].item_name);
strcpy(sec[i].item_id,can[i].item_id);
strcpy(in[i].item_id,can[i].item_id);
strcpy(sec[i].ind,can[i].ind);
strcpy(in[i].ind,can[i].ind);
}
sort_index();
sort_secind();
for(int i=0;i<number;i++)
{
f1<<can[i].ind<<"|"<<can[i].item_id<<"|"<<can[i].item_name<<"|"<<can[i].cost<<"|"<<can[i].quantity<<"|"<<can[i].rating<<"\n";
f2<<in[i].item_id<<"|"<<in[i].ind<<"\n";
f3<<sec[i].item_name<<"|"<<sec[i].item_id<<"|"<<sec[i].ind<<"\n";
}
f1.close();
f2.close();
f3.close();
cout<<"your deletion has been successful";
}


void orderfood()
{
system("CLS");
gotoxy(40,1);cout<<"\nROSE CANTEEN";
gotoxy(40,2);
int choice,i,flag1,flag;
fstream file1,file2,file3;
char ind[5],
it_id[20],
it_name[20],
item_id[5],
item_name[20],
cost[20],
quantity[20],
rating[5];
file3.open("index.txt",ios::out);
file1.open("canteen1.txt",ios::app|ios::out);
file2.open("secind.txt",ios::out);
if(!file1)
{
cout<<"Sorry your file could not be added";
exit(0);
}
int n;
cout<<"\nEnter the total number of food items\n";
cin>>n;
for(int i=number;i<number+n;i++)
{
label: cout<<"\n Please Enter "<<i+1<<" the name of the item:\n";
cout<<"Please Enter the Item's id:"; cin>>can[i].item_id;
cout<<"Please Enter the name of the Item:"; cin>>can[i].item_name;
cout<<"Please Enter Cost of the item :"; cin>>can[i].cost;
cout<<"Please Enter Quantity of item:"; cin>>can[i].quantity;
cout<<"Please Enter rating of the item:"; cin>>can[i].rating;
int q=search_item(can[i].item_id,i);
if(q==1)
{
cout<<"This is a duplicate entry,Please Enter again\n";
goto label;
}
file1<<i<<"|"<<can[i].item_id<<"|"<<can[i].item_name<<"|"<<can[i].cost<<"|"<<can[i].quantity<<"|"<<can[i].rating<<"\n";
}
file1.close();
number=number+n;
file1.open("canteen1.txt",ios::in);
for(int i=0;i<number;i++)
{
file1.getline(ind,5,'|');
file1.getline(item_id,5,'|');
file1.getline(item_name,20,'|');
file1.getline(cost,20,'|');
file1.getline(quantity,20,'|');
file1.getline(rating,5,'\n');
strcpy(can[i].ind,ind);
strcpy(sec[i].ind,ind);
strcpy(in[i].ind,ind);
strcpy(sec[i].item_name,item_name);
strcpy(sec[i].item_id,item_id);
strcpy(in[i].item_id,item_id);
}
sort_index();
sort_secind();
cout<<"\n Secondary index has been sorted the components are:\n";
for(i=0;i<number;i++)
cout<<sec[i].item_name<<" "<<sec[i].item_id<<" "<<sec[i].ind<<endl;
cout<<"\nThe index has been sorted its components are:\n";
for(i=0;i<number;i++)
cout<<in[i].item_id<<" "<<in[i].ind<<endl;
for(int i=0;i<number;i++)
file2<<sec[i].item_name<<"|"<<sec[i].item_id<<"|"<<sec[i].ind<<"\n";
for(int i=0;i<number;i++)
file3<<in[i].item_id<<"|"<<in[i].ind<<"\n";


file1.close();
file2.close();
file3.close();
cout<<endl<<" Enter any key to procced in the system";
cout<<" ";getch();
store_var_page();
}


void bill()
{
system("CLS");
gotoxy(40,1);cout<<"ROSE CANTEEN";
gotoxy(40,2);
int choice,i,flag1,flag;
fstream file1,file2,file3;
char ind[5],
it_id[20],
it_name[20],
item_id[5],
item_name[20],
cost[20],
quantity[20],
rating[5];
fstream f1;
f1.open("canteen1.txt",ios::in);
if(!f1)
{
cout<<"File not found";
exit(0);
}
cout<<"\nID NAME COST QUANTITY RATINGS\t\n\n";
i=0;
while(i!=number)
{
f1.getline(ind,5,'|');
f1.getline(item_id,5,'|');
f1.getline(item_name,20,'|');
f1.getline(cost,20,'|');
f1.getline(quantity,20,'|');
f1.getline(rating,5,'\n');
cout<<"\n"<<item_id<<"\t"<<item_name<<"\t\t"<<cost<<"\t"<<quantity<<"\t"<<rating<<"\t\n";
i++;
}
int totalcost=0;
cout<<"\nThe total number of food items that have been ordered are :"<<i<<"\n";
for(int f=i-1;f<0;f--)
{
totalcost=totalcost+ (cost[f]*quantity[f]);
cout<<totalcost;
}
cout<<"\nPlease make a payment of Rs.70"<<totalcost<<endl;
cout<<" THANK YOU \n";


f1.close();
cout<<endl<<" Enter any key to proceed.....";
cout<<" ";getch();
store_var_page();
}


void foodsearch()
{
system("CLS");
gotoxy(40,1);cout<<"ROSE CANTEEN\n";
gotoxy(40,2);
char it_name[20];
cout<<"\nEnter Item name to be searched\n";
cin>>it_name;
search(it_name);
cout<<endl<<" Enter any key to proceed.....";
cout<<" ";getch();
store_var_page();
}
void deletefood()
{
system("CLS");
gotoxy(40,1);cout<<"ROSE CANTEEN";
gotoxy(40,2);
char it_name[20];
cout<<"\nEnter the Item name to be deleted\n";
cin>>it_name;
del(it_name);
cout<<endl<<" Enter any key to proceed.....";
cout<<" ";getch();
store_var_page();
}


storepageandswitch()
{
system("CLS");
gotoxy(40,1);cout<<"ROSE CANTEEN";
gotoxy(40,2);cout<<"-----------------"<<endl<<endl;
int choice;
cout<<"\n\nROSE CANTEEN SERVICES\n";
cout<<"\n Press 1 to Order Food\nPress 2 to Search Item\nPress 3 to Delete Item\nPress 4 to Generate Bill\nPress 5 to Exit\n";
cout<<"Enter your desired choice\n";
cin>>choice;
switch(choice)
{
case 1:
orderfood();
break;
storepageandswitch();
case 2:{
foodsearch();
break;


}
case 3:{
deletefood();
break;
}
case 4:{
bill();
break;
}
case 5:{
cout<<"ROSE CANTEEN \n";
cout<<"Thank You!! Please visit again\n";
break;
}
default:
cout<<"Sorry !!!Invalid Choice\n";
cout<<" ENTER YOUR DESIRED CHOICE"<<endl;
cout<<" ";cin>>choice;
break;
}
}
};
class employee
{
public:
int ch,age;
char name[50];
long int sal;
void addemp();
void displayemp();
void removeemp();
void editemp();
void emppageswitch();
void emppage()
{
system("CLS");
gotoxy(40,1);cout<<"ROSE CANTEEN";
gotoxy(40,2);cout<<"-----------------"<<endl<<endl;
cout<<" Press 1 to DISPLAY ALL THE DETAILS OF AN EMPLOYEE"<<endl;
cout<<" Press 2 to ADD DETAILS OF NEW EMPLOYEES "<<endl;
cout<<" Press 3 to REMOVE THE DETAILS OF EMPLOYEES"<<endl;
cout<<" Press 4 to EXIT FROM THE SYSTEM"<<endl<<endl;
cout<<" ENTER YOUR REQUIRED CHOICE"<<endl;
cout<<" ";cin>>ch;
emppageswitch();
}
};
void employee::emppageswitch()
{
while(ch!=1||ch!=2||ch!=3||ch!=4)
{
switch(ch)
{
case 1:
displayemp();
break;
case 2:
addemp();
break;
case 3:
removeemp();
break;
case 4:
exit(0);
break;
default:
cout<<endl<<" SORRY!!INVALID CHOICE"<<endl;
cout<<" ENTER YOUR CHOICE AGAIN "<<endl;
cout<<" ";cin>>ch;
break;
}
}
}
void employee::addemp()
{
system("CLS");
gotoxy(40,1);cout<<"ROSE CANTEEN";
gotoxy(40,2);cout<<"-----------------"<<endl<<endl;
ofstream newemployee("EMPLOYEE.txt",ios::app);
cout<<" PLEASE ENTER THE NAME OF EMPLOYEE"<<endl;
cout<<" ";cin>>name;
cin.sync();
cout<<" ENTER EMPLOYEE's AGE"<<endl;
cout<<" ";cin>>age;
cout<<" ENTER EMPLOYEE's SALARY"<<endl;
cout<<" ";cin>>sal;
newemployee<<name<<' '<<age<<' '<<sal<<endl;
newemployee.close();
cout<<endl<<" THE EMPLOYEE HAS BEEN ADDED SUCCESSFULLY"<<endl;
cout<<endl<<" Press any other key to continue......";
cout<<" ";getch();
emppage();
}
void employee::displayemp()
{
system("CLS");
gotoxy(40,1);cout<<"ROSE CANTEEN";
gotoxy(40,2);cout<<"-----------------"<<endl<<endl;
ifstream employee("EMPLOYEE.txt");
cout<<" EMPLOYEE ---- AGE ---- SALARY"<<endl;
cout<<" -----------------------"<<endl;
while (employee>>name>>age>>sal)
{
cout<<" "<<name<<" -- "<<age<<" -- "<<sal<<endl ;
}
employee.close();
cout<<endl<<" Press any other key to continue......"<<endl;
cout<<" ";getch();
emppage();
}
void employee::removeemp()
{
system("CLS");
gotoxy(40,1);cout<<"ROSE CANTEEN";
gotoxy(40,2);cout<<"-----------------"<<endl<<endl;
char tname[50];
ifstream emp1("EMPLOYEE.txt");
ofstream emp2("temp.txt");
cout<<" ENTER THE EMPLOYEE's NAME THAT YOU WISH TO REMOVE"<<endl;
cout<<" ";cin>>tname;
while(emp1>>name>>age>>sal)
{
if(strcmp(name,tname)!=0)
{
emp2<<name<<' '<<age<<' '<<sal<<endl;
}
}
emp1.close();
emp2.close();
remove("EMPLOYEE.txt");
rename("temp.txt","EMPLOYEE.txt");
cout<<endl<<" THE EMPLOYEE HAS BEEN REMOVED SUCCESSFULLY"<<endl;
cout<<endl<<" Press any other key to continue......"<<endl;
cout<<" ";
getch();
emppage();
}
class login
{
public:
string pass="";
int ch;
char c;
void loginpageswitch();
void homepageswitch();
void employeelogin();
void ownerlogin();
void emp();
void own();
void homepage()
{
system("CLS");
gotoxy(40,1);cout<<"WELCOME TO ROSE CANTEEN";
gotoxy(40,2);cout<<"----------------------------"<<endl<<endl;
cout<<" PRESS 1 to LOGIN into the system"<<endl;
cout<<" PRESS 2 to EXIT from the system"<<endl<<endl;
cout<<" ENTER YOUR DESIRED CHOICE"<<endl;
cout<<" ";cin>>ch;
homepageswitch();
}
void loginpage()
{
loginpage:;
system("CLS");
gotoxy(40,1);cout<<"ROSE CANTEEN";
gotoxy(40,2);cout<<"-----------------"<<endl<<endl;
cout<<" PRESS 1 to LOGIN as the OWNER"<<endl;
cout<<" PRESS 2 to LOGIN as the EMPLOYEE"<<endl;
cout<<" PRESS 3 to EXIT from the system"<<endl<<endl;
cout<<" ENTER YOUR DESIRED CHOICE"<<endl;
cout<<" ";cin>>ch;
loginpageswitch();
}
};
void login::homepageswitch()
{
while(ch!=1||ch!=2)
{
switch(ch)
{
case 1:
loginpage();
break;
case 2:
exit(0);
break;
default:
cout<<endl<<" SORRY!! INVALID CHOICE"<<endl;
cout<<" Press any other key to continue......"<<endl;
cout<<" ";cin>>ch;
}
}
}
void login::loginpageswitch()
{
while(ch!=1||ch!=2||ch!=3)
{
switch(ch)
{
case 1:
ownerlogin();
break;
case 2:
employeelogin();
break;
case 3:
exit(0);
break;
default:
cout<<endl<<" SORRY!! INVALID CHOICE"<<endl;
cout<<" ENTER YOUR DESIRED CHOICE"<<endl;
cout<<" ";cin>>ch;
}
}
}
void login::ownerlogin()
{
while(pass!="OWN")
{
pass="";
cout<<endl<<" ENTER PASSWORD TO LOGIN AS OWNER"<<endl;
cout<<" ";c=_getch();
while(c!=13)
{
pass.push_back(c);
cout<<"*";
c=getch();
}
if(pass=="OWN")
{
cout<<endl<<" OWNER ACCESS IS GRANTED"<<endl;
cout<<endl<<" Press any other key to continue......"<<endl;
cout<<" ";getch();
own();
}
else
{
cout<<endl<<" THE ENTERED PASSWORD IS INVALID "<<endl;
}
}
}
void login::employeelogin()
{
while(pass!="EMP")
{
pass="";
cout<<" ENTER PASSWORD TO LOGIN AS EMPLOYEE"<<endl;
cout<<" ";c=_getch();
while(c!=13)
{
pass.push_back(c);
cout<<"*";
c=getch();
}
if(pass=="EMP")
{
cout<<endl<<" EMPLOYEE ACCESS IS GRANTED"<<endl;
cout<<endl<<" Press any other key to continue......"<<endl;
cout<<" ";getch();
emp();
}
else
{
cout<<endl<<" SORRY!!! INVALID PASSWORD"<<endl;
}
}
}
void login::emp()
{
store_manage s;
s.store_var_page();
}
void login::own()
{
employee e;
e.emppage();
}
void empjump()
{
employee e;
e.emppage();
}
int main()
{
system("-------- CANTEEN MANAGEMENT SYSTEM--------");
system("color 75");
login l;
l.homepage();
return 0;
}
#include<stdio.h>
#include<cstdlib>
#include<string>
#include<conio.h>
using namespace std;
COORD coordinate={0,0};
void gotoxy(int x,int y)
{
coordinate.X=x;
coordinate.Y=y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coordinate);
}
class store_manage
{
public:


void store_var_page()
{
storepageandswitch();
}


int canteen_flag=0,number=0;
char canteen_index[5];
struct canteenmanage{
char ind[5],
item_id[5],
item_name[20],
cost[20],
quantity[20],
rating[5];
}can[20];
struct secind{
char item_name[20],
item_id[5],
ind[5];
}sec[20],found[20];
struct index{
char item_id[20],ind[20];
}in[20],temp;
void sort_index()
{
int i,j;
for(i=0;i<number-1;i++)
for(j=0;j<number-i-1;j++)
if(strcmp(in[j].item_id,in[j+1].item_id)>0)
{
temp =in[j];
in[j]=in[j+1];
in[j+1]=temp;
}
}
void sort_secind()
{
int i,j;
secind temp;
for(i=0;i<number-1;i++)
for(j=0;j<number-i-1;j++)
if(strcmp(sec[j].item_name,sec[j+1].item_name)>0)
{
temp =sec[j];
sec[j]=sec[j+1];
sec[j+1]=temp;
}
else if(strcmp(sec[j].item_name,sec[j+1].item_name)==0)
{
if(strcmp(sec[j].item_id,sec[j+1].item_id)>0)
{
temp =sec[j];
sec[j]=sec[j+1];
sec[j+1]=temp;
}
}
}
void ret_rec(char *ind)
{
int flag=0;
for(int i=0;i<number;i++)
{
if(strcmp(can[i].ind,ind)==0)
{
strcpy(canteen_index,ind);
canteen_flag=1;
cout<<"Your Item is found\n";
cout<<can[i].item_id<<"|"<<can[i].item_name<<"|"<<can[i].cost<<"|"<<can[i].quantity<<"|"<<can[i].rating<<"\n";
flag=1;
}
}
if(!flag)
{
cout<<"sorry the Item search has been failed\n";
}
}
void search_index(char *item_id)
{
int flag=0;
for(int i=0;i<number;i++)
{
if(strcmp(in[i].item_id,item_id)==0)
{
ret_rec(in[i].ind);
flag=1;
}
}
if(!flag)
{
cout<<"sorry Index search has been failed\n";
}
}
void search(char *it_name)
{
char it_id[20];
int flag1=0;
int k=0,i;
for(i=0;i<number;i++)
{
if(strcmp(sec[i].item_name,it_name)==0)
{
strcpy(found[k].item_id,sec[i].item_id);
strcpy(found[k].item_name,sec[i].item_name);
strcpy(found[k].ind,sec[i].ind);
flag1=1;
k++;
}
}
if(!flag1)
{
cout<<"second index search has been failed\n";
return;
}
cout<<"\n The records which are matched are:";
for(i=0;i<k;i++)
cout<<"\n"<<found[i].item_name<<" "<<found[i].item_id;
cout<<"\n Please select an Item ID ";
cin>>it_id;
flag1=0;
for(i=0;i<k;i++)
if(strcmp(found[i].item_id,it_id)==0)
{
search_index(it_id);
flag1=1;
}
if(!flag1)
{
cout<<"Wrong item ID entered search has been failed\n";
}
}
int search_item(char *it_id,int j)
{
int flag=0;
for(int i=0;i<j;i++)
{
if(strcmp(can[i].item_id,it_id)==0)
{
flag=1;
break;
}
}
if(flag)
return 1;
else
return -1;
}
void del(char *it_name)
{
canteen_flag=0;
int fr=0;
search(it_name);
if(!canteen_flag)
{
cout<<"Sorry Deletion has failed\n";
return;
}
for(int i=0;i<number;i++)
{
if(strcmp(can[i].ind,canteen_index)==0)
{
fr=i;
break;
}
}
for(int i=fr;i<number-1;i++)
{
can[i]=can[i+1];
char str[3];
sprintf(str,"%d",i);
strcpy(can[i].ind,str);
}
number--;


fstream f1,f2,f3;
f1.open("canteen1.txt",ios::out);
f2.open("index.txt",ios::out);
f3.open("secind.txt",ios::out);
for(int i=0;i<number;i++)
{
strcpy(sec[i].item_name,can[i].item_name);
strcpy(sec[i].item_id,can[i].item_id);
strcpy(in[i].item_id,can[i].item_id);
strcpy(sec[i].ind,can[i].ind);
strcpy(in[i].ind,can[i].ind);
}
sort_index();
sort_secind();
for(int i=0;i<number;i++)
{
f1<<can[i].ind<<"|"<<can[i].item_id<<"|"<<can[i].item_name<<"|"<<can[i].cost<<"|"<<can[i].quantity<<"|"<<can[i].rating<<"\n";
f2<<in[i].item_id<<"|"<<in[i].ind<<"\n";
f3<<sec[i].item_name<<"|"<<sec[i].item_id<<"|"<<sec[i].ind<<"\n";
}
f1.close();
f2.close();
f3.close();
cout<<"your deletion has been successful";
}


void orderfood()
{
system("CLS");
gotoxy(40,1);cout<<"\nROSE CANTEEN";
gotoxy(40,2);
int choice,i,flag1,flag;
fstream file1,file2,file3;
char ind[5],
it_id[20],
it_name[20],
item_id[5],
item_name[20],
cost[20],
quantity[20],
rating[5];
file3.open("index.txt",ios::out);
file1.open("canteen1.txt",ios::app|ios::out);
file2.open("secind.txt",ios::out);
if(!file1)
{
cout<<"Sorry your file could not be added";
exit(0);
}
int n;
cout<<"\nEnter the total number of food items\n";
cin>>n;
for(int i=number;i<number+n;i++)
{
label: cout<<"\n Please Enter "<<i+1<<" the name of the item:\n";
cout<<"Please Enter the Item's id:"; cin>>can[i].item_id;
cout<<"Please Enter the name of the Item:"; cin>>can[i].item_name;
cout<<"Please Enter Cost of the item :"; cin>>can[i].cost;
cout<<"Please Enter Quantity of item:"; cin>>can[i].quantity;
cout<<"Please Enter rating of the item:"; cin>>can[i].rating;
int q=search_item(can[i].item_id,i);
if(q==1)
{
cout<<"This is a duplicate entry,Please Enter again\n";
goto label;
}
file1<<i<<"|"<<can[i].item_id<<"|"<<can[i].item_name<<"|"<<can[i].cost<<"|"<<can[i].quantity<<"|"<<can[i].rating<<"\n";
}
file1.close();
number=number+n;
file1.open("canteen1.txt",ios::in);
for(int i=0;i<number;i++)
{
file1.getline(ind,5,'|');
file1.getline(item_id,5,'|');
file1.getline(item_name,20,'|');
file1.getline(cost,20,'|');
file1.getline(quantity,20,'|');
file1.getline(rating,5,'\n');
strcpy(can[i].ind,ind);
strcpy(sec[i].ind,ind);
strcpy(in[i].ind,ind);
strcpy(sec[i].item_name,item_name);
strcpy(sec[i].item_id,item_id);
strcpy(in[i].item_id,item_id);
}
sort_index();
sort_secind();
cout<<"\n Secondary index has been sorted the components are:\n";
for(i=0;i<number;i++)
cout<<sec[i].item_name<<" "<<sec[i].item_id<<" "<<sec[i].ind<<endl;
cout<<"\nThe index has been sorted its components are:\n";
for(i=0;i<number;i++)
cout<<in[i].item_id<<" "<<in[i].ind<<endl;
for(int i=0;i<number;i++)
file2<<sec[i].item_name<<"|"<<sec[i].item_id<<"|"<<sec[i].ind<<"\n";
for(int i=0;i<number;i++)
file3<<in[i].item_id<<"|"<<in[i].ind<<"\n";


file1.close();
file2.close();
file3.close();
cout<<endl<<" Enter any key to procced in the system";
cout<<" ";getch();
store_var_page();
}


void bill()
{
system("CLS");
gotoxy(40,1);cout<<"ROSE CANTEEN";
gotoxy(40,2);
int choice,i,flag1,flag;
fstream file1,file2,file3;
char ind[5],
it_id[20],
it_name[20],
item_id[5],
item_name[20],
cost[20],
quantity[20],
rating[5];
fstream f1;
f1.open("canteen1.txt",ios::in);
if(!f1)
{
cout<<"File not found";
exit(0);
}
cout<<"\nID NAME COST QUANTITY RATINGS\t\n\n";
i=0;
while(i!=number)
{
f1.getline(ind,5,'|');
f1.getline(item_id,5,'|');
f1.getline(item_name,20,'|');
f1.getline(cost,20,'|');
f1.getline(quantity,20,'|');
f1.getline(rating,5,'\n');
cout<<"\n"<<item_id<<"\t"<<item_name<<"\t\t"<<cost<<"\t"<<quantity<<"\t"<<rating<<"\t\n";
i++;
}
int totalcost=0;
cout<<"\nThe total number of food items that have been ordered are :"<<i<<"\n";
for(int f=i-1;f<0;f--)
{
totalcost=totalcost+ (cost[f]*quantity[f]);
cout<<totalcost;
}
cout<<"\nPlease make a payment of Rs.70"<<totalcost<<endl;
cout<<" THANK YOU \n";


f1.close();
cout<<endl<<" Enter any key to proceed.....";
cout<<" ";getch();
store_var_page();
}


void foodsearch()
{
system("CLS");
gotoxy(40,1);cout<<"ROSE CANTEEN\n";
gotoxy(40,2);
char it_name[20];
cout<<"\nEnter Item name to be searched\n";
cin>>it_name;
search(it_name);
cout<<endl<<" Enter any key to proceed.....";
cout<<" ";getch();
store_var_page();
}
void deletefood()
{
system("CLS");
gotoxy(40,1);cout<<"ROSE CANTEEN";
gotoxy(40,2);
char it_name[20];
cout<<"\nEnter the Item name to be deleted\n";
cin>>it_name;
del(it_name);
cout<<endl<<" Enter any key to proceed.....";
cout<<" ";getch();
store_var_page();
}


storepageandswitch()
{
system("CLS");
gotoxy(40,1);cout<<"ROSE CANTEEN";
gotoxy(40,2);cout<<"-----------------"<<endl<<endl;
int choice;
cout<<"\n\nROSE CANTEEN SERVICES\n";
cout<<"\n Press 1 to Order Food\nPress 2 to Search Item\nPress 3 to Delete Item\nPress 4 to Generate Bill\nPress 5 to Exit\n";
cout<<"Enter your desired choice\n";
cin>>choice;
switch(choice)
{
case 1:
orderfood();
break;
storepageandswitch();
case 2:{
foodsearch();
break;


}
case 3:{
deletefood();
break;
}
case 4:{
bill();
break;
}
case 5:{
cout<<"ROSE CANTEEN \n";
cout<<"Thank You!! Please visit again\n";
break;
}
default:
cout<<"Sorry !!!Invalid Choice\n";
cout<<" ENTER YOUR DESIRED CHOICE"<<endl;
cout<<" ";cin>>choice;
break;
}
}
};
class employee
{
public:
int ch,age;
char name[50];
long int sal;
void addemp();
void displayemp();
void removeemp();
void editemp();
void emppageswitch();
void emppage()
{
system("CLS");
gotoxy(40,1);cout<<"ROSE CANTEEN";
gotoxy(40,2);cout<<"-----------------"<<endl<<endl;
cout<<" Press 1 to DISPLAY ALL THE DETAILS OF AN EMPLOYEE"<<endl;
cout<<" Press 2 to ADD DETAILS OF NEW EMPLOYEES "<<endl;
cout<<" Press 3 to REMOVE THE DETAILS OF EMPLOYEES"<<endl;
cout<<" Press 4 to EXIT FROM THE SYSTEM"<<endl<<endl;
cout<<" ENTER YOUR REQUIRED CHOICE"<<endl;
cout<<" ";cin>>ch;
emppageswitch();
}
};
void employee::emppageswitch()
{
while(ch!=1||ch!=2||ch!=3||ch!=4)
{
switch(ch)
{
case 1:
displayemp();
break;
case 2:
addemp();
break;
case 3:
removeemp();
break;
case 4:
exit(0);
break;
default:
cout<<endl<<" SORRY!!INVALID CHOICE"<<endl;
cout<<" ENTER YOUR CHOICE AGAIN "<<endl;
cout<<" ";cin>>ch;
break;
}
}
}
void employee::addemp()
{
system("CLS");
gotoxy(40,1);cout<<"ROSE CANTEEN";
gotoxy(40,2);cout<<"-----------------"<<endl<<endl;
ofstream newemployee("EMPLOYEE.txt",ios::app);
cout<<" PLEASE ENTER THE NAME OF EMPLOYEE"<<endl;
cout<<" ";cin>>name;
cin.sync();
cout<<" ENTER EMPLOYEE's AGE"<<endl;
cout<<" ";cin>>age;
cout<<" ENTER EMPLOYEE's SALARY"<<endl;
cout<<" ";cin>>sal;
newemployee<<name<<' '<<age<<' '<<sal<<endl;
newemployee.close();
cout<<endl<<" THE EMPLOYEE HAS BEEN ADDED SUCCESSFULLY"<<endl;
cout<<endl<<" Press any other key to continue......";
cout<<" ";getch();
emppage();
}
void employee::displayemp()
{
system("CLS");
gotoxy(40,1);cout<<"ROSE CANTEEN";
gotoxy(40,2);cout<<"-----------------"<<endl<<endl;
ifstream employee("EMPLOYEE.txt");
cout<<" EMPLOYEE ---- AGE ---- SALARY"<<endl;
cout<<" -----------------------"<<endl;
while (employee>>name>>age>>sal)
{
cout<<" "<<name<<" -- "<<age<<" -- "<<sal<<endl ;
}
employee.close();
cout<<endl<<" Press any other key to continue......"<<endl;
cout<<" ";getch();
emppage();
}
void employee::removeemp()
{
system("CLS");
gotoxy(40,1);cout<<"ROSE CANTEEN";
gotoxy(40,2);cout<<"-----------------"<<endl<<endl;
char tname[50];
ifstream emp1("EMPLOYEE.txt");
ofstream emp2("temp.txt");
cout<<" ENTER THE EMPLOYEE's NAME THAT YOU WISH TO REMOVE"<<endl;
cout<<" ";cin>>tname;
while(emp1>>name>>age>>sal)
{
if(strcmp(name,tname)!=0)
{
emp2<<name<<' '<<age<<' '<<sal<<endl;
}
}
emp1.close();
emp2.close();
remove("EMPLOYEE.txt");
rename("temp.txt","EMPLOYEE.txt");
cout<<endl<<" THE EMPLOYEE HAS BEEN REMOVED SUCCESSFULLY"<<endl;
cout<<endl<<" Press any other key to continue......"<<endl;
cout<<" ";
getch();
emppage();
}
class login
{
public:
string pass="";
int ch;
char c;
void loginpageswitch();
void homepageswitch();
void employeelogin();
void ownerlogin();
void emp();
void own();
void homepage()
{
system("CLS");
gotoxy(40,1);cout<<"WELCOME TO ROSE CANTEEN";
gotoxy(40,2);cout<<"----------------------------"<<endl<<endl;
cout<<" PRESS 1 to LOGIN into the system"<<endl;
cout<<" PRESS 2 to EXIT from the system"<<endl<<endl;
cout<<" ENTER YOUR DESIRED CHOICE"<<endl;
cout<<" ";cin>>ch;
homepageswitch();
}
void loginpage()
{
loginpage:;
system("CLS");
gotoxy(40,1);cout<<"ROSE CANTEEN";
gotoxy(40,2);cout<<"-----------------"<<endl<<endl;
cout<<" PRESS 1 to LOGIN as the OWNER"<<endl;
cout<<" PRESS 2 to LOGIN as the EMPLOYEE"<<endl;
cout<<" PRESS 3 to EXIT from the system"<<endl<<endl;
cout<<" ENTER YOUR DESIRED CHOICE"<<endl;
cout<<" ";cin>>ch;
loginpageswitch();
}
};
void login::homepageswitch()
{
while(ch!=1||ch!=2)
{
switch(ch)
{
case 1:
loginpage();
break;
case 2:
exit(0);
break;
default:
cout<<endl<<" SORRY!! INVALID CHOICE"<<endl;
cout<<" Press any other key to continue......"<<endl;
cout<<" ";cin>>ch;
}
}
}
void login::loginpageswitch()
{
while(ch!=1||ch!=2||ch!=3)
{
switch(ch)
{
case 1:
ownerlogin();
break;
case 2:
employeelogin();
break;
case 3:
exit(0);
break;
default:
cout<<endl<<" SORRY!! INVALID CHOICE"<<endl;
cout<<" ENTER YOUR DESIRED CHOICE"<<endl;
cout<<" ";cin>>ch;
}
}
}
void login::ownerlogin()
{
while(pass!="OWN")
{
pass="";
cout<<endl<<" ENTER PASSWORD TO LOGIN AS OWNER"<<endl;
cout<<" ";c=_getch();
while(c!=13)
{
pass.push_back(c);
cout<<"*";
c=getch();
}
if(pass=="OWN")
{
cout<<endl<<" OWNER ACCESS IS GRANTED"<<endl;
cout<<endl<<" Press any other key to continue......"<<endl;
cout<<" ";getch();
own();
}
else
{
cout<<endl<<" THE ENTERED PASSWORD IS INVALID "<<endl;
}
}
}
void login::employeelogin()
{
while(pass!="EMP")
{
pass="";
cout<<" ENTER PASSWORD TO LOGIN AS EMPLOYEE"<<endl;
cout<<" ";c=_getch();
while(c!=13)
{
pass.push_back(c);
cout<<"*";
c=getch();
}
if(pass=="EMP")
{
cout<<endl<<" EMPLOYEE ACCESS IS GRANTED"<<endl;
cout<<endl<<" Press any other key to continue......"<<endl;
cout<<" ";getch();
emp();
}
else
{
cout<<endl<<" SORRY!!! INVALID PASSWORD"<<endl;
}
}
}
void login::emp()
{
store_manage s;
s.store_var_page();
}
void login::own()
{
employee e;
e.emppage();
}
void empjump()
{
employee e;
e.emppage();
}
int main()
{
system("-------- CANTEEN MANAGEMENT SYSTEM--------");
system("color 75");
login l;
l.homepage();
return 0;
}

Explanation of the Code:

Let’s go through the code step by step and explain what each function is doing:

1. gotoxy(int x, int y): This function is used to move the cursor to the specified position (x, y) on the console screen. It is used to create a basic text-based user interface by positioning the output at specific coordinates.

2. class store_manage: This is a class that contains functions related to managing the canteen’s inventory. It has functions for ordering food, searching for food items, deleting food items, generating a bill, and displaying the canteen’s inventory.

3. class employee: This is another class that contains functions related to managing employees. It has functions for adding new employees, displaying employee details, and removing employees.

4. void login::own(): This function is a part of the login class and is used to provide access to the owner of the canteen. It asks the user to enter a password, and if the correct password is entered (in this case, “OWN”), the owner can access the employee management functionalities.

5. void login::emp(): This function is a part of the login class and is used to provide access to the employees of the canteen. It asks the user to enter a password, and if the correct password is entered (in this case, “EMP”), the employees can access the canteen inventory management functionalities.

6. void login::homepageswitch(): This function is a part of the login class and is used to navigate between different options on the homepage. It allows the user to either log in as an owner or an employee or exit the system.

7. void login::loginpageswitch(): This function is a part of the login class and is used to navigate between different options on the login page. It allows the user to choose whether they want to log in as an owner or employee or exit the system.

8. void store_manage::store_var_page(): This function is used to display the main menu of the canteen’s inventory management system. It provides options to order food, search for food items, delete food items, generate a bill, and exit the system.

9. void store_manage::orderfood(): This function is used to add new food items to the canteen’s inventory. It asks the user to enter details for the new food items, such as item name, item ID, cost, quantity, and rating. It also checks for duplicate entries and sorts the inventory for efficient searching.

10. void store_manage::search(): This function is used to search for food items in the canteen’s inventory based on the item name. It displays a list of matched items and allows the user to select a specific item ID to view its details.

11. void store_manage::del(): This function is used to delete a food item from the canteen’s inventory. It searches for the item to be deleted, updates the inventory, and rewrites the updated data to the storage files.

12. void store_manage::bill(): This function is used to generate a bill for the ordered food items. It calculates the total cost and displays the bill along with a thank you message.

13. void employee::emppage(): This function is used to display the main menu for employee management. It allows the user to view all employee details, add new employees, remove employees, or exit the employee management system.

14. void employee::addemp(): This function is used to add a new employee to the employee records. It prompts the user to enter the employee’s name, age, and salary and stores the details in a file.

15. void employee::displayemp(): This function is used to display all the details of all employees stored in the file.

16. void employee::removeemp(): This function is used to remove an employee from the employee records. It prompts the user to enter the name of the employee to be removed, and then it updates the records by removing the specified employee.

Output

Canteen Management System with C++

Canteen Management System with C++ - Employee Details

Canteen Management System with C++ - Menu

Conclusion

The above-written code for the Canteen Management System with C++ is a complete source file to perform basic operations for the admin and users. It provides the owner, user, and customer login operations so as to give the users a perfect platform.

Through this management system, we can access the food item information and order the items that we intend to have in a straightforward, automated, and convenient manner

More C++ Projects>>>

You May Also Like To Create…

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *