This program question is for a hypothetical catering company Assignment Plan and
ID: 3536946 • Letter: T
Question
This program question is for a hypothetical catering company
Assignment
Plan and code a program utilizing one file for input and one file for output to solve the following problem:
For adults, the deluxe meals will cost $25.80 per person and the standard meals will cost $21.75 per person, dessert included. Children's meals will cost 60 percent of adult meals. Everyone within a given party must be served the same meal type.
All customers will be charged the same rate for tip and tax, currently 18 percent (applied only to the cost of the food).
A surcharge, currently 7 percent, is added to the total bill if the catering is to be done on the weekend (Friday, Saturday, or Sunday).
To induce customers to pay promptly, a discount is offered if payment is made within ten days.
This discount depends on the amount of the total bill. If the bill is less than $100.00, the discount is 1.5 percent; if the bill is at least $100.00 but less than $400.00, the discount is 2.5 percent; if the bill is $400.00 or more, the discount is 3.5 percent.
Input
Number of adults, number of children, meal type (D, S) character indicating whether or not date is a weekend (Y/N), amount of any deposit. Create the data file below in text editor or Notepad.
Data File
10 0 S Y 100.00
27 3 D Y 57.50
125 17 D N 0.00
4 0 S N 25.00
0 25 S Y 23.75
250 43 D N 500.00
0 0 D N 0.0
10 0 R Y 10.00
17 3 D R 15.00
5 0 D Y 275.00
-3 10 D Y 20.00
14 -1 S N 30.00
20 3 D Y -10.00
Output
Output an itemized bill listing the number of adults, children, cost for adult meals, cost for children's meals, total food cost, surcharge (if appropriate), tax and tip, total cost of the party, deposit (if any), total balance due, amount of discount if bill is paid within ten days. Output error data to a separate error file.
Explanation / Answer
#include<iostream>
#include<fstream>
using namespace std;
// function for reading the records and creating the output file
int readFileAndCreateOutputFile(char* inputFile,char* outputFile)
{
int adults;
int childrens;
char mealType;
char weekend;
double deposits;
const double deluxeAdultMealCost=25.80;
const double standardAdultMealCost=25.80;
double total=0.0;
double zero=0.0;
double tax=0.0;
double discount=0.0;
//open files for reading and writting
ifstream in(inputFile);
ofstream out(outputFile);
int i=0;
// check file existense
if(!in)
{
cout<<"file does not exist "<<endl;
return -1;
}
// check file existense
if(!out)
{
cout<<"cannot open output file ";
return -1;
}
// start reading the record
out<<"adults childrens costOfAdults costOfchildrens totalFoodCost sucharge"
<<" tax totalCost(party) deposits due discount ";
while(!in.eof())
{
in>>adults;
in>>childrens;
in>>mealType;
in>>weekend;
in>>deposits;
//output no of adults and children
out<<adults<<" "<<childrens;
// output adult cost and children cost
if(mealType=='D')
{
total=adults*deluxeAdultMealCost+childrens*0.6*deluxeAdultMealCost;
out<<" "<<adults*deluxeAdultMealCost<<" "<<childrens*0.6*deluxeAdultMealCost;
}
else
{
total=adults*standardAdultMealCost+childrens*0.6*standardAdultMealCost;
out<<" "<<adults*standardAdultMealCost<<" "<<childrens*0.6*standardAdultMealCost;
}
// output total food cost
out<<" "<<total;
//calculate tax
tax=total*0.18;
total=total+tax;
// output surcharge (if appropriate),
if(weekend=='Y')
{
out<<" "<<total*0.07;
total=total+total*0.07;
}
else
out<<" "<<zero;
//output tax
out<<" "<<tax;
//output total food cost
out<<" "<<total;
//output deposits
out<<" "<<deposits;
//output deposits
out<<" "<<total-deposits;
//output discounts
if(total<100)
discount=total*0.015;
else if(total<400)
discount=total*0.025;
else
discount=total*0.035;
out<<" "<<discount;
out<<endl;
i++;
}
//close the files
in.close();
out.close();
return i;
}
int main()
{
char inputFile[30];
char outputFile[30];
// take input and output file name
cout<<"Enter the input file: ";
cin>>inputFile;
cout<<"Enter the output File: ";
cin>>outputFile;
// read the file and create the output file
int n=readFileAndCreateOutputFile(inputFile,outputFile);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.