Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

CPSC 131 Fall 2017 Project 1 Requirements: Grocery cash register Introduction To

ID: 3884341 • Letter: C

Question

CPSC 131 Fall 2017

Project 1 Requirements: Grocery cash register

Introduction

To compute a grocery bill, a checkout stand typically has a scanner to identify product codes of items. This code is used to get the price of the item from the store’s price list, along with the item name and whether it is taxable. This information is then used to compute the price of the item and the total of the bill (see figure below). In this project, you will write C++ code to represent the workings of such a

Objective

You are given partial implementations of three classes. PriceList is a class to hold information of all items in the grocery store. There could be up to 1,000,000 items. The information of each item is its price, barcode, item name, and whether it is taxable; these are kept together in Class PriceListItem. The items in PriceList are loaded all together from a text file[1], or inserted one at a time. The complete grocery bill is computed in Class GroceryBill. To do so, it is given (a const pointer to) a previously created PriceList to get the prices, and the tax rate percentage for taxable items when constructed. It is then given barcodes of items and their quantity. The barcodes can be given one at a time, or they can be collected together in a text file.

You are to complete the implementations of these classes, adding public/private member variables and functions as needed. You should not use any of the C++ Standard Library containers (such as std::array, std::vector, std::list) for this project. Your code is tested in the provided main.cpp. Initially, the given code does not even compile. As you complete the code, it will pass the tests in the main.

Source Code Files

You are given “skeleton” code with many blank spaces. Your assignment is to fill in the missing parts so that the code is complete and works properly.

The included C++ code has multiple files:

        PriceListItem.h and PriceListItem.cpp: This is to be completed, with public/private member variables and functions as needed, so that it can be used in other classes.

        PriceList.h and PriceList.cpp: This is to be completed, with public/private member variables and functions as needed.

        This class contains a method to read item information from a text file. This method is already implemented.

        GroceryBill.h and GroceryBill.cpp: This is to be completed, with public/private member variables and functions as needed.

        main.cpp: Code that brings everything together into one application. The main function also tests the output of your functions. This is already complete and you should not change this code (it is ok to edit the file for your own testing, but during grading we will use the original main file).

        A README.md file. You must edit this file to include the name and CSUF email address of each student in your group. Do this even if you are working by yourself. We need this information so that we can enter your grades into Titanium. For example, if your group includes (fictional) students Ada Lovelace and Charles Babbage, your README.md should be in this format

Group members:

Ada Lovelace adalovelace@csu.fullerton.edu

Charles Babbage charlesbab@csu.fullerton.edu

Add default constructors, copy constructor, assignment operator, destructor if needed to the classes.

Hints

        Start implementing the PriceListItem class, then the PriceList class, and finally the GroceryBill class. As you write each class, test your code - the main function is just a series of tests. Do NOT wait until you complete the project before testing your code.

Simplifying assumptions

        The maximum number of different items in the grocery store (maximum number of PriceListItems that could be stored in the ItemList class) is 1,000,000.

        The maximum number of items scanned in any one grocery bill is 1,000.

        Names of items do not contain spaces.

This project wants me to create 3 classes PriceList, PriceListItem, and GroceryBill. This program must be in c++

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<<"";
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote