Textbook Used: Introduction to Programming with C++ (2nd Edition), Y. Daniel Lia
ID: 3623011 • Letter: T
Question
Textbook Used: Introduction to Programming with C++ (2nd Edition), Y. Daniel Liang,Pearson/Prentice Hall, 2009.
Write a program called, A2, that:
1. Reads in the year, month, and day of the year. Check these values to make sure that theyare valid. If the user enters invalid data, display an error message and have them correct theinput until it is valid {Hint: use a loop}. Do not forget that each month has a different number ofdays. Also, account for the fact that February has 28 or 29 days depending if it is a leap year ornot (see section 3.12 of your textbook) {Hint: enter the year before the day of the month}.
2. Use Zeller's congruence (see problem 3.8) to calculate the day of the week. Use an enumto clarify your code so that 0: SATURDAY, 1: SUNDAY etc. Do not use literal constants in yourcode.
3. Use enum's to represent the months, do not use literal constants in the code {Hint: theuser is going to enter in an integer month but Zeller's congruence uses non-standard values forJanuary and February}.
4. Print the “long format” of the date, for example, 2001-01-21 should be output like“Friday January 21st, 2011” Your program must also display the correct ending to the day of themonth, for example “st” for 1, “nd” for 2, “rd” for 3 and “th” for everything else.
Explanation / Answer
#include #include #include using namespace std; //prototypes int EnterDate(int&, int&, int&); int testDate(int, int, int); void outputDate(int, int, int); bool isLeapYear(int); int main() { int month, day, year; int returnValue = 0; while( returnValue != -4) { returnValue = EnterDate(month, day, year); switch(returnValue) { case -1: coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.