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

First, you must do all 3tasks in homework 5 to be eligible for extra credit Afte

ID: 3823313 • Letter: F

Question

First, you must do all 3tasks in homework 5 to be eligible for extra credit After you have completed the regular assignment, you may consider doing one or all of the following tasks for extra credit. File vo currently the Second Hand Rose problem has you ask the user for the item number and original price. Modify the program to read this data from a file. First, add the following to the Inventory class 1. A method that inputs an inventory item from a file, where the file is passed a The fle contains, on each line, the item number and then the original price of the item. as parameter. Then modify main0 so it does the following: open a text file named inventory txr 2. read all the Inventory records from the file by repeatedly calling the appropriate method in the Inventory class (Note that after each read, main0 should send the Inventory item to printSaleData0 for processing.)

Explanation / Answer

Hi,

I have written the code for above conditions and also given the output display below:-

#include <iostream>
using namespace std;
string item;//global variable
//This method will read data from file inventory.txt
void readFile(std::ifstream& )file
{
    file>>item;
  
   
}
//This method will take the data output form readFile and then output relevant information
void printSaleData(String saleitem)
{
      cout<<"The sale data for"<<saleitem<<"is"<<endl;
   
}
     

int main()
{
    //Open input file inventory.txt in read mode
    std::ifstream file("inventory.txt");
      if(!file)
      {
            cout<<"Error in opening file..!!";
            getch();
            exit(0);
      }
      //if file is not at end then call readFile function passing file members as parameters.
      while(ifile.eof()==0)
      {
          readFile(file);
          //After reading data then pas that item to printSaleData method for sales dispaly
          printSaleData(item);
      }
      return 0;
}

=============================================================================

OUTPUT:-

Assuming file inventor.txt have data

Book 100

Pen 200

Output

The sale data for Book is

The sale data for Pen is

===================================================================================

Please let me know in cae for clarification.