Object Oriented Programming (Oops) : Class and Objects
Object Oriented Programming (Oops) : Class and Objects
1
class Car which has data members (variables) such as speed,
weight, price and functions such as gearChange(), slowDown(),
brake() etc. Now lets say I create a object of this class named
FordFigo which uses these data members and functions and give
them its own values. Similarly we can create as many objects as
we want using the blueprint (class).
2
Abstraction
Encapsulation
Inheritance
3
Polymorphism
4
Cafeteria Management System
Cafeteria management system will able to provide fast services to
their customers by using their records which has been saved
previously. However new records can be added any time
whenever any customers visited to their Cafeteria shop. To
identify the customers each customers will be provided with their
customer id and during data entering process all their basic
information’s will be added into the file in the binary format.
Admin will have the facility what are the items which are
available at their shop at particular time and what is the exact
quantity of any particular item.
The current system will allow their users to know what items are
available under their Cafeteria shop and in what quantity they are
available. At the mean time customers are also provided with
option of purchasing the particular item. If the customer enter the
yes option, then they can enter the number of quantity for each
product and at the end they will able to get the bills for the items
which they have purchased and finally backup their purchased
items from the pickup center. Thus admin will only having the
5
responsibility to check the final bills and provide better services to
their new and existing customers.
6
HEADER FILE USED
AND THEIR
PURPOSE :
7
Program:
//***************************************************************
// HEADER FILE USED IN PROJECT
//****************************************************************
#include<conio.h>
#include<stdio.h>
#include<process.h>
#include<fstream.h>
#include<iomanip.h>
#include<string.h>
#include<ctype.h>
struct order
{
int prodid1;
char pname1[50];
char compy1[50];
int qty1;
float price1,dis1;
}o1[50];
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);
//***************************************************************
// CLASS USED IN PROJECT
//****************************************************************
//*******************customer information****************************
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; }
8
char *getcustadd()
{ return address; }
char *getphno()
{ return phno; }
void cust_input(int idj)
{
fflush(0);
gotoxy(5,7);
cout<<"=================================================";
gotoxy(10,8);
cout<<"CUST NO:";
cust_id=idj;
gotoxy(24,8);
cout<<cust_id;
gotoxy(35,8);
cout<<"NAME OF CUST:";
gotoxy(54,8);
cin.getline(cname,sizeof(cname));
gotoxy(10,9);
cout<<"ADDRESS:";
gotoxy(22,9);
cin.getline(address,sizeof(address));
gotoxy(10,11);
cout<<"PHONE NO.:";
gotoxy(25,11);
cin>>phno;
gotoxy(5,12);
cout<<"==============================="; }
void show_cust()
{ gotoxy(5,7);
cout<<"===============================================";
gotoxy(10,8);
cout<<"CUST NO:";
gotoxy(25,8);
cout<<cust_id;
gotoxy(70,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 showallcust(int c)
{
gotoxy(1,c);
cout<<cust_id<<setw(17)<<cname<<setw(20)<<address<<setw(30)<<phn}
void showcustdatamulti()
{ gotoxy(5,7);
9
cout<<"===================================================";
gotoxy(10,8);
cout<<"CUST NO:";
gotoxy(30,8);
cout<<cust_id;
gotoxy(40,8);
cout<<"NAME OF CUSTD:";
gotoxy(60,8);
cout<<cname;
gotoxy(10,9);
cout<<"ADDRESS:";
gotoxy(30,9);
cout<<address;
gotoxy(10,10);
cout<<"PHONE NO.:";
gotoxy(30,10);
cout<<phno;
gotoxy(5,11);
cout<<"==============================================";}};
//*************************modify customer details
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;
10
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<<"==================================================";}
//**************************class function customer modify ends here
//*********************customer class ends here*********************
//****************function to add the records in a file
void write_customer()
{ ofstream objoff;
customer cobj;
objoff.open("customer.txt",ios::binary|ios::app);
clrscr();
intromain();
int r=getcustomers();
if(r>1000) //1000 {
r=1; // r=100}
cobj.cust_input(r);
objoff.write((char*)&cobj,sizeof(customer));
objoff.close();
gotoxy(10,20);
cout<<"***************CUSTOMER RECORD SAVED***************** ";
cin.ignore();
11
getch(); }
//**************function to add the record in a file ends here
//******check the customer number already given or not******
int getcustomers() {
ifstream objiff;
customer cust;
int count=0;
objiff.open("customer.txt",ios::binary);
objiff.seekg(0,ios::beg);
if(!objiff) {
cout<<"File could not be open !! Press any Key...";
getch(); }
//**************temporary hiding these lines
while(objiff.read((char *) &cust, sizeof(customer)))
{ count++; }
//***********jump to the last line
objiff.seekg(count-sizeof(cust),ios::beg);
objiff.read((char *) &cust, sizeof(customer));
count=cust.getcustid();
count++;
objiff.close();
return count; }
//*****************check the customer number ends here
// function to read specific record from file
//********************************************************
void display_cust_sp(int n) {
ifstream objfp;
customer cust;
int flag=0;
objfp.open("customer.txt",ios::binary);
if(!objfp) {
cout<<"File could not be open !! Press any Key...";
getch();
return; }
while(objfp.read((char*)&cust,sizeof(customer)))
{ if(cust.getcustid()==n)
{ clrscr();
intromain();
cust.show_cust();
flag=1; } }
objfp.close();
if(flag==0)
cout<<"\n\nrecord not exist";
getch(); }
//*********customer record sepecific********************
// DISPLAY ALL THE CUSTOMER TABULAR FORM
//*****************************************************
void cust_tabular()
{ int r=0,col=10;
customer cust;
ifstream inFile;
inFile.open("customer.txt",ios::binary);
if(!inFile) {
cout<<"File could not be open !! Press any Key...";
getch();
return; }
12
display_all_cust();
while(inFile.read((char *) &cust, sizeof(customer))) {
if(r<=20) {
r++;
cust.showallcust(col);
col++; }
else {
gotoxy(10,30);
cout<<"-------press any key-------------------";
getch();
clrscr();
display_all_cust();
col=10;
r=0; } }
inFile.close();
getch(); }
//*******************tabular forms ends***************
//function to display all the records of product
//****************************************************
void display_all_cust() {
clrscr();
intromain();
gotoxy(1,5);
cout<<" *************CUSTOMERDETAILS****************";
gotoxy(1,6);
cout<<"==============================================";
gotoxy(1,7);
cout<<"CUST.NO"<<setw(10)<<"NAME"<<setw(15)<<"ADDRESS"
<<setw(30)<<"PHONE NO";
gotoxy(1,8);
cout<<"============================================"; }
//*****************DISPLAY ALL ENDS HERE**********************
// MODIFY customer RECORD
//**********************************************************
void modify_cust_record(int n) {
customer cust,temp;
char tmpnm[50],tmpaddress[50];
ifstream inFile;
int fpos1=-1;
inFile.open("customer.txt",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) {
clrscr();
intromain();
cust.showcustdatamulti();
flag=1; } }
inFile.close();
if(flag==0)
cout<<"\n\nrecord not exist";
else {
//*******modifying the records starts here
13
fstream File;
File.open("customer.txt",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; } }
File.seekp(fpos1-sizeof(customer),ios::beg);
strcpy(tmpnm,cust.getcustnm());
strcpy(tmpaddress,cust.getcustadd());
char q1[15];
strcpy(q1,cust.getphno());
gotoxy(1,12);
cout<<"**************************************************";
gotoxy(1,13);
cout<<"=ENTER NEW VALUES FOR THE RECORDS GIVEN ABOVE=";
temp.modifycust_data(n,tmpnm,tmpaddress,q1);
File.write((char *) &temp, sizeof(customer));
File.close(); } }
//DELETE THE RECORD OF THE customer AVAILABLE
void deletecust_record(int n) {
customer cust;
ifstream inFile;
inFile.open("customer.txt",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)
{ clrscr();
intromain();
cust.showcustdatamulti();
flag=1; } }
inFile.close();
char ch;
if(flag==0)
cout<<"\n\nrecord 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.txt",ios::binary);
objiff.seekg(0,ios::beg);
while(objiff.read((char *) &cust, sizeof(customer))){
14
if(cust.getcustid()!=n)
{ outFile.write((char *) &cust, sizeof(customer)); } }
outFile.close();
objiff.close();
remove("customer.txt");
rename("Temp2.dat","customer.txt");
againopenandclosecust();
gotoxy(30,20);
cout<<"-------Record Deleted-----------"; } }
getch(); }
//****************delete record ends*********************
void againopenandclosecust()
{ ifstream inFile;
customer cust;
inFile.open("customer.txt",ios::binary);
if(!inFile) {
getch();
return; }
while(inFile.read((char *) &cust, sizeof(customer))) { }
inFile.close(); }
//**********search the customer***********************
int searchcust(int p)
{ customer cust;
int tmprt=0;
ifstream inFile;
inFile.open("customer.txt",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)
{ clrscr();
intromain();
cust.showcustdatamulti();
flag=1;
tmprt=(int)inFile.tellg();
break; } }
inFile.close();
if(flag==0)
return 1;
//cout<<"\n\nrecord not exist";
Else {
return tmprt; } }
//*********customer information ends*********
class product {
int prodid;
char name[50];
char company[50];
int qty;
float price,dis;
public:
product() {
qty=0;
price=0;
15
dis=0; }
void modifydata(int n1,char snm[15],char companynm[15],int q);
//*******************************************************
void showdatamulti()
{ gotoxy(5,7);
cout<<"===============================================";
gotoxy(10,8);
cout<<"PROD NO:";
gotoxy(30,8);
cout<<prodid;
gotoxy(40,8);
cout<<"NAME OF PROD:";
gotoxy(60,8);
cout<<name;
gotoxy(10,9);
cout<<"COMPANY:";
gotoxy(30,9);
cout<<company;
gotoxy(40,9);
cout<<"PROD PRICE:";
gotoxy(60,9);
cout<<price;
gotoxy(10,10);
cout<<"QUANTITY:";
gotoxy(30,10);
cout<<qty;
gotoxy(40,10);
cout<<"DISCOUNT";
gotoxy(60,10);
cout<<dis;
gotoxy(5,11);
cout<<"=============================================";}
//*********************************************
void create_prod(int rn1 {
//**********************************************
gotoxy(5,7);
cout<<"===========================================";
gotoxy(10,8);
cout<<"PROD NO:";
prodid=rn1;
gotoxy(24,8);
cout<<prodid;
gotoxy(35,8);
cout<<"NAME OF PROD:";
gotoxy(54,8);
cin.getline(name,sizeof(name));
gotoxy(10,9);
cout<<"COMPANY:";
gotoxy(22,9);
cin.getline(company,sizeof(company));
gotoxy(35,9);
cout<<"QUANTITY";
gotoxy(54,9);
cin>>qty;
gotoxy(10,11);
cout<<"PROD PRICE";
16
gotoxy(25,11);
cin>>price;
gotoxy(35,11);
cout<<"DISCOUNT";
gotoxy(45,11);
cin>>dis;
gotoxy(5,12);
cout<<"==================================================="; }
void show_prod() {
//********************************
gotoxy(5,7);
cout<<"===============================================";
gotoxy(10,8);
cout<<"PROD NO:";
//rollno=rn1;
gotoxy(25,8);
cout<<prodid;
gotoxy(35,8);
cout<<"NAME OF PROD:";
gotoxy(54,8);
cout<<name;
gotoxy(10,9);
cout<<"COMPANY:";
gotoxy(25,9);
cout<<company;
gotoxy(35,9);
cout<<"PROD PRICE:";
gotoxy(54,9);
cout<<price;
gotoxy(10,10);
cout<<"DISCOUNT:";
gotoxy(25,10);
cout<<dis<<"%";
gotoxy(35,10);
cout<<"QUANTITY:";
gotoxy(54,10);
cout<<qty;
gotoxy(5,11);
cout<<"================================================"; }
//-----------------------show data tabular form--------------
void showall(int c) {
gotoxy(1,c);
cout<<prodid<<setw(17)<<name<<setw(11)<<company<<setw(10)<<"Rs."<<price<
<setw(15)<<qty<<setw(12)<<dis<<"%"; }
//-----------------------ends here-----------------------
int retpno()
{return prodid;}
float retprice()
{return price;}
char* getcompany()
{ return company;}
char* getname()
{return name;}
int getqty()
{ return qty;}
float retdis()
17
{return dis;}
void setqty(int q21)
{qty=q21;} };
//class ends here
//*******************************************************
// global declaration for stream object, object
//*******************************************************
//*************************modify product
void product::modifydata(int n1,char snm[15],char companynm[15],int q)
{ char tmpnm[40],tmpnm2[40];
gotoxy(5,14);
cout<<"===================WANT TO MODIFY =================";
gotoxy(10,15);
cout<<"PROD NO:";
prodid=n1;
gotoxy(25,15);
cout<<prodid;
gotoxy(40,15);
strcpy(name,snm);
cout<<"NAME OF PROD:";
gotoxy(60,15);
cout<<name;
gotoxy(10,17);
cout<<"Want to change the name of product";
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(name,tmpnm);}
Else { }
gotoxy(1,18);
strcpy(company,companynm);
//****************COMPANY NAME TO BE MODIFY
cout<<"COMPANY NAME:";
gotoxy(20,18);
cout<<company;
gotoxy(35,18);
cout<<"Want to change the COMPANY";
gotoxy(65,18);
flag=0;
while(1)
{ gets(tmpnm2);
if(strlen(tmpnm2)!=0)
{ flag=1;
break;
} if(strlen(tmpnm2)==0)
{ flag=0;
break;
} }
18
if(flag==1)
{ strcpy(company,tmpnm2); }
//*****************COMPANY NAME TO BE MODIFIED ENDS HERE
gotoxy(5,19);
cout<<"*MODIFY**PRODUCT PRICE - QUANTITY - DISCOUNT ******";
//****************************************************
gotoxy(5,20);
cout<<"PRICE:";
gotoxy(15,20);
float tmppr=0;
flag=-1;
while(1)
{ cin>>tmppr;
if(tmppr!=0)
{ flag=1;
break;
}else
{ flag=0;
break; } }
if(flag==1)
{ price=tmppr; }
Else {}
//****************************************************
gotoxy(22,20);
cout<<"INCREASE QUANTITY:";
gotoxy(45,20);
int tmpqty=0;
cin>>tmpqty;
qty=q;
qty=qty+tmpqty;
//***************************************************
gotoxy(50,20);
cout<<"DISCOUNT:";
gotoxy(63,20);
float tmpdis=0;
cin>>tmpdis;
dis=tmpdis;
//*****************************************
gotoxy(5,22);
cout<<"================================================="; }
//**************************class function outside
fstream fp;
product pr;
//*****************************************************
// function to write in file
//*****************************************************
void write_book() {
fp.open("product.txt",ios::binary|ios::app);
clrscr();
intromain();
int rnn=getproduct();
if(rnn>1000)
{rnn=1;}
pr.create_prod(rnn);
fp.write((char*)&pr,sizeof(product));
fp.close();
19
gotoxy(10,20);
cout<<"***************PRODUCTS RECORD SAVED******************* ";
cin.ignore();
getch(); }
//*******check the product number already given or not*****
int getproduct() {
ifstream objiff;
product st;
int count=0;
objiff.open("product.txt",ios::binary);
objiff.seekg(0,ios::beg);
if(!objiff) {
cout<<"File could not be open !! Press any Key...";
getch(); }
//**************temporary hiding these lines
while(objiff.read((char *) &st, sizeof(product)))
{ count++; }
//***********jump to the last line
objiff.seekg(count-sizeof(st),ios::beg);
objiff.read((char *) &st, sizeof(product));
count=st.retpno();
count++;
objiff.close();
return count; }
//************************************************
// function to read specific record from file
//*************************************************
void display_sp(int n) {
int flag=0;
fp.open("product.txt",ios::in);
if(!fp) {
cout<<"File could not be open !! Press any Key...";
getch();
return; }
while(fp.read((char*)&pr,sizeof(product)))
{ if(pr.retpno()==n) {
clrscr();
intromain();
pr.show_prod();
flag=1; } }
fp.close();
if(flag==0)
cout<<"\n\nrecord not exist";
getch(); }
//***************************************************
// function before place order and then call place order function
//***********************************************************
int before_order()
{ int f=-1,num=0;
customer cust;
clrscr();
intromain();
gotoxy(10,8);
cout<<"*****ENTER THE CUST ID TO BE SEARCHED:";
gotoxy(55,9);
cin>>num;
20
ifstream inFile;
inFile.open("customer.txt",ios::binary);
if(!inFile) {
cout<<"File could not be open !! Press any Key...";
getch();
return -1; }
while(inFile.read((char *) &cust, sizeof(customer)))
{ if(cust.getcustid()==num)
{ clrscr();
intromain();
cust.showcustdatamulti();
f=1;
//tmprt=(int)inFile.tellg();
break; } }
inFile.close();
return f; }
//********************************************************
//*******************************************************
// function to place order and generating bill for PRODUCT PURCHASED
//****************************************************************
void place_order() {
order o1[50];
int c=0,pr1=0;
float amt=0,damt=0,total=0,ttaxt=0;
int k=0,q1;
char ch='Y';
int value=before_order();
if(value==1)
{ clrscr();
prod_tabular();
clrscr();
intromain();
gotoxy(30,4);
cout<<"============================";
gotoxy(30,5);
cout<<" PLACE YOUR ORDER";
gotoxy(30,6);
cout<<"============================";
do
{ clrscr();
gotoxy(5,10);
cout<<"ENTER THE PRODUCT NO: ";
gotoxy(55,10);
cin>>pr1;
k=search(pr1);
if(k>0)
{ gotoxy(5,12);
cout<<"Enter the Quantity:";
gotoxy(28,12);
cin>>q1;
changeqty(pr1,q1);
copyme(k,o1,q1,c);
}else
{ cout<<"PRODUCT not found"; }
clrscr();
gotoxy(10,20);
21
cout<<"Do you want purchase more (Yes[ y or Y ] or NO [n or N])";
gotoxy(10,21);
cin>>ch;
} while(ch=='y' || ch=='Y');
//***************while ends by these lines
clrscr();
gotoxy(20,20);
cout<<"Thank You For Placing The Order..........";
getch();
clrscr();
intromain();
gotoxy(13,5);
cout<<"*************************INVOICE************************";
gotoxy(1,6);
cout<<"PR.No."<<setw(12)<<"NAME"<<setw(10)<<"Qty"<<setw(15)<<"Price
"<<setw(13)<<"Amount"<<setw(23)<<"Amount- discount";
gotoxy(3,7);
cout<<"---------------------------------------------";
int yy=8;
for(int x=0;x<c;x++)
{ gotoxy(1,yy);
cout<<o1[x].prodid1;
gotoxy(10,yy);
cout<<o1[x].pname1;
gotoxy(27,yy);
cout<<o1[x].qty1;
gotoxy(40,yy);
cout<<"Rs."<<o1[x].price1;
gotoxy(50,yy);
amt=o1[x].qty1*o1[x].price1;
cout<<"Rs."<<amt;
damt=amt-o1[x].dis1;
gotoxy(65,yy);
cout<<"Rs."<<damt;
total+=damt;
//ttaxt+=o1[x].tax1;
yy++;
}
ttaxt=5;
gotoxy(3,yy);
cout<<"-----------------------------------------------";
yy++;
gotoxy(25,yy);
cout<<"TOTAL:";
gotoxy(35,yy);
cout<<total;
yy++;
gotoxy(25,yy);
cout<<"TAX%:";
gotoxy(36,yy);
cout<<"+"<<ttaxt;
yy++;
gotoxy(25,yy);
cout<<"----------------------------";
22
yy++;
gotoxy(25,yy);
cout<<"NET TOTAL:";
gotoxy(35,yy);
cout<<(total+((ttaxt*total)/100));
yy++;
gotoxy(3,yy);
cout<<"------------------------------------------"; }
else{
clrscr();
gotoxy(20,30);
cout<<"************YOUR ID IS WRON*****************"; }
//*****************change at the above
getch();}
//***********fuction to copy all record to a structure
void copyme(int k2,order order1[50],int q1,int &c2)
{
ifstream objiff2("product.txt",ios::binary);
product bk1;
objiff2.seekg(k2-sizeof(product));
objiff2.read((char*)&bk1,sizeof(product));
strcpy(order1[c2].pname1,bk1.getname());
strcpy(order1[c2].compy1,bk1.getcompany());
order1[c2].dis1=bk1.retdis();
order1[c2].price1=bk1.retprice();
//**********copy record***********************
order1[c2].qty1=q1;
c2++;
objiff2.close();}
//*******************************
// INTRODUCTION FUNCTION
//*******************************
void intro(){
clrscr();
gotoxy(4,2);
cout<<"******CAFETERIA-MANAGEMENT************";
gotoxy(12,4);
cout<<"=========================================";
gotoxy(5,5);
cout<<"******************S=Y=S=T=E=M*****";
gotoxy(5,7);
cout<<"----SCHOOL : Maria Assumpta Convent School--------";
gotoxy(50,20);
cout<<"MADE BY : PRARTHANA & SUCHI ";
getch(); }
//****************************************************
// ADMINSTRATOR MENU1 FUNCTION
//****************************************************
void admin_menu1() {
clrscr();
char ch2;
int num;
//*********************************************
clrscr();
intromain();
gotoxy(20,6);
23
cout<<"=================ADMIN MENU====================";
gotoxy(22,7);
cout<<"1.CREATE CUSTOMERS DETAILS";
gotoxy(22,8);
cout<<"2.DISPLAY ALL CUSTOMERS DETAILS";
gotoxy(22,9);
cout<<"3.SEARCH RECORD(QUERY) ";
gotoxy(22,10);
cout<<"4.MODIFY CUSTOMERS RECORDS";
gotoxy(22,11);
cout<<"5.DELETE CUSTOMERS RECORDS";
gotoxy(22,12);
cout<<"6.BACK TO MAIN MENU";
gotoxy(18,13);
cout<<"Please Enter Your Choice (1-6) ";
gotoxy(55,13);
//****************************************************
ch2=getche();
switch(ch2){
case '1':
clrscr();
write_customer();
break;
case '2':
cust_tabular();
break;
case '3':
//********************
clrscr();
intromain();
gotoxy(10,8);
cout<<"*****ENTER THE CUST ID TO BE SEARCHED:";
gotoxy(55,9);
cin>>num;
display_cust_sp(num);
break;
case '4':
clrscr();
intromain();
gotoxy(10,8);
cout<<"*****ENTER THE CUST ID TO BE SEARCHED AND MODIFY:";
gotoxy(55,9);
cin>>num;
modify_cust_record(num);
break;
case '5':
clrscr();
intromain();
gotoxy(10,8);
cout<<"*****ENTER THE CUST ID TO BE SEARCHED AND TO DELETE:";
gotoxy(55,9);
cin>>num;
deletecust_record(num);
break;
case '6':
break;
24
default:
cout<<"\a";admin_menu1();}}
//****************MENU 1 CUSTOMERS ENDS HERE*******
//-----------------------------------------
//*************************************
// ADMINSTRATOR MENU2 FUNCTION
//**************************************************
void admin_menu(){
clrscr();
char ch2;
int num;
//*******************************
clrscr();
intromain();
gotoxy(20,6);
cout<<"=================ADMIN MENU==============";
gotoxy(22,7);
cout<<"1.CREATE PRODUCTS";
gotoxy(22,8);
cout<<"2.DISPLAY ALL PRODUCTS AVAILABEL";
gotoxy(22,9);
cout<<"3.SEARCH RECORD(QUERY) ";
gotoxy(22,10);
cout<<"4.MODIFY PRODUCTS";
gotoxy(22,11);
cout<<"5.DELETE PRODUCTS";
gotoxy(22,12);
cout<<"6.BACK TO MAIN MENU";
gotoxy(18,13);
cout<<"Please Enter Your Choice (1-6) ";
gotoxy(55,13);
//**********************************************************
ch2=getche();
switch(ch2)
{
case '1':
clrscr();
write_book();
break;
case '2':
prod_tabular();//display_all();
break;
case '3':
//********************
clrscr();
intromain();
gotoxy(10,8);
cout<<"*****ENTER THE PROD ID TO BE SEARCHED:";
gotoxy(55,9);
cin>>num;
display_sp(num);
break;
case '4':
clrscr();
intromain();
25
gotoxy(10,8);
cout<<"*ENTER THE PROD ID TO BE SEARCHED AND MODIFY:";
gotoxy(55,9);
cin>>num;
modify_record(num);
break;
case '5':
clrscr();
intromain();
gotoxy(10,8);
cout<<"ENTER THE PROD ID TO BE SEARCHED AND TO DELETE:";
gotoxy(55,9);
cin>>num;
delete_record(num);
break;
case '6':
break;
default:cout<<"\a";admin_menu(); }}
//*************************************
// THE MAIN FUNCTION OF PROGRAM
//*************************************
void main() {
char ch;
intro();
do { {
//****************TEMPORARY***********************
clrscr();
intromain();
gotoxy(10,6);
cout<<"=================MAIN MENU====================";
gotoxy(18,7);
cout<<"01. PRODUCTS REPORT GENERATOR";
gotoxy(18,8);
cout<<"02. ADMINISTRATOR";
gotoxy(18,9);
cout<<"03. EXIT";
gotoxy(10,10);
cout<<"==============================================";
gotoxy(15,12);
cout<<"Please Select Your Option (1-3) ";
gotoxy(15,14);
ch=getche();
switch(ch)
{
case '1':
clrscr();
orderk=0;
place_order();
getch();
break;
case '2':
middleadminmenu();
break;
case '3':
26
exit(0);
default :
cout<<"\a"; } }
while(ch!='3');}
//***************main intro
void intromain()
{ clrscr();
gotoxy(1,2);
cout<<"**CAFETERIA****MANAGEMENT****SYSTEM*****PROJECT";
gotoxy(1,3);
cout<<"***********************************************"; }
//**************************************************
// DISPLAY ALL THE PRODUCT TABULAR FORM
//**************************************************
void prod_tabular() {
int r=0,col=10;
product st;
ifstream inFile;
inFile.open("product.txt",ios::binary);
if(!inFile)
{ cout<<"File could not be open !! Press any Key...";
getch();
return; }
display_all();
while(inFile.read((char *) &st, sizeof(product)))
{ if(r<=12) {
r++;
st.showall(col);
col++;
}else
{
gotoxy(10,30);
cout<<"----press any key------------------------";
getch();
clrscr();
display_all();
col=10;
r=0; } }
inFile.close();
getch();}
//**********tabular forms ends*******
//**********tabulars form
headings************************************
//function to display all the records of product
void display_all() {
clrscr();
intromain();
gotoxy(1,5);
cout<<" ***PRODUCTS DETAILS*******************";
gotoxy(1,6);
cout<<"=============================================";
gotoxy(1,7);
cout<<"PROD.NO"<<setw(10)<<"NAME"<<setw(15)<<"COMPANY"<<setw(15)<<"
PRICE"<<setw(15)<<"QUANTITY"<<setw(10)<<"DISCOUNT";
27
gotoxy(1,8);
cout<<"========================================"; }
//************************************************
// MODIFY RECORD
//************************************************
void modify_record(int n)
{ product st,temp;
char tmpnm[50],tmpcompany[50];
ifstream inFile;
int fpos=-1;
inFile.open("product.txt",ios::binary);
if(!inFile) {
cout<<"File could not be open !! Press any Key...";
getch();
return; }
int flag=0;
while(inFile.read((char *) &st, sizeof(product)))
{ if(st.retpno()==n)
{ clrscr();
intromain();
st.showdatamulti();
flag=1; } }
inFile.close();
if(flag==0)
cout<<"\n\nrecord not exist";
else {
//*******modifying the records starts here
fstream File;
File.open("product.txt",ios::binary|ios::in|ios::out);
if(!File)
{ cout<<"File could not be open !! Press any Key...";
getch();
return; }
while(File.read((char *) &st, sizeof(product)))
{ if(st.retpno()==n)
{ fpos=(int)File.tellg();
break; } }
File.seekp(fpos-sizeof(product),ios::beg);
strcpy(tmpnm,st.getname());
strcpy(tmpcompany,st.getcompany());
int q1=st.getqty();
gotoxy(1,12);
cout<<"*****************************************************************
************";
gotoxy(1,13);
cout<<"=ENTER NEW VALUES FOR THE RECORDS GIVEN ABOVE=";
temp.modifydata(n,tmpnm,tmpcompany,q1);
File.write((char *) &temp, sizeof(product));
File.close(); } }
//******************************
//DELETE THE RECORD OF THE PRODUCTC NOT AVAILABLE
//**********************************
void delete_record(int n) {
28
product st;
ifstream inFile;
inFile.open("product.txt",ios::binary);
if(!inFile) {
cout<<"File could not be open !! Press any Key...";
getch();
return; }
int flag=0;
while(inFile.read((char *) &st, sizeof(product)))
{ if(st.retpno()==n)
{ clrscr();
intromain();
st.showdatamulti();
flag=1; } }
inFile.close();
char ch;
if(flag==0)
cout<<"\n\nrecord 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("Temp1.dat",ios::binary);
ifstream objiff("product.txt",ios::binary);
objiff.seekg(0,ios::beg);
while(objiff.read((char *) &st, sizeof(product)))
{ if(st.retpno()!=n) {
outFile.write((char *) &st, sizeof(product));
} }
outFile.close();
objiff.close();
remove("product.txt");
rename("Temp1.dat","product.txt");
againopenandclose();
gotoxy(10,20);
cout<<"----------Record Deleted----------"; } }
getch(); }
//*************delete record ends*********
void againopenandclose()
{ ifstream inFile;
product st;
inFile.open("product.txt",ios::binary);
if(!inFile)
{ getch();
return; }
while(inFile.read((char *) &st, sizeof(product))) { }
inFile.close(); }
//********search the product***********************
29
int search(int p)
{ product st;
int tmprt=0;
ifstream inFile;
inFile.open("product.txt",ios::binary);
if(!inFile)
{ cout<<"File could not be open !! Press any Key...";
getch();
return -1; }
int flag=0;
while(inFile.read((char *) &st, sizeof(product)))
{ if(st.retpno()==p)
{ clrscr();
intromain();
st.showdatamulti();
flag=1;
tmprt=(int)inFile.tellg();
break; } }
inFile.close();
if(flag==0)
return 1;
//cout<<"\n\nrecord not exist";
Else {
return tmprt; } }
//***********change quantity*******************
void changeqty(int pr1,int q11) {
product st;
int fpos=-1;
fstream File;
File.open("product.txt",ios::binary|ios::in|ios::out);
if(!File) {
cout<<"File could not be open !! Press any Key...";
getch();
return; }
while(File.read((char *) &st, sizeof(product)))
{ if(st.retpno()==pr1)
{ fpos=(int)File.tellg();
break; } }
File.seekp(fpos-sizeof(product),ios::beg);
int q1=st.getqty();
q1=q1-q11;
st.setqty(q1);
File.write((char *) &st, sizeof(product));
File.close(); }
void middleadminmenu()
{ char ch;
do {
//****************TEMPORARY***********************
clrscr();
intromain();
gotoxy(20,6);
cout<<"=======CUSTOMER'S-PRODUCT'S MENU======";
gotoxy(28,7);
cout<<"01. CUSTOMER'S MENU";
gotoxy(28,8);
cout<<"02. PRODUCT'S MENU";
30
gotoxy(28,9);
cout<<"03. BACK TO MAIN";
gotoxy(20,10);
cout<<"======================================";
gotoxy(25,12);
cout<<"Please Select Your Option (1-3) ";
gotoxy(30,14);
ch=getche();
switch(ch) {
case '1': admin_menu1();
break;
case '2': admin_menu();
break;
case '3': break;
default :cout<<"\a";admin_menu(); }
}while(ch!='3'); }
//********************************
// END OF PROJECT
//********************************
31
Output
32
33
BIBLIOGRPHY
34