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

use c++ to write this program Write a program that uses ifstream to receive data

ID: 674483 • Letter: U

Question

use c++ to write this program

Write a program that uses ifstream to receive data for today's sales for five stores from a text file. The input file should contain the name of each store (choosen by you) and the sales amount for today. Here is an example of the input file (please choose your own store names and amounts).

Macy's 1000

Nordstrom 12000

Boscov's 1800

Dillard's 800

JCPenney 1900

The program should then print to a file (output.out) a bar graph comparing each stores sales. Create each band in the bar graph by displaying a row of asterisks. Each asterisk should represent $100 of sales.

Here is an example of the program's output.

SALES BAR CHART

(each * = $100)

Store 1 : * * * * * * * * * * ( Macy's)

Store 2 : * * * * * * * * * * * * (Nordstrom)

Store 3: * * * * * * * * * * * * * * * * * * ( Boscovs)

Store 4: * * * * * * * * ( Dillard's)

Store 5 : * * * * * * * * * * ( JCPenney)

Explanation / Answer

#include<iostream>

#include<string.h>

#include<fstream>

using namespace std;

int main() {

ifstream in;

in.open("input.txt");

  

ofstream out;

out.open("output.txt");

  

int index = 0;

  

out<<"SALES BAR CHART ";

out<<"(each * = $100) ";

while (!in.eof()) {

string name;

int amt;

in>>name>>amt;

  

int g = amt/100;

  

out<<"Store "<<++index<<": ";

for (int i=0; i<g; i++) {

out<<'*';

}

out<<" ("<<name<<") ";

}

  

out.close();

in.close();

cout<<" ";

return 0;

}