We’ve been updating and extending the inventory project to use files and to use arrays. Now it’s time to put it all together. I will give you a file inventory.txt  File Contents: Red delicious apples 1.00 25 6 8 10 Assorted bouquets 4.00 50 10 10 0 Camembert cheese 2.00 25 10 12 4 END The file will have the following specifications: Each record consists of two lines. The first line contains the name of the product, which may be more than one word long. The second line contains the wholesale price as a decimal, the markup as a percentage, and three quantities, for counter, shelf, and warehouse. If the first line of a record contains the word END all by itself, that is the end of the file. Your task is to read each record into the program, as a string for the name, and numbers for the price and markup, and as an array of numbers for the quantities. Then calculate the total profit for each item: (wholesale price) * (markup, converted into a decimal) * (total quantity). Print out a report on one line for each item: Name, total profit. Format the output nicely: names should fit in 30 characters and the prices should line up and should have two decimal places. Hints: You’ll want to use getline to read multi-word product names. You’ll want to consider what kind of array to use for quantities – do you have fractional quantities or whole numbers? You’ll want to review section 6.2 for how to produce a nicely formatted output. PREVIOUS VERSION OF PROGRAM (Writing to a File): #include #include #include using namespace std;   int main () {           ofstream w;         int c=1;           string filename;         cout << "File Name: ";         getline(cin, filename);         w.open(filename.c_str());   while(c==1){         string product_name;         cout << "Product name: ";         getline(cin, product_name,'\n');         w << product_name << endl; double wppi; //wholesale price per item cout << "Wholesale price: "; cin >> wppi; w << "Wholesale Price: " << wppi << " "; int quanity; cout << "Quanity: ";  cin >> quanity; w << "Quanity: " << quanity << " "; double total_price_paid; total_price_paid = wppi * quanity; double markup; cout << "What is the markup? "; cin >> markup; double retail_price; double anticipated_profit; retail_price = wppi + markup; anticipated_profit = total_price_paid - wppi; w << "Retail Price: " << retail_price << " " << "Anticipated Profit: " << anticipated_profit << endl; cout << "Do you want to process another record? Type 1 for Yes or 2 for No." <> c; cin.ignore(); } w.close(); return 0; } PREVIOUS VERSION OF THE PROGRAM (Reading from file): #include #include #include using namespace std; int main () { ifstream w; string filename; cout << "File Name: "; getline(cin, filename); w.open(filename.c_str()); string line; while(line!="END"){ getline(w,line); cout<

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter7: File Handling And Applications
Section: Chapter Questions
Problem 1GZ
icon
Related questions
Question

We’ve been updating and extending the inventory project to use files and to use arrays. Now it’s time to put it all together.

I will give you a file inventory.txt 

File Contents:

Red delicious apples

1.00 25 6 8 10

Assorted bouquets

4.00 50 10 10 0

Camembert cheese

2.00 25 10 12 4

END

The file will have the following specifications:

Each record consists of two lines.

The first line contains the name of the product, which may be more than one word long.

The second line contains the wholesale price as a decimal, the markup as a percentage, and three quantities, for counter, shelf, and warehouse.

If the first line of a record contains the word END all by itself, that is the end of the file.

Your task is to read each record into the program, as a string for the name, and numbers for the price and markup, and as an array of numbers for the quantities.

Then calculate the total profit for each item: (wholesale price) * (markup, converted into a decimal) * (total quantity).

Print out a report on one line for each item: Name, total profit.

Format the output nicely: names should fit in 30 characters and the prices should line up and should have two decimal places.

Hints:

You’ll want to use getline to read multi-word product names.

You’ll want to consider what kind of array to use for quantities – do you have fractional quantities or whole numbers?

You’ll want to review section 6.2 for how to produce a nicely formatted output.

PREVIOUS VERSION OF PROGRAM (Writing to a File):

#include <iostream>

#include <string>

#include <fstream>

using namespace std;

 

int main ()

{

 

        ofstream w;

        int c=1;

 

        string filename;

        cout << "File Name: ";

        getline(cin, filename);

        w.open(filename.c_str());

 

while(c==1){

        string product_name;

        cout << "Product name: ";

        getline(cin, product_name,'\n');

        w << product_name << endl;

double wppi; //wholesale price per item

cout << "Wholesale price: ";

cin >> wppi;

w << "Wholesale Price: " << wppi << " ";

int quanity;

cout << "Quanity: ";

 cin >> quanity;

w << "Quanity: " << quanity << " ";

double total_price_paid;

total_price_paid = wppi * quanity;

double markup;

cout << "What is the markup? ";

cin >> markup;

double retail_price;

double anticipated_profit;

retail_price = wppi + markup;

anticipated_profit = total_price_paid - wppi;

w << "Retail Price: " << retail_price << " " << "Anticipated Profit: " << anticipated_profit << endl;

cout << "Do you want to process another record? Type 1 for Yes or 2 for No." <<endl;

cin >> c;

cin.ignore();

}

w.close();

return 0;

}

PREVIOUS VERSION OF THE PROGRAM (Reading from file):

#include <iostream>
#include <string>
#include <fstream>
using namespace std;

int main ()
{

ifstream w;

string filename;
cout << "File Name: ";
getline(cin, filename);
w.open(filename.c_str());

string line;

while(line!="END"){
getline(w,line);
cout<<line<<endl;
}

w.close();

return 0;
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT