1. Write a C++ program that reads book purchasing/order information from a file.
ID: 3586740 • Letter: 1
Question
1. Write a C++ program that reads book purchasing/order information from a file. There will be multiple lines in the file and each line in the file will represent the purchase of a book by a customer. Each customer will generally buy multiple copies of each book for their book club. Each line will contain the following information about the book: • Customer ID • Title • Author • ISBN • Price • Quantity • Fiction/Non-Fiction • Genre The file will contain ordering information for 4 or 5 different customers. Here is an example of the data (note the column headers will NOT be in the file): CUST_ID Title Author ISBN PRICE QUANTITY F_NF GENRE 1234 Dog Strategy Henry C. Moreno 3-598-21500-2 12.99 5 N M 6789 Companion Kicked Me Out Lorraine J. Johnson 3-598-21599-1 24.99 3 F R 3444 Mime On My Journey Kristy S. Wahl 3-699-21500-8 6.75 10 N D 4455 Damaged By The Joke Henry C. Christopher 3-598-21500-2 12.99 4 N R 2. Make use of the following data types: • c++ string • double • int • char • bool 3. Additional Requirements: a) Assume the tax on the total price of the books is 7%. b) Shipping fee: If the quantity is over 20 Fee $50, 15-19: Fee $40, 10-14: Fee $30, 5-9: Fee $20, less than 5 Fee $10 c) Use and if/else or switch to determine the fee. d) Tax should not be calculated on the fees. e) A Boolean variable should be used to hold whether the book is Fiction or Non-Fiction. f) Use an if/else if statement to display the genre in the output. g) Do not apply fee to non-fiction romance. h) Accumulate total sales (without tax) of all invoices for this batch (file). i) Accumulate total number of books sold in this batch. j) Display the average book order sale. Do not use arrays for this project. Process one line at a time (read, accumulate, calculate, print to file). Take this project one step at a time: a) Loop through and read the data variables. b) Within your loop, next process a single line file. c) Still within your loop accumulate your total variables. d) Still within your loop write the invoice to the console. 4. Example Output Print Invoice (include the lines) to an invoice.txt file, you should have an entry like this for each unique customer id: __________________________________________________________________ Invoice Customer ID: 1234 Dog Strategy Non-Fiction Mystery 5@12.99 subtotal: 64.95 Total book sales: 64.95 Tax: 4.55 Subtotal: 69.50 Fee: 20.00 Total: 89.50 _________________________________________________________________ Now show the next customer…Complete for all separate Customer IDs After all of the individual invoice display the report totals: _________________________________________________________________ REPORT TOTALS: Total Book Sales: 259.38 Average Book Sale: 64.85 _________________________________________________________________
Explanation / Answer
Since, in the question given it is asked only to read from the file, so we need not create the books purchasing and ordering file, we are assuming the file is alerady been created. The data is there, or program will proceed from fetching the file as follows and all the nexessary explainations about the program i have written in the comments along with it. so do read that :-
#include <fstream>
#include <iostream>
using namespace std;
int main ()
{
char buffer[256];
ifstream myfile ("bookspur_ord.txt"); // name of the text file is bookspur_ord
int tax,shippingfee;
bool F_NF;
double PRICE;
char GENRE[100];
if(!myfile) //checking if text file is present or not
{
cout<<"Error in opening file..!!";
getch();
exit(0);
}
while (! myfile.eof() ) // checking for end of file
{
myfile.getline (buffer,100); // getting input line by line because the information is stored in lines
cout << buffer << endl;
tax=.07*PRICE;
if(QUANTITY>19)
shippingfee=50;
else if(QUANTITY>=15 && QUANTITY<=19)
shippingfee=40;
else if(QUANTITY>=10 && QUANTITY<=14)
shippingfee=30
else if(QUANTITY>=5 && QUANTITY<=9)
shippingfee=20;
else if(QUANTITY<5)
shippingfee=10;
if(F_NF=true)
cout<<" the book is fiction";
else
cout<<" the book is non fiction";
if(GENRE=="romance" && F_NF=false)
shippingfee=0;
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.