Electricity is generated nationwide from a number of sources, including coal, nu
ID: 3857914 • Letter: E
Question
Electricity is generated nationwide from a number of sources, including coal, nuclear, hydroelectric, wind, and more. The Department of Energy publishes various reports each year related to energy. Some of the reports are located at http://www.eia.doe.gov/emeu/aer/elect.html . One of the reports is: Table 8.2b Electricity Net Generation: Electric Power Sector, 1949-2013. A subset of this table for 1980 – 2015 (with formatting and headings removed) is available on Blackboard in the data file is named Energy Data.dat. It is shown below.
The file Energy.dat is arranged as follows: Column 1 contains the year.
Columns 2-14 contain the following information:
Column
Energy (in Million Kilowatt-hours) generated by
Energy Category
2
Coal
Fossil Fuel
3
Petroleum
Fossil Fuel
4
Natural Gas
Fossil Fuel
5
Other Gases
Fossil Fuel
6
Nuclear Electric Power
Nuclear
7
Hydro-Electric Pumped Power
Hydro-Electric
8
Conventional Hydro-Electric
Renewable
9
Biomass – Wood
Renewable
10
Biomass – Waste
Renewable
11
Geothermal
Renewable
12
Solar
Renewable
13
Wind
Renewable
Program Requirements
Write a C++ program according to the following requirements:
1. Open the data file Energy.dat and read each column into an array (13 arrays total).
2. In addition to the 13 energy categories, create arrays for 3 useful totals:
Total Fossil Fuel Energy (sum of all fossil fuels)
Total Renewable Energy (sum of all renewable sources)
Grand Total Energy (sum of all 13 types of energy)
3. Give the user menu three options, including:
Option A: Display a report showing the energy produced and the percentage of the grand total energy for each of the 13 types of energy for a given year. Prompt the user to enter the year.
Example: If the user enters 2013, the report might look like:
Energy produced by different sources for the year 2013:
Category
Energy (Million Kilowatt-hours)
Percentage of total energy
Coal
1572179.442
9.382385
Petroleum
24094.141
0.143788
Natural Gas
1019962.207
6.086887
Option B: Determine the year in which the peak production of energy occurred (absolute value) for any of the 16 categories (13 in the table and the three totals). Also display the value of the energy.
Example: if the user selects nuclear as the category, the output might be:
The peak production of energy by nuclear power of 806968.301 million kilowatt hours occurred in 2010
Option C: Create an output data file to be later opened by Excel in order to graph. Allow the user to specify the name of the file. Submit the output file under assignments. Call the file Option C.txt.
Any of the 16 categories of energy for a given year (for example, Wind Energy or Total Renewable Energy)
Additional Requirement: Allow the user to correct any bad inputs (invalid year or menu selection, etc.)
Test Cases: Run the program for the following test cases and submit the results:
Option A: Generate reports for 1994, 2015 and at least one more year.
Option B: Generate reports for Wind Energy, Total Renewable and two more choices
Please you can use the file below for testing if you need to
207 301 222 302 22 167 125
367 60 120 111 301 499 434
211 62 441 192 21 293 316
401 340 161 297 441 117 206
448 111 370 220 264 444 207
21 313 204 222 446 401 337
213 208 444 321 320 335 313
162 137 265 44 370 315 322
150 218 234 384 283 199 204
204 245 287 298 302 288 297
Column
Energy (in Million Kilowatt-hours) generated by
Energy Category
2
Coal
Fossil Fuel
3
Petroleum
Fossil Fuel
4
Natural Gas
Fossil Fuel
5
Other Gases
Fossil Fuel
6
Nuclear Electric Power
Nuclear
7
Hydro-Electric Pumped Power
Hydro-Electric
8
Conventional Hydro-Electric
Renewable
9
Biomass – Wood
Renewable
10
Biomass – Waste
Renewable
11
Geothermal
Renewable
12
Solar
Renewable
13
Wind
Renewable
Explanation / Answer
#include <fstream>
#include <iostream>
#include <string>
using space std;
int main()
{
ifstream inFile;
int neglible[300]; //size of arrays bigger than number of entries in data file
int series1[100];
int series2[100];
int i=0;
inFile.open("happiness.dat");
if (inFile.fail())
{
cout << "Error" << endl;
return 1;
}
while (!inFile.eof())
{
inFile >> neglible[i];
inFile >> series1[i];
inFile >> series2[i];
i++;
cout << series1[i] << endl; // display values in the array to check that the correct values have been imported
}
inFile.close();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.