Question: These are notes on what I need to fix. /* Program not acceptable. 1. We do not allow global variables. 2. You never call the
These are notes on what I need to fix.
/* Program not acceptable.
1. We do not allow global variables.
2. You never call the functions that you wrote.
3. What is the code in main doing? returning aboolean to whom?
4. You do not have any protypes.
*/
Please help me fix this c++ program:
#include
#include
#include
using namespace std;
//to check whether the input value is positive or not
bool validateInput(int number, double arg1, double arg2, double arg3, double arg4)
{
if (arg1
{
return false;
}
return true;
}
//calculate the interior Cost
double interiorCost(double sqft, double price)
{
return sqft*price;
}
//calculate the exterior Cost
double exteriorCost(double sqft, double price)
{
return sqft*price;
}
//calculate the totalCost post applying discount
double totalCost(double total)
{
//if price is greater than 1000, apply 10% discount
if(total >1000)
{
double totalCost=total*0.1;
return total-totalCost;
}
return total;
}
int main()
{
string name;
int value;
double intSqFt=0, extSqtFt=0;
double intRate=0, extRate=0;
ifstream inFile;
ofstream oFile;
ofstream eFile;
//declarartion for input, output, error files.
string fileName, outfile="output.txt", errorfile="error.txt";
cout
cin >> fileName;
//open the file name
inFile.open(fileName);
//throw error if file opening has error
if (!inFile)
{
cout
exit(1);
}
oFile.open (outfile);
//throw error if file opening has error
if (!oFile)
{
cout
inFile.close();
exit(1);
}
eFile.open (errorfile);
//throw error if file opening has error
if (!eFile)
{
cout
inFile.close();
oFile.close();
exit(1);
}
oFile
eFile
//read each line from input file
while (inFile >> name >> value >> intSqFt >> intRate >> extSqtFt >> extRate)
{
//cout
if (validateInput(value, intSqFt, intRate, extSqtFt, extRate) == false)
{
eFile
continue;
}
//calculate the total
double total = (interiorCost(intSqFt, intRate) + exteriorCost(extSqtFt, extRate));
double discount = 0;
//print the output to out file
oFile
oFile
oFile
oFile
oFile
//calculate the discount from total, if the price is more than 1000
if (total > 1000)
{
discount=total*0.1;
}
//print the Discount and final price
oFile
oFile
}
//close all the files
inFile.close();
oFile.close();
eFile.close();
cout
return 0;
}
This is the prompt:
Objectives To learn to code, compile and run a program containing two or more functions. Assignment Write a complete program to calculate painting costs for customers of Top Quality Home Painting Service. Function 1: Read the data for one job from a file (see data below). Validate that none of the numbers are negative. Return the data from good records to main and write error records onto a separate file. Function 2: Determine the cost for interior painting, the cost for exterior painting, and the cost for the entire paint job. Any painting estimate greater than $1000.00 receives a 10% discount. Return all calculated values to main. Function 3: Label and output all good data (customer initials, customer account number, interior square feet, cost per interior square feet, exterior square feet, cost per exterior square feet, total interior cost, total exterior cost, any discount and total cost) to the screen. Input Input data from a file. One record of data contains the following sequence of data: ABC 1234 400 3.50 850 5.50 3 customer initials, customer account number (4 digit integer), the number of interior square feet to be painted, the cost per square foot for interior painting, the number of exterior square feet to be painted, the cost per square foot for exterior painting. Create the data file below using your text editor or Notepad. Data File ABC 1234 DEF 1345 GHI 2346 JKL 4567 MNO 5463 PQR 679 STU 6879 VWX 7348 XYZ 9012 400 100 200 375 200 0 100 0 -24 3.50 5.25 10.00 4.00 -5.0 0.0 0.0 0.0 5.00 850 200 0 50 150 100 -100 750 -50 5.50 2.75 0.0 4.00 3.00 3.50 0.0 0.0 5.00 Output Output and label all input and calculated data (three initials, customer account number, interior square feet, cost per interior square feet, exterior square feet, cost per exterior square feet, total interior cost, total exterior cost, any discount, and total cost) to an output file. Output valid data to one file and errors to an error file. Turn in Program listing and program output. Objectives To learn to code, compile and run a program containing two or more functions. Assignment Write a complete program to calculate painting costs for customers of Top Quality Home Painting Service. Function 1: Read the data for one job from a file (see data below). Validate that none of the numbers are negative. Return the data from good records to main and write error records onto a separate file. Function 2: Determine the cost for interior painting, the cost for exterior painting, and the cost for the entire paint job. Any painting estimate greater than $1000.00 receives a 10% discount. Return all calculated values to main. Function 3: Label and output all good data (customer initials, customer account number, interior square feet, cost per interior square feet, exterior square feet, cost per exterior square feet, total interior cost, total exterior cost, any discount and total cost) to the screen. Input Input data from a file. One record of data contains the following sequence of data: ABC 1234 400 3.50 850 5.50 3 customer initials, customer account number (4 digit integer), the number of interior square feet to be painted, the cost per square foot for interior painting, the number of exterior square feet to be painted, the cost per square foot for exterior painting. Create the data file below using your text editor or Notepad. Data File ABC 1234 DEF 1345 GHI 2346 JKL 4567 MNO 5463 PQR 679 STU 6879 VWX 7348 XYZ 9012 400 100 200 375 200 0 100 0 -24 3.50 5.25 10.00 4.00 -5.0 0.0 0.0 0.0 5.00 850 200 0 50 150 100 -100 750 -50 5.50 2.75 0.0 4.00 3.00 3.50 0.0 0.0 5.00 Output Output and label all input and calculated data (three initials, customer account number, interior square feet, cost per interior square feet, exterior square feet, cost per exterior square feet, total interior cost, total exterior cost, any discount, and total cost) to an output file. Output valid data to one file and errors to an error file. Turn in Program listing and program output
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
