Question: Adapt this program to accept input pairs old price/new price for multiple products, from a text le. Your products.txt text le should contain 5 records

Adapt this program to accept input pairs old price/new price for multiple products, from a text le. Your products.txt text le should contain 5 records (lines), each line consisting of 3 elds: product name (string), old price (float), and new price (float). Reading from the text le should be controlled by EOF, not by the number of lines known beforehand. As the program reads from the le, a counter variable should keep track of the number of records read. This variable should be used later for calculating the average ination rate, derived as a simple average of the 5 values for the ination rate that result for each product. For this purpose, the program should maintain a running sum of the ination rates, which will be divided by the number of products, to obtain the average. The program should also calculate the projected prices of each of the 5 products next year, and output all 3 prices into an output.txt le. Add a header for this le, indicating what each eld (column) represents, and format the records so each eld starts at the same tab.

#include

#include

#include

#include

using namespace std;

float Inflation(float oldp, float newp);

void Output(float rate);

float oldprice, newprice;

int main(int argc, char **argv)

{

float inflationrate;

bool start;

start = true;

char answer;

string food;

float oldp;

float newp;

fstream myfile;

myfile.open("products.txt");

}

float Inflation(float oldp, float newp)

{

float rate = ((newp - oldp) / oldp) * 100;

return rate;

}

void Output(float rate)

{

cout << "The inflation rate is: " << rate << "%" << endl;

float next;

next = ((rate / 100) + 1)*newprice;

cout << "Next year's price is: $" <

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!