Question
#include #include //#include #include using namespace std; int main() { ifstream fin; // ifstream object to read char item[50]; int qty; float price; float total=0;
#include
int main() { ifstream fin; // ifstream object to read char item[50]; int qty; float price; float total=0; string report_text; fstream fout; // fstream object to write
fin.open("inventory.txt", ios::in); if(!fout) { cout
while(fin>>item>>qty>>price) { report_text = report_text + " " + item + "\t\t" + to_string(qty) + "\t\t" + to_string(price) + "\t\t" + to_string(qty*price); total = total + qty*price; } report_text = report_text + " -------------------------------------------------------"; report_text = report_text + " Inventory Total($) \t\t\t\t"+ to_string(total); // Print the report on console and file cout
Code is not reading the .txt file and bringing up the information. I am stuck on how to proceed further. Please someone assist me.
CS1 Lab 15 Write a C++ program to read the data from an ASCII file (text file), which has the inventory data for a store. Use only windows notepad to create this file, otherwise there may be extra characters in the file. The file has the data written to file in the following sequence for each part in the inventory. Part name (one word only), number of units in inventory (integer data), unit price (floating point data). The sample lines from the file looks like the Figure 1 below. Exp3. txt - Notepad Chisel 50 9.99 Hanner 30 15.99 Nails 2006 0.99 Bolts 200 2.99 Nuts 300 1.99 Soap 55 1.891 FIG 1 This structure of file will allow you to use only extraction operator>> to read all data. Read the data from file and calculate the value of inventory first for each item. For example for Chisel it would be 50-9.99 - 499.50 Then sum up the values for all items in the file to find Total cost of the inventory in dollars. Then output the data into an output file where it is formatted in a Table form that looks like the Figure 2 below: Inventory Report For Jane Doe International Hardware ITEM NUMBER OF UNITS UNIT COST (S) TOTAL VALUE (5) 499.50 50 9.99 Chisel Inventory Total (S) 2000.45 Perfect alignment is required. The names of parts must all be left justified, so that first letter of each part name aligns in the same vertical line. All numbers must be right justified, so that last digit of each line in each column aligns in the same vertical line. Numbers must be centered in each column. The inventory total must be aligned as shown in the Figure 2 above. For those float numbers, where price or total value rounds off to whole dollar, the price must be printed such as 12.00, not 12. L=12022C++ WINTER Microsoft Visual Studio Debug Console 2W oleA Inventory Report Item Number of Units Unit Cost($) Total Value($) Inventory Total($) 0.000000 C:\Users\scope\Desktop\projects\ConsoleApplication1\Debug ConsoleApplication1.exe (process 40056) exited with code e. "To automatically close the console when debugging stops, enable Tools->Options ->Debugging->Automatically close the conso le when debugging stops. Press any key to close this windowStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started