Question
Write a C program (intro level) that calculate car emmisions
4.2 Car emissions Gas-powered cars emit various types of pollutants: 1. Carbon monoxide (CO), an odorless and colorless gas that is highly poisonous if breathed by humans. 2. Hydrocarbons (HC), burned or partially burned raw fuel, which are a major contributor to smog. 3. Nitrogen oxides (NOx), which is generated when nitrogen in the air reacts with oxygen at the high temperature and pressure inside the engine. 4. Non-methane hydrocarbons (NMHC), the part of the hydrocarbons that doesnt include methane emissions In an effort to fight the emissions of such pollutants in the atmosphere, the city of Davis wants to enforce emissions caps for cars. Since cars tend to exhibit different properties, whether they relatively new (i.e. less than or equal to 50,000 miles) or old, the city defined the following table: Limit for old car 4.2 grams/mile 0.39 grams/mile 0.5 grams/mile 0.31 grams/mile Pollutant number CO HC NOx NMHC Limit for new car 3.4 grams/mile 0.31 grams/mile 0.4 grams/mild 0.25 grams/mile 4
media%2F93f%2F93fa2ea2-1429-415f-bf11-e9
0 0
Add a comment Improve this question Transcribed image text
Answer #1

//Code to copy
//main.c
//include header files
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
//start of main method
int main(int argc,char *argv[])
{

   //check if number of arguments are less than 4
   if(argc<4)
   {
       getch();
       return 1;
   }

   //parset from strign to integer and float
   int emissions_type=atoi(argv[1]);
   float grams_omitted=atof(argv[2]);
   int odo_reading=atoi(argv[3]);


   //check if emission is out of range
   if(emissions_type<1 || emissions_type>4)
   {
       printf("Unknown pollutant\n");
       getch();
       return 1;
   }

   //check if emission type is 1
   if(emissions_type==1)
   {
       if(odo_reading<=50000)
       {
           if(grams_omitted>3.4)
               printf("Emissions exceed permitted level of 3.4 grams/mile\n");
           else
               printf("Emissions do not exceed permitted level of 3.4 grams/mile\n");
       }
       else
       {
           if(grams_omitted>4.2)
               printf("Emissions exceed permitted level of 4.2 grams/mile\n");
           else
               printf("Emissions do not exceed permitted level of 4.2 grams/mile\n");
       }
   }
   //check if emission type is 2
   else if(emissions_type==2)
   {
       if(odo_reading<=50000)
       {
           if(grams_omitted>0.31)
               printf("Emissions exceed permitted level of 0.31 grams/mile\n");
           else
               printf("Emissions do not exceed permitted level of 0.31 grams/mile\n");
       }
       else
       {
           if(grams_omitted>0.39)
               printf("Emissions exceed permitted level of 0.39 grams/mile\n");
           else
               printf("Emissions do not exceed permitted level of 0.39 grams/mile\n");
       }
   }
   //check if emission type is 3
   else if(emissions_type==3)
   {
       if(odo_reading<=50000)
       {
           if(grams_omitted>0.4)
               printf("Emissions exceed permitted level of 0.4 grams/mile\n");
           else
               printf("Emissions do not exceed permitted level of 0.4 grams/mile\n");
       }
       else
       {
           if(grams_omitted>0.5)
               printf("Emissions exceed permitted level of 0.5 grams/mile\n");
           else
               printf("Emissions do not exceed permitted level of 0.5 grams/mile\n");
       }
   }
   //check if emission type is 4
   else if(emissions_type==4)
   {
       if(odo_reading<=50000)
       {
           if(grams_omitted>0.25)
               printf("Emissions exceed permitted level of 0.25 grams/mile\n");
           else
               printf("Emissions do not exceed permitted level of 0.25 grams/mile\n");
       }
       else
       {
           if(grams_omitted>0.31)
               printf("Emissions exceed permitted level of 0.31 grams/mile\n");
           else
               printf("Emissions do not exceed permitted level of 0.31 grams/mile\n");
       }
   }

   getch();
   return 0;
}

Sample Output:

S(TargetPath) 2 0.35 40112 Command Command Arguments

Emissions exceed permitted level of e.31 grams/mile

Command S(TargetPath) 3 0.45 63987 Command Arquments

Emissions do not exceed permitted level of e.5 grams/mile

Add a comment
Know the answer?
Add Answer to:
Write a C program (intro level) that calculate car emmisions 4.2 Car emissions Gas-powered cars emit...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. Match the definitions at the left with the most appropriate term on the right. NOTE:...

    1. Match the definitions at the left with the most appropriate term on the right. NOTE: A given term in the right-hand column may or may not be used more than once. _An example of a secondary air pollutant A. PM2.5 Estimated number of children worldwide under 5 years of age B. PM10 that are killed by air pollution each year Geographic region where about two-thirds of all air pollution C. Carbon monoxide (CO) related deaths occur D. Nitrogen dioxide...

  • QUESTION 3 The textbook discusses 3 types of environmental degradation affecting the environment. Below, please match...

    QUESTION 3 The textbook discusses 3 types of environmental degradation affecting the environment. Below, please match each type of degradation discussed to the type of consequence suggested in the textbook. (Answer based on what the book says, not based on your personal opinion.) Air pollution A., is killinig humans 8,..isklin the earth Land poliution Water pollution address chiticar Watel Air Pollution Air pollution occurs when the release of materials to the atmosphere cannot be safelv disposed of by natural processes....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT