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

This is a program I wrote to calculate the price of 3 books of x customers and s

ID: 653925 • Letter: T

Question

This is a program I wrote to calculate the price of 3 books of x customers and subtotal/ total/ discounts/ etc... using for loops and arrays. I need to modify the project using the following criteria:

This is my current source code, I need to modify THIS project using the pictures criteria.

Please help!

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cstring>

using namespace std;

int main ()

{
ifstream inputfile;
string name, booknum, payment_type,
author1, title1, isbn1, header, address, aisle;

double discount =0.0;
double subtotal_before= 0.0, price1;
double subtotal_after=0.0;
double total_discount= 0.0;
double tax_total=0.0;
double grand_total;


const int string_max= 500;
const double float_max= 500.00;
const double float_min= 1.00;
int num= 75;
const int int_max=100;
const int int_min=1;
int x;


string cust_info [5][3];
int custinfo_num [5][3];
string book_info [5][3][4];
double book_info_num [5][3][2];
float cust_num2 [5][5];
double cust_tot = 0,sub_total=0, paytotal,total, tax;


ofstream outputfile;


inputfile.open("Project4_A04474443_input.txt"); //opening the input file
if (inputfile.fail()) //check to see if the input file will open
{
cout << "Error opening the file./n";
return 1;
}

outputfile.open("project4_A04474443_Output.txt");
if (outputfile.fail()) // checking to see if the output file will open
{
cout << "Error opening the output file.";
return 2;
}

cout << "Please enter the number of customers that" << endl;
cout << "will be buying books. "; // prompt the user to enter number of customers
cin >> x;
while(x != 5)
{
cout << "You must have five customers for this project!" << endl;
return 3;
}


for (int x=0; x<5; x++ ) //for loop for the 5 customers
{
sub_total = 0;
cust_tot = 0;
total = 0;
paytotal = 0;
//inputfile.ignore();
getline(inputfile,header);
cust_info[x][0]=header;
if (header.length() > string_max) //reading first line
{
cout << "string too long. ";
}

getline(inputfile, name);
cust_info[x][1]=name;
if (name.length() > string_max)
{
cout << "string too long ";
}

getline(inputfile, address);
cust_info[x][2]=address;
if (address.length() > string_max)
{
cout << "string too long ";
}
//writing to the output file
outputfile << left << cust_info[x][0] << endl;
outputfile << left << "Customer Name: " << cust_info[x][1] << endl;
outputfile << left << "Customer Address: " << cust_info[x][2] << endl;

//loop to get # of customers
for(int m = 0; m < 2; m++)
{
inputfile >> custinfo_num[x][m];
if(custinfo_num[x][m] > int_max || custinfo_num[x][m] < int_min)
cout << "Enter an integer between 1 and 100";
}

//writing the numerical information to the output file
outputfile << "Customer Age: " << custinfo_num [x][0] << endl;
outputfile << "Number of books being bought: " << custinfo_num[x][1] << endl;
outputfile << " " << endl;

inputfile.ignore();
//initialize before the loop to set the values
// back to zero for each new customer
cust_num2[x][2]=0.0;
cust_num2[x][1]=0.0;

//loop for the three books
for(int j = 0; j < 3; j++)
{
getline(inputfile, book_info[x][j][0]); //booknum
if (book_info[x][j][0].length() > string_max)
cout << "string too long";
outputfile << "Book Number: " << book_info[x][j][0] << endl;

getline(inputfile, book_info[x][j][1]); //booktitle

if (book_info[x][j][1].length() > string_max)
cout << "string too long";
outputfile << "Book Title: " << book_info[x][j][1] << endl;


getline(inputfile, book_info[x][j][2]); // bookauth
if (book_info[x][j][2].length() > string_max)
cout << "Author name too long";
outputfile << "Book Author: " << book_info[x][j][2] << endl;

getline(inputfile, book_info[x][j][3]); //aislenum
if (book_info[x][j][3].length() > string_max)
cout << "Aisle incorrect";
outputfile << "Aisle Number: " << book_info[x][j][3] << endl;

inputfile >> book_info_num[x][j][0];


if (book_info_num[x][j][0] > float_max || book_info_num[x][j][0] < float_min)
cout << "floating number not within 1.00 and 500.00";


inputfile.ignore();


outputfile << "Price: $" << fixed << setprecision(2) << book_info_num[x][j][0] << endl;


//calculates the subtotal of the three books before discounts
sub_total += book_info_num[x][j][0];


//calculating the discount
if (book_info_num[x][j][0] > 90)
{
book_info_num[x][j][1]= book_info_num[x][j][0]*.05;

}
else
{
book_info_num[x][j][1]= 0;
}

//calculates the total discount

cust_tot += book_info_num[x][j][1] ;


}

outputfile << endl << "Subtotal of three books: $" << sub_total << endl;
outputfile << "Total Discount: $" << cust_tot << endl;


//calculates the subtotal after discounts
total= sub_total-cust_tot;
outputfile << "Subtotal after discount: $" << setprecision(2) << fixed;
outputfile << total << endl;

//calculates the amount of tax added and saves to the array
tax= total*0.08;

outputfile << "Tax Added: $" << setw(5) << setprecision(2) << fixed;
outputfile << tax << endl;

//gets total amount
paytotal= total+tax;

outputfile << endl << "Total Amount Paid: $" << paytotal;

outputfile << endl << endl << right << setw(90);
outputfile << "Thank you for shopping at the University Bookstore!" << endl << endl <<endl;

}

//close the input and output files
inputfile.close();
outputfile.close();

return 0;
}

Explanation / Answer

//calculates the subtotal of the three books before discounts
sub_total += book_info_num[x][j][0];


//calculating the discount
if (book_info_num[x][j][0] > 90)
{
book_info_num[x][j][1]= book_info_num[x][j][0]*.05;

}
else
{
book_info_num[x][j][1]= 0;
}

//calculates the total discount

cust_tot += book_info_num[x][j][1] ;

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