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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education