I am implementing a shopping mall system in c++ One class is of Mall with data m
ID: 3902488 • Letter: I
Question
I am implementing a shopping mall system in c++
One class is of Mall with data members and are possible methods listed below:
The mall itself. The mall performs the creation of a set of different stores, such as a book store, a shoe store, an electronic games store, etc. The mall greets an arriving customer and allows the customer to shop at the mall.
Some of the things a customer can do at the mall are:
Get a list of available stores
Get a shopping cart
Enter a store
Get of list of items available for sale at the store
Add items to the shopping cart
Proceed to checkout and purchase the items
Notable Attributes:
name - the name of the mall
stores - a collection of stores of different types
customers - the customers currently in the mall
Possible Methods:
void enter(Customer c) - customer c enters the mall
void exit(Customer c) - customer c exits the mall
ShoppingCart getShoppingCart - returns an empty shopping cart
Enumeration customers() - returns an enumeration of the customers in the mall
void checkout(shoppingCart cart) - checkout and purchase the items in the shopping cart
Help me out in implementing class
Explanation / Answer
#include<conio.h>
#include<stdio.h>
#include<process.h>
#include<fstream.h>
//***************************************************************
// CLASS USED IN PROJECT
//****************************************************************
class product
{
int pno;
char name[50];
float price,qty,tax,dis;
public:
void create_product()
{
cout<<" Please Enter The Product No. of The Product ";
cin>>pno;
cout<<" Please Enter The Name of The Product ";
gets(name);
cout<<" Please Enter The Price of The Product ";
cin>>price;
cout<<" Please Enter The Discount (%) ";
cin>>dis;
}
void show_product()
{
cout<<" The Product No. of The Product : "<<pno;
cout<<" The Name of The Product : ";
puts(name);
cout<<" The Price of The Product : "<<price;
cout<<" Discount : "<<dis;
}
int retpno()
{return pno;}
float retprice()
{return price;}
char* retname()
{return name;}
int retdis()
{return dis;}
}; //class ends here
//***************************************************************
// global declaration for stream object, object
//****************************************************************
fstream fp;
product pr;
//***************************************************************
// function to write in file
//****************************************************************
void write_product()
{
fp.open("Shop.dat",ios::out|ios::app);
pr.create_product();
fp.write((char*)&pr,sizeof(product));
fp.close();
cout<<" The Product Has Been Created ";
getch();
}
//***************************************************************
// function to read all records from file
//****************************************************************
void display_all()
{
clrscr();
cout<<" DISPLAY ALL RECORD !!! ";
fp.open("Shop.dat",ios::in);
while(fp.read((char*)&pr,sizeof(product)))
{
pr.show_product();
cout<<" ==================================== ";
getch();
}
fp.close();
getch();
}
//***************************************************************
// function to read specific record from file
//****************************************************************
void display_sp(int n)
{
int flag=0;
fp.open("Shop.dat",ios::in);
while(fp.read((char*)&pr,sizeof(product)))
{
if(pr.retpno()==n)
{
clrscr();
pr.show_product();
flag=1;
}
}
fp.close();
if(flag==0)
cout<<" record not exist";
getch();
}
//***************************************************************
// function to modify record of file
//****************************************************************
void modify_product()
{
int no,found=0;
clrscr();
cout<<" To Modify ";
cout<<" Please Enter The Product No. of The Product";
cin>>no;
fp.open("Shop.dat",ios::in|ios::out);
while(fp.read((char*)&pr,sizeof(product)) && found==0)
{
if(pr.retpno()==no)
{
pr.show_product();
cout<<" Please Enter The New Details of Product"<<endl;
pr.create_product();
int pos=-1*sizeof(pr);
fp.seekp(pos,ios::cur);
fp.write((char*)&pr,sizeof(product));
cout<<" Record Updated";
found=1;
}
}
fp.close();
if(found==0)
cout<<" Record Not Found ";
getch();
}
//***************************************************************
// function to delete record of file
//****************************************************************
void delete_product()
{
int no;
clrscr();
cout<<" Delete Record";
cout<<" Please Enter The product no. of The Product You Want To Delete";
cin>>no;
fp.open("Shop.dat",ios::in|ios::out);
fstream fp2;
fp2.open("Temp.dat",ios::out);
fp.seekg(0,ios::beg);
while(fp.read((char*)&pr,sizeof(product)))
{
if(pr.retpno()!=no)
{
fp2.write((char*)&pr,sizeof(product));
}
}
fp2.close();
fp.close();
remove("Shop.dat");
rename("Temp.dat","Shop.dat");
cout<<" Record Deleted ..";
getch();
}
//***************************************************************
// function to display all products price list
//****************************************************************
void menu()
{
clrscr();
fp.open("Shop.dat",ios::in);
if(!fp)
{
cout<<"ERROR!!! FILE COULD NOT BE OPEN Go To Admin Menu to create
File";
cout<<" Program is closing ....";
getch();
exit(0);
}
cout<<" Product MENU ";
cout<<"==================================================== ";
cout<<"P.NO. NAME PRICE ";
cout<<"==================================================== ";
while(fp.read((char*)&pr,sizeof(product)))
{
cout<<pr.retpno()<<" "<<pr.retname()<<" "<<pr.retprice()<<endl;
}
fp.close();
}
//***************************************************************
// function to place order and generating bill for Products
//****************************************************************
void place_order()
{
int order_arr[50],quan[50],c=0;
float amt,damt,total=0;
char ch='Y';
menu();
cout<<" ============================";
cout<<" PLACE YOUR ORDER";
cout<<" ============================ ";
do{
cout<<" Enter The Product No. Of The Product : ";
cin>>order_arr[c];
cout<<" Quantity in number : ";
cin>>quan[c];
c++;
cout<<" Do You Want To Order Another Product ? (y/n)";
cin>>ch;
}while(ch=='y' ||ch=='Y');
cout<<" Thank You For Placing The Order";getch();clrscr();
cout<<"
********************************INVOICE************************ ";
cout<<" Pr No. Pr Name Quantity Price Amount Amount after
discount ";
for(int x=0;x<=c;x++)
{
fp.open("Shop.dat",ios::in);
fp.read((char*)&pr,sizeof(product));
while(!fp.eof())
{
if(pr.retpno()==order_arr[x])
{
amt=pr.retprice()*quan[x];
damt=amt-(amt*pr.retdis()/100);
cout<<" "<<order_arr[x]<<" "<<pr.retname()
<<" "<<quan[x]<<" "<<pr.retprice()<<" "<<amt<<" "<<damt;
total+=damt;
}
fp.read((char*)&pr,sizeof(product));
}
fp.close();
}
cout<<" TOTAL = "<<total;
getch();
}
//***************************************************************
// INTRODUCTION FUNCTION
//****************************************************************
void intro()
{
clrscr();
gotoxy(31,11);
cout<<"SUPER MARKET";
gotoxy(35,14);
cout<<"BILLING";
gotoxy(35,17);
cout<<"PROJECT";
cout<<" MADE BY : ANUJ KUMAR";
cout<<" SCHOOL : RYAN INTERNATIONAL SCHOOL";
getch();
}
//***************************************************************
// ADMINSTRATOR MENU FUNCTION
//****************************************************************
void admin_menu()
{
clrscr();
char ch2;
cout<<" ADMIN MENU";
cout<<" 1.CREATE PRODUCT";
cout<<" 2.DISPLAY ALL PRODUCTS";
cout<<" 3.QUERY ";
cout<<" 4.MODIFY PRODUCT";
cout<<" 5.DELETE PRODUCT";
cout<<" 6.VIEW PRODUCT MENU";
cout<<" 7.BACK TO MAIN MENU";
cout<<" Please Enter Your Choice (1-7) ";
ch2=getche();
switch(ch2)
{
case '1': clrscr();
write_product();
break;
case '2': display_all();break;
case '3':
int num;
clrscr();
cout<<" Please Enter The Product No. ";
cin>>num;
display_sp(num);
break;
case '4': modify_product();break;
case '5': delete_product();break;
case '6': menu();
getch();
case '7': break;
default:cout<<"";admin_menu();
}
}
//***************************************************************
// THE MAIN FUNCTION OF PROGRAM
//****************************************************************
void main()
{
char ch;
intro();
do
{
clrscr();
cout<<" MAIN MENU";
cout<<" 01. CUSTOMER";
cout<<" 02. ADMINISTRATOR";
cout<<" 03. EXIT";
cout<<" Please Select Your Option (1-3) ";
ch=getche();
switch(ch)
{
case '1': clrscr();
place_order();
getch();
break;
case '2': admin_menu();
break;
case '3':exit(0);
default :cout<<"";
}
}while(ch!='3');
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.