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

Using C++ ,Give the user menu three options, including: Option A : Display a rep

ID: 656974 • Letter: U

Question

Using C++ ,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 1994, the report might look like:

Energy produced by different sources for the year 1994:

            Category            Energy (Thousand Kilowatthours)            Percentage of total energy

            Coal                             1666276091                                               53.947%

            Petroleum                        98676618                                               3.195%

            Natural Gas                 385689325                                               12.487%

         

Explanation / Answer

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<fstream.h>
struct ENERGY
{
int year;
int coal;
int petroleum;
int naturalgas;
int other;
int nuclear;
int hydro;
int hydro2;
int wood;
int waste;
int geothermal;
int solar;
int wind;
int totalfossil;
int totalrenew;
int grandtotal;
};
void main()
{
struct ENERGY en[19];
ifstream infile("Energy.dat");
ofstream outfile;
int i;
int option,pos;
int userinput;
int choice;
int max;
for(i=0;i<19;i++)
{
infile>>en[i].year;
infile>>en[i].coal;
infile>>en[i].petroleum;
infile>>en[i].naturalgas;
infile>>en[i].other;
infile>>en[i].nuclear;
infile>>en[i].hydro;
infile>>en[i].hydro2;
infile>>en[i].wood;
infile>>en[i].waste;
infile>>en[i].geothermal;
infile>>en[i].solar;
infile>>en[i].wind;
}
for(i=0;i<19;i++)
{
en[i].totalfossil=en[i].coal+en[i].petroleum+en[i].naturalgas+en[i].other+en[i].nuclear;
en[i].totalrenew=en[i].hydro2+en[i].wood+en[i].waste+en[i].geothermal+en[i].solar+en[i].wind;
en[i].grandtotal=en[i].totalfossil+en[i].totalrenew;
}
infile.close();
cout<<" Enter the 1 for Option A 2 for Option B 3 for Option C";
cin>>option;
switch(option)
{
case 1:
cout<<" Enter the year";
cin>>userinput;
for(i=0;i<19;i++)
{
if(userinput==en[i].year)
{
cout<<" Category Energy(Thousand Kilowatthours) Percentage of TotalEnergy";
cout<<"Coal"<<" "<<en[i].coal<<" "<<(en[i].coal/en[i].grandtotal)*100<<"%"<<endl;
cout<<"Petroleum"<<" "<<en[i].petroleum<<" "<<(en[i].petroleum/en[i].grandtotal)*100<<"%"<<endl;
cout<<"Natural Gas"<<" "<<en[i].naturalgas<<" "<<(en[i].naturalgas/en[i].grandtotal)*100<<"%"<<endl;
cout<<"Other"<<" "<<en[i].other<<" "<<(en[i].other/en[i].grandtotal)*100<<"%"<<endl;
cout<<"Nuclear"<<" "<<en[i].nuclear<<" "<<(en[i].nuclear/en[i].grandtotal)*100<<"%"<<endl;
cout<<"Hydro-Electric"<<" "<<en[i].hydro<<" "<<(en[i].hydro/en[i].grandtotal)*100<<"%"<<endl;
cout<<"Hydro-Electric2"<<" "<<en[i].hydro2<<" "<<(en[i].hydro2/en[i].grandtotal)*100<<"%"<<endl;
cout<<"Biomass-Wood"<<" "<<en[i].wood<<" "<<(en[i].wood/en[i].grandtotal)*100<<"%"<<endl;
cout<<"Biomass-Waste"<<" "<<en[i].waste<<" "<<(en[i].waste/en[i].grandtotal)*100<<"%"<<endl;
cout<<"Geothermal"<<" "<<en[i].geothermal<<" "<<(en[i].geothermal/en[i].grandtotal)*100<<"%"<<endl;
cout<<"Solar"<<" "<<en[i].solar<<" "<<(en[i].solar/en[i].grandtotal)*100<<"%"<<endl;
cout<<"Wind"<<" "<<en[i].wind<<" "<<(en[i].wind/en[i].grandtotal)*100<<"%"<<endl;
}
}
break;
case 2:
cout<<" enter the any one of 16 categories ";
cout<<" 1. coal 2.Petroleum 3.Natural Gas 4.Other 5.Nuclear 6.Hydro 7.Hydro2 8.Biomass-wood 9.Biomass-Waste 10.Geothermal 11.Solar 12.Wind 13.Total fossil 14. Total Renewable 15.Grand Total";
cout<<" Enter ur choice:";
cin>>choice;
//for coal
if(choice==1)
{
max=0;
for(i=0;i<19;i++)
{
if(en[i].coal>max)
{
max=en[i].coal;
pos=i;
}
}
cout<<" The peak production of energy by coal power of "<<max<<"thousand kilowatt hours occurred in "<<en[pos].year;
}
//for petroleum
if(choice==2)
{
max=0;
for(i=0;i<19;i++)
{
if(en[i].petroleum>max)
{
max=en[i].petroleum;
pos=i;
}
}
cout<<" The peak production of energy by petroleum power of "<<max<<"thousand kilowatt hours occurred in "<<en[pos].year;
}
//natural gas
if(choice==3)
{
max=0;
for(i=0;i<19;i++)
{
if(en[i].naturalgas>max)
{
max=en[i].naturalgas;
pos=i;
}
}
cout<<" The peak production of energy by natural gas power of "<<max<<"thousand kilowatt hours occurred in "<<en[pos].year;
}
//Other gasees
if(choice==4)
{
max=0;
for(i=0;i<19;i++)
{
if(en[i].other>max)
{
max=en[i].other;
pos=i;
}
}
cout<<" The peak production of energy by Other gaases of "<<max<<"thousand kilowatt hours occurred in "<<en[pos].year;
}
//Nuclear
if(choice==5)
{
max=0;
for(i=0;i<19;i++)
{
if(en[i].nuclear>max)
{
max=en[i].nuclear;
pos=i;
}
}
cout<<" The peak production of energy by nuclear power of "<<max<<"thousand kilowatt hours occurred in "<<en[pos].year;
}
//hjydro-Electric Pumped Storage
if(choice==6)
{
max=0;
for(i=0;i<19;i++)
{
if(en[i].hydro>max)
{
max=en[i].hydro;
pos=i;
}
}
cout<<" The peak production of energy by hydro-Electric pumped Storage of "<<max<<"thousand kilowatt hours occurred in "<<en[pos].year;
}
//hydro-Eletric
if(choice==7)
{
max=0;
for(i=0;i<19;i++)
{
if(en[i].hydro2>max)
{
max=en[i].hydro2;
pos=i;
}
}
cout<<" The peak production of energy by hydro-Electric of "<<max<<"thousand kilowatt hours occurred in "<<en[pos].year;
}
//Biomass-Wood
if(choice==8)
{
max=0;
for(i=0;i<19;i++)
{
if(en[i].wood>max)
{
max=en[i].wood;
pos=i;
}
}
cout<<" The peak production of energy by Biomass-wood of "<<max<<"thousand kilowatt hours occurred in "<<en[pos].year;
}
//Biomass-Waste
if(choice==9)
{
max=0;
for(i=0;i<19;i++)
{
if(en[i].waste>max)
{
max=en[i].waste;
pos=i;
}
}
cout<<" The peak production of energy by Biomass-Waste of "<<max<<"thousand kilowatt hours occurred in "<<en[pos].year;
}
//Geothermal
if(choice==10)
{
max=0;
for(i=0;i<19;i++)
{
if(en[i].geothermal>max)
{
max=en[i].geothermal;
pos=i;
}
}
cout<<" The peak production of energy by geothermal power of "<<max<<"thousand kilowatt hours occurred in "<<en[pos].year;
}
//Solar
if(choice==11)
{
max=0;
for(i=0;i<19;i++)
{
if(en[i].solar>max)
{
max=en[i].solar;
pos=i;
}
}
cout<<" The peak production of energy by solar power of "<<max<<"thousand kilowatt hours occurred in "<<en[pos].year;
}
//Wind
if(choice==12)
{
max=0;
for(i=0;i<19;i++)
{
if(en[i].wind>max)
{
max=en[i].wind;
pos=i;
}
}
cout<<" The peak production of energy by wind of "<<max<<"thousand kilowatt hours occurred in "<<en[pos].year;
}
//total fossil
if(choice==13)
{
max=0;
for(i=0;i<19;i++)
{
if(en[i].totalfossil>max)
{
max=en[i].totalfossil;
pos=i;
}
}
cout<<" The peak production of energy by total fossil of "<<max<<"thousand kilowatt hours occurred in "<<en[pos].year;
}
//Total renewable
if(choice==14)
{
max=0;
for(i=0;i<19;i++)
{
if(en[i].totalrenew>max)
{
max=en[i].totalrenew;
pos=i;
}
}
cout<<" The peak production of energy by totalrenewable of "<<max<<"thousand kilowatt hours occurred in "<<en[pos].year;
}
//Grand total
if(choice==15)
{
max=0;
for(i=0;i<19;i++)
{
if(en[i].grandtotal>max)
{
max=en[i].grandtotal;
pos=i;
}
}
cout<<" The peak production of energy by grand total of "<<max<<"thousand kilowatt hours occurred in "<<en[pos].year;
}

break;
case 3:
outfile.open("outfile.dat");
cout<<" enter the any one of 16 categories ";
cout<<" 1. coal 2.Petroleum 3.Natural Gas 4.Other 5.Nuclear 6.Hydro 7.Hydro2 8.Biomass-wood 9.Biomass-Waste 10.Geothermal 11.Solar 12.Wind 13.Total fossil 14. Total Renewable 15.Grand Total";
cout<<" Enter ur choice:";
cin>>choice;
outfile.close();
break;
default:
cout<<" You have entered wrong option";
break;
}
}

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