Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C++ and with a result 3.18 PO3-03 Advance to Next Dav Before you start, we\'v

ID: 3604326 • Letter: I

Question

In C++ and with a result

3.18 PO3-03 Advance to Next Dav Before you start, we've decided to take a slightly different approach on this exercise. First, this exercise is completely optional Project #03 now consists of just 2 exercises, P03-01 and P03-02. So if you have completed those 2 exercises, you will have a 100 on Project #03. The purpose of this exercise is to serve as additional practice, AND allow you to make up for some missed work/low scores that you might currently have. For example: let's suppose you have a 0 on project #01 or project #02. Your score on this exercise can be used to replace one of those 0's. Let's suppose you have a 100 on project #01 and a 50 on project #02. If your score on this exercise is > 50, it can be used to replace that 50 on project #02. Finally, let's suppose you got 100 on both project #01 and project #02, but didn't finish one of the homeworks. If your score on this exercise is > than your lowest homework score, it can replace that lowest homework score So, the deal is that your score on this exercise will be used to replace a lower score on project #01 or project #02. If your score on this exercise does not replace a project score, then well try to use it to replace a lower homework score. If your score on this exercise does not replace a homework score, then we'll simply ignore itbut the exercise was good practice. Your score here will not impact future projects and homeworks-i.e. you cannot put it in the bank against the future. But it can be used to replace an earlier score. Most computer devices keep track of the date and time. When the clock strikes midnight, the computer has to advance to the next day. The exercise is to input a month and day, and simply advance to the next calendar day. For example, if the input is 9 and 14, denoting September 14th, then the program outputs 9/15, the next calendar day. Sounds easy enough. Write a complete C++ program to input a month (1..12) and a day (1.31), and output the next day. For example, if the input is 1 and 31, denoting the month and day: 31 then the output should be followed by a newline. Assume no leap years, and valid input. Another example: the input 12 31 should yield the output Hint: after you input the month and day, add 1 to the day using day day +1, and then use if statements to correct based on the month. You could use 12 if statements, or as little as 4

Explanation / Answer

#include <iostream>

using namespace std;

int main() {

int day, month;

//First of all get user input for month.

cout<<"Enter the month:"<<endl;

cin>>month;

//then get user input for day.

cout<<"Enter the day of the month:"<<endl;

cin>>day;

//We would now increase the day value by 1.

int newDay = day + 1;

//Now, we would check which month is this, if this is month Jan, Mar, May, Jul, Aug, Oct, Dec, then it has 31 days.

if ((month == 1) || (month == 3) || (month == 5) || (month == 7) || (month == 8) || (month == 10) || (month == 12)){

if ( newDay <= 31) {

//If the new day is lesser than 31, then we would simply print the month and newDay.

cout<<month<<"/"<<newDay;

} else{

//If the new day is greater than 31, then we would need to increase the month.

//Here we also need to check whether the current month is 12, so we would need to set the month to 1 again.

if (month == 12){

cout<<1<<"/"<<1;

}else {

cout<<month+1<<"/"<<1;

}

}

}

//Now, we would check which month is this, if this is month Apr,Jun,Sep, Nov then it has 30 days.

else if ((month == 4) || (month == 6) || (month == 9) || (month == 11)){

if ( newDay <= 30) {

//If the new day is lesser than 30, then we would simply print the month and newDay.

cout<<month<<"/"<<newDay;

} else{

//If the new day is greater than 30, then we would need to increase the month.

cout<<month+1<<"/"<<1;

}

}

//this check is specially for month of feb.

else if (month == 2){

if ( newDay <= 28) {

cout<<month<<"/"<<newDay;

} else{

cout<<month+1<<"/"<<1;

}

}

return 0;

}