Question

The Program:
You will put the different parts of the code in functions and call them from main(). You will also loop until no error on input, and do everything in a loop until the user says they want to quit.

Functions:
What calls what tree:
int main(int argc, char * argv[])
int getDaysInMonth(int year, int month) // returns the # of days in month for year
int getFebDays(int year) // returns # of days in February for this year
int getNumDays(int year, int month, int day) // returns # of days in year that given date is
int getFebDays(int year) // same function called again
Function details: Each function must follow the algorithm given below

int main(int argc, char * argv[]) // must use do while and while loops as documented
do
Ask the user to enter a year, a month and a day after 1600.
while checkInput(year, month , day) is error
Ask the user to enter a year, a month and a day after 1600.
end while error
print getNumDays(year, month, day)
Ask user do you want to quit y or n?
while user does not want to quit (does not enter y)

int checkInput(int year, int month, int day) // returns 0 if ok else -1
Print an error message if year is < 1600 or month is not 1 – 12 or day not 1 – correct number for that month and return -1
Else return 0 for no errors
// important only one return statement at the bottom of function
Use if statement for year and month being correct
Calls getDaysInMonth(int year, int month) and use if statement to see if days is correct.

int getDaysInMonth(int year, int month) // returns the # of days in month for year
You must use a switch statement on the month to find the number of days in that month with break statements for each case.
Calls getFebDays(int Year)

int getNumDays(int year, int month, int day) // returns # of days in year
Use another switch statement with no break statements to find the day of the year. 2/1 is 31 days of January plus 1 in February for a total of 32.
This must be switch with no break statements. Each month must add to the total only the days for that month. As demonstrated in class. No if or other statements on the single statement for each case that adds that month to the total.

case 11: retval += 30;
case 10: retval _= 31;
Calls getFebDays(int year) for case 2: retval += getFebDays(year);

Int getFebDays(int year) // returns # of days in February for this year

Rules:
You must use the functions as documented above with the same number of arguments.
Code for finding days in February must only be written once as a function and called twice.
You must use a while loop for input errors.
You must use a do while loop for doing everything again and again in main.
No variables declared outside of a function {   }
Correctly calculate the # of days in February based on the year.
One and only one return or exit in ANY FUNCTION at the bottom last line.
Any right } that is more than 3 lines away from its { must have a comment explaining what it is the end of. Even end of main.
If ( a < b) {
Statement1;
Statement2;
Statement3;
Statement4;
} // end a < b

Hints:
January 28 (1/28/16) is the 28th. Day of the year. February 3 is 31 + 3 or day 34. Days in Jan. plus 3.
Get your program working for one time. Write and test from the bottom up as in the what calls what tree above.
getFebDays write and test this first before doing anything else
Then write and test ONLY getDaysInMonth which of course calls getFebDays
Then write and test ONLY checkInput which calls getDaysInMonth
And so forth. One thing at a time build on what already works.
DO NOT try to write the whole program and then test it.
Exactly Which Years Are Leap Years?
We add a Leap Day on February 29, almost every four years. The leap day is an extra, or intercalary, day and we add it to the shortest month of the year, February.
In the Gregorian calendar three criteria must be taken into account to identify leap years:
* The year can be evenly divided by 4;
* If the year can be evenly divided by 100, it is NOT a leap year, unless;
* The year is also evenly divisible by 400. Then it is a leap year.
This means that in the Gregorian calendar, the years 2000 and 2400 are leap years, while 1800,1900, 2100, 2200, 2300 and 2500 are NOT leap years.

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

#include <stdio.h>
#include <stdlib.h>

#define ERROR -1
#define NO_ERROR 0

int checkInput(int year, int month, int day);
int getDaysInMonth(int year, int month) ;
int getNumDays(int year, int month, int day);
int getFebDays(int year);

/*
*
*/
int main(int argc, char** argv) {
   
    /**
    *    do
    * Ask the user to enter a year, a month and a day after 1600.
    * while checkInput(year, month , day) is error
    * Ask the user to enter a year, a month and a day after 1600.
    * end while error
    * print getNumDays(year, month, day)
    * Ask user do you want to quit y or n?
    * while user does not want to quit (does not enter y)
    */
    char option;
    int year, month, day;
    do{...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Assisting Tutor

Related Homework Solutions

Twenty-One Card Game in C++
Homework Solution
$63.00
Computer Science
C++ Programming
Twenty-One
Blackjack
Card Game
Loops
Conditions
Functions
Arguments
Dealers
Players
Counters
Decks
Users
Probability Problems Using C++ Programming
Homework Solution
$18.00
Computer Science
C++ Programming
Probability
Estimations
Simulations
Loops
Random Numbers
Guessing
Theoretical Solutions
Passing Exams
Multiple Choice Questions
C++ Programming Problems
Homework Solution
$30.00
Computer Science
C++
Animals
Members
Classes
Age
Input
Prototypes
Lists
Validation
Data
Statements
Variables
C++ Programming Problems
Homework Solution
$63.00
Computer Science
C++ Programming
Containers
Ordered Lists
Codewords
Functions
Integers
Symbols
Overloaded Operators
Distances
Dynamic Arrays in C++
Homework Solution
$50.00
Computer Science
C++ Programming
Dynamic Arrays
Pointers
Functions
Declarations
Constructors
Values
Elements
Statements
Orders
C++ Programming Problems
Homework Solution
$70.00
Computer Science
C++ Programming
Characters
Encrypted Messages
ASCII
Values
Users
Strings
Binary
Recursive Functions
Algorithms
Get help from a qualified tutor
Live Chats