Question
If necessary, create a new project named Advanced25 Project and save it in the Cpp8Chap14 folder. Also create a new source file named Advanced25.cpp. If
If necessary, create a new project named Advanced25 Project and save it in the Cpp8\Chap14 folder. Also create a new source file named Advanced25.cpp. If you are using Microsoft Visual C++, copy the Advanced25.txt file from the Cpp8\Chap14 folder to the Cpp8\Chap14\Advanced25 Project folder. Use a text editor to open the Advanced25.txt file, which contains the names of the items in inventory, as well as each items quantity and price. Close the Advanced25.txt file. Write a program that displays the contents of the file in three columns titled Name, Quantity, and Price. The program should also display a fourth column that contains the result of multiplying each items quantity by its price. Use Value as the columns title. (Hint: You can align the columns using '\t', which is the escape sequence for the Tab key.) In addition, the program should calculate and display the total value of the items in inventory. Display the price, value, and total value with two decimal places. Save and then run the program.
this code cannot run the program. please make copy
#include
#include
#include
#include
#include
#include
#include
using namespace std;
int main()
{
ifstream inFile("Advanced25.txt");
//reading data from file
if (inFile.is_open())
{
//declaring necessary variables
string line;
double totalValue=0;
//displat header line
cout< //reading data line by line while( getline(inFile,line) ) { stringstream ss(line); string name, qty, p; int quantity; double price,value; getline(ss,name,'#'); getline(ss,qty,'#'); getline(ss,p,' '); //converting string to int quantity= stoi(qty); //converting string to double price=stod(p); //computing value value=quantity*price; //display total line cout< cout< //updating total value totalValue+=value; } //display total value cout< cout< } else { cout<<"File cannot be opened"; exit(0); } return 0; }
Step 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