This is for C++:   Assume that you have a file that contains the weekly average prices for a gallon of gas in the United States for the past 3 years.  The data is stored in the file as records.  Each record contains the average price of a gallon of gas on a specific date.  Each record contains the following fields: The month, stored as an integer.  January = 1, February = 2, etc. The day of the month, stored as an integer. The year, stored as an integer. The average price of a gallon of gas on the specified date, stored as a real number, rounded to 3 decimal places. Design a program that reads the file and displays the lowest and highest gas prices, as well as the dates for those prices.

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter8: Advanced Method Concepts
Section: Chapter Questions
Problem 4RQ
icon
Related questions
Question

This is for C++:

 

Assume that you have a file that contains the weekly average prices for a gallon of gas in the United States for the past 3 years.  The data is stored in the file as records.  Each record contains the average price of a gallon of gas on a specific date.  Each record contains the following fields:

  • The month, stored as an integer.  January = 1, February = 2, etc.
  • The day of the month, stored as an integer.
  • The year, stored as an integer.
  • The average price of a gallon of gas on the specified date, stored as a real number, rounded to 3 decimal places.

Design a program that reads the file and displays the lowest and highest gas prices, as well as the dates for those prices.  

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 5 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

I need help figuring out what I did do wrong.
So where can I put TXT File SNIP?

52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
string line;
string T;
string min_month, min_date, min_year;
float min_price= 1000000;
while (getline (inFile, line))
{
stringstream X(line);
getline (X, T,' ');
string month= T;
getline (X, T, ' ');
string date= T;
1
getline (X, T, ');
string year T;
getline (X, T, ' ');
string price= T;
float f_price= std::stof (price);
if(f_price < min_price)
{
min_price= f_price;
min_month= month;
min_date= date;
min_year= year;
}
cout << "Lowest Price is "<< min_price<< " on date "<< min_year<< "-"<< min_month<< "-"<< min_date<< endl;
inFile.close();
}
void printMaximumPrice()
{
ifstream inFile;
infile.open("gasPrices.txt");
string line;
string T;
string max_month, max_date, max_year;
float max_price= 0;
while (getline (inFile, line))
{
stringstream X(line);
getline (X, T, ' ');
string month= T;
getline (X, T,
string date= T;
1
getline (X, T,
');
');
string year= T;
1
getline (X, T, ');
string price= T;
Transcribed Image Text:52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 string line; string T; string min_month, min_date, min_year; float min_price= 1000000; while (getline (inFile, line)) { stringstream X(line); getline (X, T,' '); string month= T; getline (X, T, ' '); string date= T; 1 getline (X, T, '); string year T; getline (X, T, ' '); string price= T; float f_price= std::stof (price); if(f_price < min_price) { min_price= f_price; min_month= month; min_date= date; min_year= year; } cout << "Lowest Price is "<< min_price<< " on date "<< min_year<< "-"<< min_month<< "-"<< min_date<< endl; inFile.close(); } void printMaximumPrice() { ifstream inFile; infile.open("gasPrices.txt"); string line; string T; string max_month, max_date, max_year; float max_price= 0; while (getline (inFile, line)) { stringstream X(line); getline (X, T, ' '); string month= T; getline (X, T, string date= T; 1 getline (X, T, '); '); string year= T; 1 getline (X, T, '); string price= T;
Lowest Price is le+06 on date --
Highest Price is 0 on date
Process exited after 0.06144 seconds with return value 0
Press any key to continue . . . |
Transcribed Image Text:Lowest Price is le+06 on date -- Highest Price is 0 on date Process exited after 0.06144 seconds with return value 0 Press any key to continue . . . |
Solution
Bartleby Expert
SEE SOLUTION
Follow-up Question

What about for pseudocode for C++ too?

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Header Files
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,