Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Starter Code: #include int main(){ char input[30]; int i; int dates; int day, year, month; printf(Enter 'month-day year' : ); fgets(input, 30, stdin); /*

image text in transcribedimage text in transcribedStarter Code:

#include  int main(){ char input[30]; int i; int dates; int day, year, month; printf("Enter 'month-day year' : " ); fgets(input, 30, stdin); /* read in the whole line */ while ( ) { /* manipulate the input, count days and display */ // read again printf("Enter 'month-day year': " ); fgets(input, 30, stdin); /* read in the whole line */ } return 0; } int countDays(int y, int m, int d){ }
3.2 Implementation Download file lab 4C . c and start from there. The program uses fgets( ) to read in a whole line. Don't modify the existing codes. Implement the function int countDays (int year, int month, int day) which calculates how many days have elapsed since the start of the year. For simplicity, assume that there are 31 days in Jan, Mar, May, July, Sep and Nov, and there are 30 days itn April, June, Aug, Oct and Dec. There are 29 days in Feb if the year is a leap year, and 28 days in Feb if the year is not leap year. Define function isLeap (int year) as you did for lab 2. Put the definition of this function in another file named leap.c. Implement the while conditions, checking if input isquit. Display the output as xx days of year xxx have elapsed Thoughts and Hints: How to get year, month and date information from the line of string? That is, how to tokenize a string? How about sscanf mentioned in class? In implementing countDays , instead of checking month with lots if... elseif.. elseif... elseif... Or if 1.. 1....), can you use an arithmetic operator to simplify the code? When fgets reads in a line, it appends a new line character at the end (before \0). For example, input a line is stored as'a''''1' 'i' 'n' 'e''n' '0 where are some other values('10' or random values). Be careful when checking if the input is quit. 3.3 Sample Inputs/Outputs: (ONE blank link between each interaction/iteration): red 339 % a . out Enter 'month-date year': 1-1 2010 1 days of year 2010 have elapsed Enter 'month-date year': 8-8 2011 220 days of year 2011 have elapsed Enter 'month-date year': 8-8 2012 221 days of year 2012 have elapsed Enter 'month-date year': 8-8 2016 221 days of year 2016 have elapsed Enter 'month-date year': 10-1 2010 274 days of year 2010 have elapsed Enter 'month-date year': 10-1 2012 275 days of year 2012 have elapsed Enter 'month-date year': 5-4 2017 124 days of year 2017 have elapsed Enter 'month-date year': 5-4 2012 125 days of year 2012 have elapsed 3.2 Implementation Download file lab 4C . c and start from there. The program uses fgets( ) to read in a whole line. Don't modify the existing codes. Implement the function int countDays (int year, int month, int day) which calculates how many days have elapsed since the start of the year. For simplicity, assume that there are 31 days in Jan, Mar, May, July, Sep and Nov, and there are 30 days itn April, June, Aug, Oct and Dec. There are 29 days in Feb if the year is a leap year, and 28 days in Feb if the year is not leap year. Define function isLeap (int year) as you did for lab 2. Put the definition of this function in another file named leap.c. Implement the while conditions, checking if input isquit. Display the output as xx days of year xxx have elapsed Thoughts and Hints: How to get year, month and date information from the line of string? That is, how to tokenize a string? How about sscanf mentioned in class? In implementing countDays , instead of checking month with lots if... elseif.. elseif... elseif... Or if 1.. 1....), can you use an arithmetic operator to simplify the code? When fgets reads in a line, it appends a new line character at the end (before \0). For example, input a line is stored as'a''''1' 'i' 'n' 'e''n' '0 where are some other values('10' or random values). Be careful when checking if the input is quit. 3.3 Sample Inputs/Outputs: (ONE blank link between each interaction/iteration): red 339 % a . out Enter 'month-date year': 1-1 2010 1 days of year 2010 have elapsed Enter 'month-date year': 8-8 2011 220 days of year 2011 have elapsed Enter 'month-date year': 8-8 2012 221 days of year 2012 have elapsed Enter 'month-date year': 8-8 2016 221 days of year 2016 have elapsed Enter 'month-date year': 10-1 2010 274 days of year 2010 have elapsed Enter 'month-date year': 10-1 2012 275 days of year 2012 have elapsed Enter 'month-date year': 5-4 2017 124 days of year 2017 have elapsed Enter 'month-date year': 5-4 2012 125 days of year 2012 have elapsed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions