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

D) Create a cpp program (named Billing then create the following objects and dis

ID: 3752342 • Letter: D

Question

D) Create a cpp program (named Billing then create the following objects and display the objects based on the Instruction below. Create a Food object named item1 using its default constructor. Use set method to assign the following values, 1, Dine-In, Appetizer, Fried Caramari, 1, and 6.95 to order number, order type, food type, food name, quantity and price respectively Create a Food object named item2 using its constructor with six parameters. Assign the following values, 1, Dine-in, Entree, Grilled Salmon, 2, and 15.99 to parameters, order number, order type, food type, food name, quantity and price respectively Create a Drink object named item3 using its constructor with five parameters Assign the following values, 1, Dine-in, Coke, 3, and 1.95 to parameters, order number, order type, drink name, quantity and price respectively . Display billing summary by using get methods and subtotal methodas sh search

Explanation / Answer

/*

#include <fstream.h>

#include <process.h>

#include <string.h>

#include <stdlib.h>

#include <stdio.h>

#include <ctype.h>

#include <conio.h>

#include <dos.h>

/***************************************************************************

CLASS NAME : menu

DETAILS : IT CONTROLLS OVER ALL THE FUNCTIONS

***************************************************************************/

class menu

{

public :

void main_menu(void);

private :

void box(void);

void edit_menu(void);

};

/***************************************************************************

CLASS NAME : food

DETAILS : IT CONTROLLS OVER ALL THE FUNCTIONS

RELATED TO FOOD ITEMS

***************************************************************************/

class food

{

public :

void add_item(void);

void delete_item(void);

void modify_item(void);

void list_of_item(void);

void purchase(void);

private :

int last_code(void);

void delete_record(int);

void modify_record(int);

void display_record(int);

int item_found(int);

int recordno(int);

void sort(void);

int itemcode;

char itemname[30];

float costprice, sellingprice;

};

/***************************************************************************

CLASS NAME : account

DETAILS : IT CONTROLLS OVER ALL THE FUNCTIONS

RELATED TO MAKING BILL

***************************************************************************/

class account

{

public :

void bill_list(void);

void prepare_bill(int);

int last_billno(void);

void add_bill(int, int t_itemcode, char *t_itemname,

float t_qty, float t_cost, float t_price);

private :

int code, billno, length;

int dd, mm, yy;

float cost, price, quantity;

char name[30];

};

/***************************************************************************

THIS FUNCTION DRAW BOX FOR THE MENUS

***************************************************************************/

void menu :: box(void)

{

char c1=178, c2=177, c3=176;

int k=1;

gotoxy(1,2);

for (int i=1; i<=1840; i++)

{

if (k == 1)

cout <<c1;

else

if (k == 2)

cout <<c2;

else

if (k == 3)

cout <<c3;

k++;

if (k == 4)

k = 1;

}

for (i=5; i<=21; i++)

{

gotoxy(21,i);

cout <<" ";

}

}

/***************************************************************************

THIS FUNCTION CREATE MAIN MENU AND CALLS OTHER FUNCTIONS

***************************************************************************/

void menu :: main_menu(void)

{

clrscr();

char ch;

while (1)

{

clrscr();

box();

gotoxy(32,6);

cout <<"F A S T F O O D";

gotoxy(32,7);

cout <<"~~~~~~~~~~~~~~~~";

gotoxy(32,9);

cout <<"1: PURCHASE";

gotoxy(32,11);

cout <<"2: SEE MENU";

gotoxy(32,13);

cout <<"3: EDIT";

gotoxy(32,15);

cout <<"4: TOTAL BILL";

gotoxy(32,17);

cout <<"0: QUIT";

gotoxy(32,20);

cout <<"Enter Choice : ";

ch = getche();

if (ch == 27)

return;

else

if (ch == '1')

{

food f;

f.purchase();

}

else

if (ch == '2')

{

food f;

f.list_of_item();

}

else

if (ch == '3')

edit_menu();

else

if (ch == '4')

{

account a;

a.bill_list();

}

else

if (ch == '0')

break;

}

}

/***************************************************************************

THIS FUNCTION CREATE EDIT MENU AND CALLS OTHER FUNCTIONS

***************************************************************************/

void menu :: edit_menu(void)

{

char ch;

while (1)

{

for (int i=5; i<=21; i++)

{

gotoxy(21,i);

cout <<" ";

}

gotoxy(32,6);

cout <<"E D I T M E N U";

gotoxy(32,7);

cout <<"~~~~~~~~~~~~~~~~";

gotoxy(32,10);

cout <<"1: ADD ITEM";

gotoxy(32,12);

cout <<"2: MODIFY ITEM";

gotoxy(32,14);

cout <<"3: DELETE ITEM";

gotoxy(32,16);

cout <<"0: EXIT";

gotoxy(32,19);

cout <<"Enter Choice : ";

ch = getche();

if (ch == 27)

return;

else

if (ch == '1')

{

food f;

f.add_item();

break;

}

else

if (ch == '2')

{

food f;

f.modify_item();

break;

}

else

if (ch == '3')

{

food f;

f.delete_item();

break;

}

else

if (ch == '0')

break;

}

}

/***************************************************************************

THIS FUNCTION RETURNS THE CODE OF THE LAST RECORD IN THE

FOOD FILE (FOOD.DAT).

***************************************************************************/

int food :: last_code(void)

{

fstream file;

file.open("FOOD.DAT", ios::in);

file.seekg(0,ios::beg);

int t=0;

while (file.read((char *) this, sizeof(food)))

t = itemcode;

file.close();

return t;

}

/***************************************************************************

THIS FUNCTION DISPLAY THE LIST OF THE FOOD ITEMS

***************************************************************************/

void food :: list_of_item(void)

{

clrscr();

fstream file;

file.open("FOOD.DAT", ios::in);

file.seekg(0);

int row = 6 , found = 0 , pageno = 1;

gotoxy(30,2);

cout <<"LIST OF ITEMS";

gotoxy(29,3);

cout <<"~~~~~~~~~~~~~~~";

gotoxy(3,4);

cout <<"ITEM CODE ITEM NAME COST PRICE SELLING PRICE";

gotoxy(2,5);

cout <<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";

while (file.read((char *) this, sizeof(food)))

{

delay(20);

found = 1;

gotoxy(5,row);

cout <<itemcode;

gotoxy(14,row);

cout <<itemname;

gotoxy(37,row);

cout <<costprice;

gotoxy(51,row);

cout <<sellingprice;

if ( row == 22 )

{

row = 5;

gotoxy(66,1);

cout <<"Page no. : " <<pageno;

gotoxy(66,2);

cout <<"===============";

pageno++;

gotoxy(1,25);

cout <<"Press any key to continue...";

getche();

clrscr();

gotoxy(30,2);

cout <<"LIST OF ITEMS";

gotoxy(3,4);

cout <<"ITEM CODE ITEM NAME COST PRICE ";

cout<<"SELLING PRICE";

gotoxy(2,5);

cout <<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";

cout <<"~~~~~~~~~~~~";

}

else

row++;

}

if ( !found )

{

gotoxy(5,10);

cout <<"Records not found";

}

gotoxy(66,1);

cout <<"Page no. : " <<pageno;

gotoxy(66,2);

cout <<"===============";

gotoxy(1,25);

cout <<"Press any key to continue...";

getche();

file.close ();

}

/***************************************************************************

THIS FUNCTION ADD RECORDS IN THE FOOD FILE (FOOD.DAT)

***************************************************************************/

void food :: add_item(void)

{

int tcode, valid;

char ch, t_costprice[10], t_sellingprice[10];

tcode = last_code();

tcode++;

do

{

clrscr();

gotoxy(71,2);

cout <<"<0>=Exit";

gotoxy(27,3);

cout <<"ADD FOOD ITEM TO THE MENU";

gotoxy(26,4);

cout <<"~~~~~~~~~~~~~~~~~~~~~~~~~~~";

gotoxy(5,6);

cout <<"Item Code : " <<tcode;

gotoxy(5,8);

cout <<"Item Name : ";

gotoxy(5,10);

cout <<"Cost Price : ";

gotoxy(5,12);

cout <<"Selling Price : ";

do

{

valid = 1;

gotoxy(1,8); clreol();

gotoxy(1,24); clreol();

gotoxy(1,25); clreol();

gotoxy(3,25);

cout <<"ENTER ITEM NAME TO ADD IN THE MENU";

gotoxy(5,8);

cout <<"Item Name : ";

gets(itemname);

strupr(itemname);

if (itemname[0] == '0')

return;

if ((strlen(itemname) < 1) || (strlen(itemname) > 20))

{

valid = 0;

gotoxy(3,24);

cout <<" Range = 1..20";

getch();

}

} while (!valid);

do

{

valid = 1;

gotoxy(1,10); clreol();

gotoxy(1,24); clreol();

gotoxy(1,25); clreol();

gotoxy(3,25);

cout <<"ENTER ITEM COST TO ADD IN THE MENU";

gotoxy(5,10);

cout <<"Item Cost : ";

gets(t_costprice);

costprice = atof(t_costprice);

if (t_costprice[0] == '0')

return;

if (costprice < 1 || costprice > 800)

{

valid = 0;

gotoxy(3,24);

cout <<" Range = 1..800";

getch();

}

} while (!valid);

do

{

valid = 1;

gotoxy(1,12); clreol();

gotoxy(1,24); clreol();

gotoxy(1,25); clreol();

gotoxy(3,25);

cout <<"ENTER ITEM PRICE TO ADD IN THE MENU";

gotoxy(5,12);

cout <<"Selling Price : ";

gets(t_sellingprice);

sellingprice = atof(t_sellingprice);

if (t_sellingprice[0] == '0')

return;

if (sellingprice < costprice || sellingprice > 1000)

{

valid = 0;

gotoxy(3,24);

cout <<" Range = " <<costprice <<"..1000";

getch();

}

} while (!valid);

do

{

gotoxy(1,15); clreol();

gotoxy(1,24); clreol();

gotoxy(1,25); clreol();

gotoxy(5,15);

cout <<"Do you want to save this record (y/n) : ";

ch = getche();

ch = toupper(ch);

if (ch == '0')

return;

} while (ch != 'N' && ch != 'Y');

if (ch == 'Y')

{

itemcode = tcode;

fstream file;

file.open("FOOD.DAT", ios::out | ios::app );

file.write((char *) this, sizeof(food));

file.close();

tcode++;

}

do

{

gotoxy(1,17); clreol();

gotoxy(1,24); clreol();

gotoxy(1,25); clreol();

gotoxy(5,17);

cout <<"Do you want to add more records (y/n) : ";

ch = getche();

ch = toupper(ch);

if (ch == '0')

return;

} while (ch != 'N' && ch != 'Y');

} while (ch == 'Y');

}

/***************************************************************************

THIS FUNCTION DISPLAY THE RECORD OF THE GIVEN CODE FROM

THE FOOD FILE (FOOD.DAT)

***************************************************************************/

void food :: display_record(int tcode)

{

fstream file;

file.open("FOOD.DAT", ios::in);

file.seekg(0,ios::beg);

while (file.read((char *) this, sizeof(food)))

{

if (itemcode == tcode)

{

gotoxy(5,3);

cout <<"Item Code : "<<itemcode;

gotoxy(5,4);

cout <<"Item Name : "<<itemname;

gotoxy(5,5);

cout <<"Cost Price : "<<costprice;

gotoxy(5,6);

cout <<"Price Price: "<<sellingprice;

break;

}

}

file.close();

}

/***************************************************************************

THIS FUNCTION RETURN THE VALUE 1 IF THE RECORD IS FOUND

FOR THE GIVEN CODE IN THE FOOD FILE (FOOD.DAT)

***************************************************************************/

int food :: item_found(int tcode)

{

fstream file;

file.open("FOOD.DAT", ios::in);

file.seekg(0,ios::beg);

int found=0;

while (file.read((char *) this, sizeof(food)))

{

if (itemcode == tcode)

{

found++;

break;

}

}

file.close();

return found;

}

/***************************************************************************

THIS FUNCTION RETURN THE RECORD NO. OF THE GIVEN CODE IN

THE FOOD FILE (FOOD.DAT)

***************************************************************************/

int food :: recordno(int tcode)

{

fstream file;

file.open("FOOD.DAT", ios::in);

file.seekg(0,ios::beg);

int found=0;

while (file.read((char *) this, sizeof(food)))

{

found++;

if (itemcode == tcode)

break;

}

file.close();

return found;

}

/***************************************************************************

THIS FUNCTION DELETES THE RECORD FOR THE GIVEN CODE FROM

THE FOOD FILE (FOOD.DAT)

***************************************************************************/

void food :: delete_record(int tcode)

{

fstream file;

file.open("FOOD.DAT", ios::in);

fstream temp;

temp.open("temp.dat", ios::out);

file.seekg(0,ios::beg);

while ( !file.eof() )

{

file.read((char *) this, sizeof(food));

if ( file.eof() )

break;

if ( itemcode != tcode )

temp.write((char *) this, sizeof(food));

}

file.close();

temp.close();

file.open("FOOD.DAT", ios::out);

temp.open("temp.dat", ios::in);

temp.seekg(0,ios::beg);

while ( !temp.eof() )

{

temp.read((char *) this, sizeof(food));

if ( temp.eof() )

break;

file.write((char *) this, sizeof(food));

}

file.close();

temp.close();

}

/***************************************************************************

THIS FUNCTION GIVES THE CODE NO. TO DELETE RECORD FROM

THE FOOD FILE (FOOD.DAT)

***************************************************************************/

void food :: delete_item(void)

{

clrscr();

char t_code[5], ch;

int t, tcode;

gotoxy(3,25);

cout <<"Press <ENTER> to see the list";

gotoxy(5,3);

cout <<"Enter Item Code of the item to be deleted : ";

gets(t_code);

t = atoi(t_code);

tcode = t;

if (t_code[0] == '0')

return;

if (tcode == 0)

{

list_of_item();

gotoxy(1,25); clreol();

gotoxy(3,25);

cout <<"Press <ENTER> to Exit";

gotoxy(5,24);

cout <<"Enter Item Code of the item to be deleted : ";

gets(t_code);

t = atoi(t_code);

tcode = t;

if (tcode == 0)

return;

}

clrscr();

if (!item_found(tcode))

{

gotoxy(5,5);

cout <<"Record not found";

getch();

return;

}

display_record(tcode);

do

{

gotoxy(1,8); clreol();

gotoxy(5,8);

cout <<"Do you want to delete this record (y/n) : ";

ch = getche();

ch = toupper(ch);

} while (ch != 'N' && ch != 'Y');

if (ch == 'N')

return;

delete_record(tcode);

gotoxy(5,15);

cout <<"Record Deleted";

getch();

}

/***************************************************************************

THIS FUNCTION MODIFY THE RECORD FOR THE GIVEN CODE FROM

THE FOOD FILE (FOOD.DAT)

***************************************************************************/

void food :: modify_record(int tcode)

{

int recno;

recno = recordno(tcode);

int valid, t_code;

char ch, t_costprice[10], t_sellingprice[10], t_itemcode[5];

gotoxy(71,2);

cout <<"<0>=Exit";

gotoxy(5,12);

cout <<"Item Code : ";

gotoxy(5,14);

cout <<"Item Name : ";

gotoxy(5,16);

cout <<"Cost Price : ";

gotoxy(5,18);

cout <<"Selling Price : ";

do

{

gotoxy(20,12); clreol();

cout <<"Change (y/n) : ";

ch = getche();

ch = toupper(ch);

if (ch == '0')

return;

} while (ch != 'N' && ch != 'Y');

valid = 0;

while (ch == 'Y' && !valid)

{

valid = 1;

gotoxy(1,12); clreol();

gotoxy(1,24); clreol();

gotoxy(1,25); clreol();

gotoxy(3,25);

cout <<"ENTER ITEM CODE TO ADD IN THE MENU";

gotoxy(5,12);

cout <<"Item Code : ";

gets(t_itemcode);

t_code = atoi(t_itemcode);

if (t_code == 0)

return;

if (item_found(t_code) && t_code != tcode)

{

valid = 0;

gotoxy(3,24);

cout <<" CODE ALREADY GIVEN";

getch();

}

}

do

{

gotoxy(20,14); clreol();

cout <<"Change (y/n) : ";

ch = getche();

ch = toupper(ch);

if (ch == '0')

return;

} while (ch != 'N' && ch != 'Y');

valid = 0;