Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ File Streams: I'm stuck! How am I going to atoi() all this jazz? and more questions! data2016.csv is in text at bottom(could not attach

C++ File Streams: I'm stuck! How am I going to atoi() all this jazz? and more questions! data2016.csv is in text at bottom(could not attach file)

We will add file-I/O with streams and continue to use loops, control flow, functions, structs, arrays and the standard library (e.g., string, iostream, iomanip, etc.). We will focus our efforts on reading and writing data to files to create a visual chart. The chart will be written to a simple text (ASCII) image format called ppm (portable pixmap). The ppm format is discussed in Part 2 of this assignment description. We will use data that was taken from a table of Energy Consumption by State acquired from the U.S. Energy Information Administrations website (www.eia.gov). The data consists of energy consumption for various types of fuel for each state and Washington DC (DC) expressed in trillions of BTUs. We will read in the data per state and compute a total energy consumption for seven categories as follows: 1. coal 2. natural gas 3. petroleum: Fuel Oil + Jet Fuel + HGL Other + Motor Gasoline + Residual Fuel Oil 4. nuclear 5. other renewables: Hydroelectric Power + Wood and Waste + Fuel Ethanol + Geothermal 6. solar 7. wind Part 1: Data Analysis - a Command-Line State Energy Consumption Query: Create a command line menu driven application to display a states total energy consumption for coal, natural gas, petroleum, other renewables, solar and wind. The first part of the assignment will be to create a program named A03.cpp that will read in a data file called Data2016.csv using C++ file stream operators. The data is stored in a comma-separated values (csv) file. To correctly read the data into an array, the commas, spaces, newlines (whitespace) and header row (first row) must be ignored. File I/O can be performed using ifstream located in the #include standard library. Data Processing The data will be read into the program using a function called: ReadData(. . . ) with the following formal parameters: an ifstream &, a data structure (e.g. an array-of-structs, etc.) and the number of states (51 in our dataset that includes Washington D.C.). The ReadData(. . . ) function will compute the state energy consumption totals for each group (coal, natural gas, petroleum, nuclear, other renewables, solar and wind) as described above and will store the result (e.g. in an array) for use later in the application. Database Interface After the data is loaded and processed, a command-driven interface will allow a user to enter a state name. The interface will query the preprocessed data and display the states energy consumption as a percentage of that states total energy consumption. For example, California consumes 32 trillion BTUs of coal annually with a total energy consumption of 6989 trillion BTUs. The states total was computed by adding up the seven energy groups. The percentage of a given energy is then computed by: 32./6989. 100 = 0.46%. Note that the number of digits printed must be controlled with the stream formatting options. An example of the output and user interaction using the database: Enter a statename or q to exit: California Coal: 0.46% Natural Gas: 32.17% Petroleum: 49.73% Nuclear: 2.83% Other Renewables: 9.20% Solar: 3.82% Wind: 1.78% Enter a statename or q to exit: Wyoming Coal: 57.09% Natural Gas: 16.61% Petroleum: 19.49% Nuclear: 0.00% Other Renewables: 1.75% Solar: 0.01% Wind: 5.06% Enter a statename or q to exit: New York Coal: 0.84% Natural Gas: 37.88% Petroleum: 37.04% Nuclear: 12.34% Other Renewables: 10.57% Solar: 0.30% Wind: 1.03% Enter a statename or q to exit: Colorado Coal: 22.35% Natural Gas: 34.83% Petroleum: 32.70% Nuclear: 0.00% Other Renewables: 3.42% Solar: 0.66% Wind: 6.05% Enter a statename or q to exit q Goodbye

State, Coal, Natural Gas, Fuel Oil, Jet Fuel,HGL Other, Motor Gasoline, Residual Fuel Oil, Nuclear Electric Power, Hydroelectric Power, Wood and Waste, Fuel Ethanol, Geothermal, Solar, Wind Alabama,410.20,715.70,169.40,18.00,44.90,309.10,11.90,417.30,64.50,167.40,23.70,0.10,0.40,0.00 Alaska,16.60,330.90,64.40,104.80,28.60,35.20,0.00,0.00,15.30,2.30,0.00,0.20,0.05,1.60 Arizona,323.90,371.50,149.10,24.90,33.90,324.30,0.00,338.60,66.20,6.60,24.70,0.30,52.80,5.00 Arkansas,246.40,315.70,113.60,8.50,36.40,170.10,0.05,140.40,33.00,77.90,13.00,0.80,0.40,0.00 California,32.10,2248.40,560.40,672.60,383.00,1714.40,145.80,197.80,267.20,137.00,131.30,107.90,267.10,124.70 Colorado,321.50,501.10,103.90,52.50,50.20,263.80,0.00,0.00,17.60,10.60,20.20,0.80,9.50,87.00 Connecticut,2.30,254.70,94.90,9.50,25.10,168.30,0.80,173.40,2.10,25.20,12.90,0.05,4.10,0.10 Delaware,8.20,113.60,14.30,0.70,32.80,54.30,1.10,0.00,0.00,1.80,4.20,0.40,1.10,0.05 DC,0.05,30.10,2.80,0.00,3.45,13.30,0.00,0.00,0.00,0.80,1.00,0.05,0.30,0.00 Florida,426.20,1414.10,312.10,155.40,86.30,1008.80,59.10,306.70,1.60,182.50,69.80,10.10,30.20,0.00 Georgia,399.30,728.00,226.50,29.30,58.40,540.30,8.50,360.60,31.10,214.20,37.40,0.30,10.20,0.00 Hawaii,16.40,0.20,26.20,74.30,20.90,52.80,60.90,0.00,0.80,8.50,4.00,2.40,9.80,5.90 Idaho,2.40,110.30,70.90,5.50,13.20,88.20,0.05,0.00,83.40,22.70,6.70,2.20,0.40,23.80 Illinois,702.50,1045.20,297.30,161.00,241.50,544.70,0.60,1031.30,1.20,24.30,40.30,2.00,2.00,98.40 Indiana,948.40,780.10,235.00,50.20,121.10,357.50,1.70,0.00,3.90,30.40,25.20,4.60,2.40,45.20 Iowa,298.00,317.20,150.10,5.50,84.90,192.10,0.05,49.20,8.50,20.10,16.30,1.30,0.60,185.30 Kansas,253.10,278.10,119.50,8.70,59.80,154.20,3.60,86.20,0.30,6.30,10.70,1.00,0.10,130.30 Kentucky,736.60,284.10,156.20,68.00,123.70,250.80,0.05,0.00,32.10,35.20,17.80,2.70,0.40,0.00 Louisiana,140.50,1697.40,192.20,166.10,1253.90,254.50,37.70,179.40,10.20,136.30,19.50,1.80,1.80,0.00 Maine,2.20,54.50,70.70,6.50,20.30,89.60,3.80,0.00,27.70,90.60,6.60,0.10,0.40,15.40 Maryland,162.90,229.60,98.50,8.80,33.70,306.50,0.70,154.40,12.90,26.00,23.20,0.60,6.80,4.90 Massachusetts,20.10,442.70,144.60,60.90,33.90,315.10,4.70,56.60,6.60,37.40,24.10,0.90,17.50,2.00 Michigan,471.20,927.50,171.70,22.80,119.00,536.90,3.20,330.00,14.40,92.90,37.30,5.20,1.10,43.40 Minnesota,261.20,466.50,160.30,27.30,113.60,296.10,0.80,145.00,11.20,72.50,27.60,1.10,0.60,91.70 Mississippi,61.20,563.40,122.00,97.20,63.00,196.10,3.60,61.70,0.00,56.30,15.00,1.00,0.10,0.00 Missouri,639.90,273.60,188.10,16.60,57.00,362.70,0.10,98.60,11.70,26.40,26.10,0.40,1.90,10.40 Montana,161.90,77.60,50.20,5.40,50.80,61.00,0.00,0.00,93.10,4.40,4.70,0.30,0.10,19.80 Nebraska,240.50,172.90,111.40,7.50,17.70,102.20,0.00,97.80,7.90,4.10,7.10,1.20,0.10,35.10 Nevada,30.80,316.00,64.30,35.00,14.10,131.80,0.00,0.00,16.50,2.50,10.00,32.50,33.30,3.20 New Hampshire,5.30,59.50,40.30,2.50,21.60,80.20,1.50,112.60,10.60,35.80,6.00,0.05,0.50,4.00 New Jersey,17.50,795.10,176.30,187.20,109.40,469.70,25.00,312.60,0.10,28.40,35.90,0.50,22.20,0.20 New Mexico,197.10,259.60,92.30,7.20,30.80,107.80,0.00,0.00,1.40,6.30,8.30,0.50,8.60,33.30 New York,29.70,1335.10,330.10,201.20,98.70,635.30,40.00,434.80,248.20,76.50,46.60,1.20,10.60,36.40 North Carolina,381.80,540.20,190.90,14.90,81.50,531.00,0.50,447.50,40.80,110.20,36.70,1.00,33.40,0.10 North Dakota,394.60,105.80,84.80,5.60,27.40,49.60,0.00,0.00,17.70,2.60,3.80,1.00,0.05,75.40 Ohio,825.30,996.90,290.50,67.40,180.50,576.80,3.90,175.90,4.60,52.70,40.10,3.40,1.90,11.50 Oklahoma,221.80,738.40,175.00,52.60,83.30,222.40,2.60,0.00,23.80,31.00,15.50,0.05,0.10,185.30 Oregon,19.40,249.80,100.20,28.60,24.60,178.50,0.80,0.00,319.00,59.40,13.50,2.90,3.10,66.10 Pennsylvania,734.80,1363.80,327.30,69.20,188.70,556.60,3.50,867.30,21.90,104.70,39.80,2.20,4.10,32.10 Rhode Island,0.00,88.90,21.20,4.10,8.30,41.80,0.40,0.00,0.05,3.30,3.20,0.10,0.40,0.20 South Carolina,221.90,284.20,130.70,11.70,48.40,321.40,10.70,583.90,20.60,104.90,22.20,0.60,0.40,0.00 South Dakota,26.70,85.60,44.10,4.90,11.80,54.30,0.05,0.00,44.40,2.20,4.20,1.90,0.05,34.30 Tennessee,379.80,339.30,167.00,76.50,82.90,386.00,0.10,309.40,62.50,62.50,26.80,0.20,1.50,0.30 Texas,1323.10,4155.60,1021.90,477.60,3126.60,1588.20,191.30,440.10,12.40,88.80,121.60,2.50,10.90,531.10 Utah,269.00,250.90,82.20,39.40,37.90,134.10,0.00,0.00,7.00,2.60,10.30,5.30,11.20,7.60 Vermont,0.00,12.40,27.50,1.60,14.30,35.10,0.20,0.00,9.90,14.40,2.40,0.05,1.30,2.70 Virginia,222.90,572.10,185.00,61.50,56.50,456.60,7.50,311.00,13.60,110.70,33.50,1.70,1.10,0.00 Washington,53.30,324.90,156.60,118.20,122.40,315.10,112.50,100.70,723.30,108.00,23.90,1.10,1.00,74.20 West Virginia,752.00,187.50,77.00,1.20,30.40,93.20,0.30,0.00,15.10,16.30,6.40,0.05,0.10,13.20 Wisconsin,357.30,499.60,143.70,10.00,77.70,294.70,0.90,106.20,25.80,88.90,22.60,0.60,0.60,14.00 Wyoming,457.30,133.00,79.20,3.10,32.30,41.50,0.00,0.00,9.00,1.10,3.20,0.70,0.05,40.50

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data Fundamentals Concepts, Drivers & Techniques

Authors: Thomas Erl, Wajid Khattak, Paul Buhler

1st Edition

0134291204, 9780134291208

More Books

Students also viewed these Databases questions

Question

8. Satyam Computer Services Limited

Answered: 1 week ago