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

Please I need help with this. I was already given a starting program, now I just

ID: 3851859 • Letter: P

Question

Please I need help with this.

I was already given a starting program, now I just need to complete it. I am writing in C++ language.

Here is the given program:

#include <iostream>

#include <string>

const int CARBON_MONOXIDE = 1;

const int HYDROCARBON = 2;

const int NITROGEN_OXIDE = 3;

const int NONMETHANE_HYDROCARBON = 4;

const int QUIT = 0;

const double CARBON_MONOXIDE_ALLOWED1 = 3.4;

const double CARBON_MONOXIDE_ALLOWED2 = 4.2;

const double HYDROCARBON_ALLOWED1 = 0.31;

const double HYDROCARBON_ALLOWED2 = 0.39;

const double NITROGEN_OXIDE_ALLOWED1 = 0.4;

const double NITROGEN_OXIDE_ALLOWED2 = 0.5;

const double NONMETHANE_HYDROCARBON_ALLOWED1 = 0.25;

const double NONMETHANE_HYDROCARBON_ALLOWED2 = 0.31;

using namespace std;

void outputMenu();

int main(int argc, char *argv[])

{

int pollutant;

int odometer;

double gramsPerMile;

  

outputMenu();

cin >> pollutant;

while (pollutant != QUIT)

{

cout << endl;

cout << "Enter grams emitted per mile: ";

cin >> gramsPerMile;

cout << "Enter odometer reading: ";

cin >> odometer;

  

switch (pollutant)

{

case CARBON_MONOXIDE:

break;

  

case HYDROCARBON:

break;

  

case NITROGEN_OXIDE:

break;

  

case NONMETHANE_HYDROCARBON:

break;

}

outputMenu();

cin >> pollutant;

}

cin.ignore();

cin.get();

}

void outputMenu()

{

cout << endl;

cout << "(" << CARBON_MONOXIDE << ") Carbon monoxide" << endl;

cout << "(" << HYDROCARBON << ") Hydrocarbons" << endl;

cout << "(" << NITROGEN_OXIDE << ") Nitrogen oxides" << endl;

cout << "(" << NONMETHANE_HYDROCARBON << ") Non-methane hydrocarbons" << endl;

cout << "(" << QUIT << ") Quit" << endl;

  

cout << "Enter choice: ";

}

These are what the professor wants us to do:

1. Not change any of the given code.

2. Use the defined constant variables for any constant values in your program.

3. Create additional constant variables to use when checking the mileage boundaries (50000 miles and 100000 miles).

4. Output an indication that an invalid odometer reading has been entered (outside of the range of 0-100000).

5. Use the switch statement started in the program for your decision structure.

6. Have at least one other user defined function. One possibility is the following function that determines the allowable level for a particular pollutant:

double getAllowableLevel (double gramsPerMileAllowed1, double gramsPerMileAllowed2, int odometer);

Thank you so much in advance.


Specification Complete a program that has a user enter a pollutant choice, a number of grams of the pollutant emitted per mile, and an odometer reading (0-100000) Output an indication of whether or not they are compliant with the following regulations: first 50,000 miles second 50,000 miles carbon monoxide 3.4 grams/mile 4.2 grams/mile 0.31 grams/mile 0.39 grams/mile hydrocarbons 0.4 grams/mile 0.5 grams/mile nitrogen oxides non-methane hydrocarbons 0.25 grams/mile 0.31 grams/mile A sample run is shown here: (1 Carbon monoxide (2 Hydrocarbons X3 Nitrogen oxides (4 Non-nethane hydrocarbons CO> Quit Enter choice: 1 Enter grans en itted per mile: 3.2 Enter odometer reading 77000 Enissions within allowable level of 4.2 grans nile X1 Carbon monoxide (2 Hydrocarbons X3 Nitrogen oxides C4> Non methane hydrocarbons CO> Quit Enter choice: 2 Enter grans enitted per mile .25 Enter odometer reading 23456 sions within allowable level of 0.31 grams nile X1 arbon monoxide Hydrocarbons X3 oxides K4> Non-nethane hydrocarbons CO> Quit Enter choice: 3 Enter grans enitted per mile Enter odometer reading 100100 Mileage 100100 must be within 0-100000 miles (1 arbon monoxide X2 Hydrocarbons C3> Nitrogen oxides K4> Non-methane hydrocarbons Quit Enter choice:

Explanation / Answer

// C++ code
#include <iostream>
#include <string>
const int CARBON_MONOXIDE = 1;
const int HYDROCARBON = 2;
const int NITROGEN_OXIDE = 3;
const int NONMETHANE_HYDROCARBON = 4;
const int QUIT = 0;
const double CARBON_MONOXIDE_ALLOWED1 = 3.4;
const double CARBON_MONOXIDE_ALLOWED2 = 4.2;
const double HYDROCARBON_ALLOWED1 = 0.31;
const double HYDROCARBON_ALLOWED2 = 0.39;
const double NITROGEN_OXIDE_ALLOWED1 = 0.4;
const double NITROGEN_OXIDE_ALLOWED2 = 0.5;
const double NONMETHANE_HYDROCARBON_ALLOWED1 = 0.25;
const double NONMETHANE_HYDROCARBON_ALLOWED2 = 0.31;
const int LIMIT1 = 50000;
const int LIMIT2 = 100000;

using namespace std;
void outputMenu();
double getAllowableLevel (double gramsPerMileAllowed1, double gramsPerMileAllowed2, int odometer);
int main(int argc, char *argv[])
{
int pollutant;
int odometer;
double gramsPerMile;
  
outputMenu();
cin >> pollutant;
while (pollutant != QUIT)
{
cout << endl;
cout << "Enter grams emitted per mile: ";
cin >> gramsPerMile;
cout << "Enter odometer reading: ";
cin >> odometer;

if(odometer > 100000 || odometer < 0)
{
   cout << "Mileage " << odometer << " must be within 0-100000 miles ";
   continue;
}

switch (pollutant)
{
case CARBON_MONOXIDE:
   cout << " Emissions within allowable level of " << getAllowableLevel(CARBON_MONOXIDE_ALLOWED1, CARBON_MONOXIDE_ALLOWED2, odometer) << " grams/mile " << endl << endl;
   break;
  
case HYDROCARBON:
   cout << " Emissions within allowable level of " << getAllowableLevel(HYDROCARBON_ALLOWED1, HYDROCARBON_ALLOWED2, odometer) << " grams/mile " << endl << endl;
   break;
  
case NITROGEN_OXIDE:
   cout << " Emissions within allowable level of " << getAllowableLevel(NITROGEN_OXIDE_ALLOWED1, NITROGEN_OXIDE_ALLOWED2, odometer) << " grams/mile " << endl << endl;
   break;
  
case NONMETHANE_HYDROCARBON:
   cout << " Emissions within allowable level of " << getAllowableLevel(NONMETHANE_HYDROCARBON_ALLOWED1, NONMETHANE_HYDROCARBON_ALLOWED2, odometer) << " grams/mile " << endl << endl;
   break;
}
outputMenu();
cin >> pollutant;
}

// cin.ignore();
// cin.get();

return 0;

}

void outputMenu()
{
cout << endl;
cout << "(" << CARBON_MONOXIDE << ") Carbon monoxide" << endl;
cout << "(" << HYDROCARBON << ") Hydrocarbons" << endl;
cout << "(" << NITROGEN_OXIDE << ") Nitrogen oxides" << endl;
cout << "(" << NONMETHANE_HYDROCARBON << ") Non-methane hydrocarbons" << endl;
cout << "(" << QUIT << ") Quit" << endl;
  
cout << "Enter choice: ";
}

double getAllowableLevel (double gramsPerMileAllowed1, double gramsPerMileAllowed2, int odometer)
{
   if(odometer <= LIMIT1)
   {
       return gramsPerMileAllowed1;
   }
   else if(odometer <= LIMIT2)
   {
       return gramsPerMileAllowed2;
   }

}


/*
output:


(1) Carbon monoxide
(2) Hydrocarbons
(3) Nitrogen oxides
(4) Non-methane hydrocarbons
(0) Quit
Enter choice: 1

Enter grams emitted per mile: 3.2
Enter odometer reading: 77000

Emissions within allowable level of 4.2 grams/mile


(1) Carbon monoxide
(2) Hydrocarbons
(3) Nitrogen oxides
(4) Non-methane hydrocarbons
(0) Quit
Enter choice: 2

Enter grams emitted per mile: 0.25
Enter odometer reading: 23456

Emissions within allowable level of 0.31 grams/mile


(1) Carbon monoxide
(2) Hydrocarbons
(3) Nitrogen oxides
(4) Non-methane hydrocarbons
(0) Quit
Enter choice: 3

Enter grams emitted per mile: 0.7
Enter odometer reading: 100100
Mileage 100100 must be within 0-100000 miles

Enter grams emitted per mile: 0.7
Enter odometer reading: 16478

Emissions within allowable level of 0.4 grams/mile


(1) Carbon monoxide
(2) Hydrocarbons
(3) Nitrogen oxides
(4) Non-methane hydrocarbons
(0) Quit
Enter choice: 0


*/