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

Create a program that creates a text file from user input with the following dat

ID: 3849131 • Letter: C

Question

Create a program that creates a text file from user input with the following data, which is a list of tools, prices and quantities. There should be 3 columns of data, including 1 String for toolName, 1 double for toolPrice, and 1 int for toolQty. Create a program which reads the data file created in Part 1, and displays it as a table report with headings and a 4^th calculated column. Also, after the table is printed, include a sum of the Ext. Price at the end, an average of the Price column, and a count of the Qy of items. Sample output: Total of Ext Price: exist999.99 Average Single Item Price: exist99.99 Count of all items Qty: 99

Explanation / Answer

The answers are as follows:

Part1. The program is supposed to take three inputs
       1.String for toolname
       2.double for toolprice
       3.int for toolQty
       it should write the data in the text file

       The code is as follows:

       #include<iostream.h>
       #include<string>

       int main()
       {
          string toolName;
          double toolPrice;
          int toolQty;
          ofstream outfile;

          outfile.open("tools.txt");
          for (int i = 0; i<10; i++)
          {
              cout << "Enter toolName, toolPrice and toolQty" << endl;
              cin >> toolName >> toolPrice >> toolQty;
              outfile << toolName << " " << toolPrice << " " << toolQty << endl;
          }
          outfile.close();
       }

Part2.
       The code is as follows:

       #include<iostream.h>
       #include<string>

       int main()
       {
          string toolName;
          double toolPrice;
          int toolQty;
          ifstream infile;
          int sumExtPrice;
          int sumPrice;
          int count;
          int sumQty;

          infile.open("tools.txt");
          cout << "Item" << "   " << "Price" << "   " << "Qty" << "   " << "Ext Price" << endl;
          sumExtPrice = 0;
          sumPrice = 0;
          count = 0;
          sumQty = 0;
          while (infile >> toolName >> toolPrice >> toolQty)
          {
              cout << toolName << "   " << toolPrice << "    " << toolQty << "    " << toolPrice * toolQty << endl;
              sumPrice = sumPrice + toolPrice;
              sumExtPrice = sumExtPrice + toolPrice * toolQty;
              sumQty = sumQty + toolQty;
              count++;   
             
          }
          infile.close();
          cout << "Total of Ext Price: $" << sumExtPrice << endl;
          cout << "Average Single Item Price: $" << sumPrice/count << end;
          cout << "Count of all items Qty: << sumQty << endl;
       }

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