Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am getting errors in this code and im not sure why. I have the questions first then the code at the bottom. Please do

I am getting errors in this code and im not sure why. I have the questions first then the code at the bottom. Please do in clion c99 and add the printf statements. thank you
Q1: How Many Days ...
This problem is based on Chapter 4 Problem #7: Given a month, day, and year, calculate how many days
into the year that date is. This is the framework:
1// c h a p t e r 4 q u e s t i o n 7
2 i n t l e a p ( i n t y e a r ) ;
3 i n t day_number ( i n t month , i n t day , i n t y e a r ) ;
The problem is really only asking you to build the day_number function, but, its easier to build that if we
have a function that tells us whether a given year is a leap year. Therefore, build the leap function first and
have it return 1 if the year is a leap year and zero otherwise. Then, use that to build the day_number function.
Q2: Pollutants
This problem is based on Chapter 4 Problem #8. Given the pollutant type, how much is being emitted, and
the odometer reading of the car, you are supposed to calculate whether the car is legal (within the limits) or
illegal (exceeding the limits)
1// c h a p t e r 4 q u e s t i o n 8
2 t y p e d e f enum p o l l u t a n t _ t y p e { c a r b o n _ m o n o x i d e , h y d r o c a r b o n s ,
3 n i t r o g e n _ o x i d e s , n o n m e t h a n e _ h y d r o c a r b o n s } p o l l u t a n t _ t y p e ;
4 t y p e d e f enum p o l l u t a n t _ l e v e l _ t y p e { l e g a l , i l l e g a l } p o l l u t a n t _ l e v e l _ t y p e ;
5 p o l l u t a n t _ l e v e l _ t y p e e m i s s i o n s ( p o l l u t a n t _ t y p e p , d o u b l e g r a m s _ p e r _ m i l e , i n t o d o m e t e r ) ;
You see two typedefs here: one for a enum of the types of pollutants and one for an enum for legal or illegal.
Line 4 is the specification of the function you are to build. It has three parameters:
1. pollutant_type p: one of the pollutant_type values
2. double gram_per_mile: the rate the car is emitting that pollutant
3. int odomoter: how far the car has been driven
Your job is to make the function return either illegal or legal based on the table in the book. Note that the
values in the table ar
int leap(int year){
if (year %4==0){
if (year %100==0){
if (year %400==0){
return 1; // Leap year
} else {
return 0; // Not a leap year
}
} else {
return 1; // Leap year
}
} else {
return 0; // Not a leap year
}
}
int day_number(int month, int day, int year){
int days_in_month[]={31,28,31,30,31,30,31,31,30,31,30,31};
int day_number =0;
for (int i =1; i < month; i++){
day_number += days_in_month[i -1];
}
if (leap(year) && month >2){
day_number +=1; // Account for leap day in February
}
day_number += day;
return day_number;
}
enum pollutant_level_type emissions(enum pollutant_type p, double grams_per_mile, int odometer){
double limit;
if (odometer <=50000){
switch (p){
case carbon_monoxide:
limit =0.4;
break;
case hydrocarbons:
limit =0.4;
break;
case nitrogen_oxides:
limit =0.4;
break;
case nonmethane_hydrocarbons:
limit =0.25;
break;
}
} else {
switch (p){
case carbon_monoxide:
limit =0.31;
break;
case hydrocarbons:
limit =0.39;
break;
case nitrogen_oxides:
limit =0.5;
break;
case nonmethane_hydrocarbons:
limit =0.31;
break;
}
}
if (grams_per_mile > limit){
return illegal;
} else {
return legal;
}
}

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

Graph Databases New Opportunities For Connected Data

Authors: Ian Robinson, Jim Webber, Emil Eifrem

2nd Edition

1491930896, 978-1491930892

More Books

Students also viewed these Databases questions

Question

What are the Five Phases of SDLC? Explain each briefly.

Answered: 1 week ago

Question

How can Change Control Procedures manage Project Creep?

Answered: 1 week ago