Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Potato 123Pizza Beverage 456 Electricity is generated nationwide from a number o

ID: 3857296 • Letter: P

Question

Potato 123Pizza Beverage 456 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 report 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: 2 pouse prt sc breaksy @2 #3 s4 %5 ^6 &7: *88 (9, ) 0,

Explanation / Answer

#include<iostream>
#include<fstream>


#define FOSSILF 15
#define NEUCLEARF 16
#define HYDROF 17
#define RENEWABLEF 18
#define TOTAL 14

#define WIND 12
#define SOLAR 11
#define GEOTHERMAL 10
#define BIOMWAST 9
#define BIOMWOOD 8
#define HYDRO 7
#define HYDROP 6
#define NEUCLEAR 5
#define OGAS 4
#define NGAS 3
#define PETROLIUM 2
#define COAL 1
using namespace std;

int energy[65][19];
int total_energy[19];
int count = 0;
int readData(ifstream &fin) {
   int total_year;
   while (!fin.eof()) {
       total_year = 0;
       for (int i = 0; i<13; i++) {
           fin >> energy[count][i];
           total_year += energy[count][i];
           total_energy[i] += energy[count][i];
           if (i >= 1 && i <= 4)
               energy[count][FOSSILF] += energy[count][i];
           if (i == 5)
               energy[count][NEUCLEARF] += energy[count][i];
           if (i == 6)
               energy[count][HYDROF] += energy[count][i];  
           if (i >= 7)
               energy[count][RENEWABLEF] += energy[count][i];  
        }
       energy[count][TOTAL] = total_year;
       total_energy[TOTAL] += energy[count][TOTAL]; // is total
       total_energy[FOSSILF] += energy[count][FOSSILF]; // is fossil
       total_energy[NEUCLEARF] += energy[count][NEUCLEARF]; // is neuclear
       total_energy[HYDROF] += energy[count][HYDROF]; // is hydro
       total_energy[RENEWABLEF] += energy[count][RENEWABLEF]; // is renwable
   }
}


int getMaxYear(int k) {
   int max = 0;
   for (int i = 1; i < count; i++)
       if (energy[i][k] > energy[max][k])
           max = i;
   return energy[max][0];
}

int print_year_report(int year) {
   year -= 1949;
   cout << "COAL " << energy[year][COAL] << " " <<(double)energy[year][COAL]/energy[year][TOTAL] << endl;
   cout << "PETROLIUM " << energy[year][PETROLIUM] << " " <<(double)energy[year][PETROLIUM]/energy[year][TOTAL] << endl;
   cout << "NATURAL GAS " << energy[year][NGAS] << " " <<(double)energy[year][NGAS]/energy[year][TOTAL] << endl;
   cout << "OTHER GASES " << energy[year][OGAS] << " " <<(double)energy[year][OGAS]/energy[year][TOTAL] << endl;
   cout << "NEUCLEAR " << energy[year][NEUCLEAR] << " " <<(double)energy[year][NEUCLEAR]/energy[year][TOTAL] << endl;
   cout << "HYDRO-ELEC Pumped " << energy[year][HYDROP] << " " <<(double)energy[year][HYDROP]/energy[year][TOTAL] << endl;
   cout << "HYDRO ELECTRIC " << energy[year][HYDRO] << " " <<(double)energy[year][HYDRO]/energy[year][TOTAL] << endl;
   cout << "BIOMASS wood " << energy[year][BIOMWOOD] << " " <<(double)energy[year][BIOMWOOD]/energy[year][TOTAL] << endl;
   cout << "BIOMASS waste " << energy[year][BIOMWAST] << " " <<(double)energy[year][BIOMWAST]/energy[year][TOTAL] << endl;
   cout << "GEOTHERMAL " << energy[year][GEOTHERMAL] << " " <<(double)energy[year][GEOTHERMAL]/energy[year][TOTAL] << endl;
   cout << "SOLAR " << energy[year][SOLAR] << " " <<(double)energy[year][SOLAR]/energy[year][TOTAL] << endl;
   cout << "WIND " << energy[year][WIND] << " " <<(double)energy[year][WIND]/energy[year][TOTAL] << endl;
   cout << "TOTAL " << energy[year][TOTAL] << " " <<(double)energy[year][TOTAL]/energy[year][TOTAL] << endl;
}

int main() {
   ifstream file;
   file.open("");
   readData(file);
   file.close();
   cout << "1. Option A "
       << "2. Option B "
            << "3. Option C "
   <<"Enter choice: ";
   int choice, year;
   cin >> choice;
   switch(choice) {
       case 1:
           cout << "Enter year for report: ";
           cin >> year;
           print_year_report(year);
           break;
       case 2:
           for (int i = 1; i < 17; i++)
               cout << getMaxYear(i) << endl; /* Print other data*/
           break;
       case 3:
           char str[100];
           cout << "Enter file name: " ;
           cin >> str;
           int col;  
           cout << "Enter column number: ";
           cin >> col;

           ofstream fout;
           fout.open(str);
           for (int i = 0; i < count; i++)
               fout << energy[i][col] << endl;
           fout.close();
   }
}

The question is too long to be asnweed in a single window. I have provided the framework for you, which you can change a little and ge valid outputs*. I hope you understand the reason why this code maiy fail. Moreover the data quoted in the question is not available, so *i cannto test the code. If you have the data.dat file, do post the link and will update you about the stability of the code.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote