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

Hello, I am working on a C++ program. My tutor and I am also working on this pro

ID: 3692344 • Letter: H

Question

Hello, I am working on a C++ program. My tutor and I am also working on this program. I am just trying to figure out how it should be set up. Thank You

Write a program that prints the days in month, given the date in the form month-day-year. For example, if the input is 1-1-2006, the days in the month 31; if the input is 2-25-2000, the days in the month is 29 since the 200 is leap year. The program should check for a leap year. A year is a leap year if it is divisible by 4, but not divisible by 100. For example, 1992 and 2008 are divisible by 4, but not by 100. A year that is divisible by 100 is a leap year if it is also divisible by 400. For example, 1600 and 2000 are divisible by 400. How- ever, 1800 is not a leap year because 1800 is not divisible by 400. Use two value-returning functions, isLeapYear, and daysInMonth. The  isLeapYear function return whether the input year is leap or not and the  daysInMonth function returns the days of each month.

Your program has to repeat until user provide a certain sign to stop.

Explanation / Answer

Here is the code for you:

#include <iostream>
#include <sstream>
using namespace std;
int main()
{
string str;
int month, day, year;
//stringstream ss;
cout<<"Enter the date in MM-DD-YYYY format: ";
getline(cin, str, '-');
stringstream ss1(str);
ss1 >> month;
  
getline(cin, str, '-');
stringstream ss2(str);
ss2 >> day;
  
getline(cin, str);
stringstream ss3(str);
ss3 >> year;
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: cout<<"The days in a month is: "<<31<<endl; break;
case 4:
case 6:
case 9:
case 11: cout<<"The days in a month is: "<<30<<endl; break;
case 2: if((!(year % 4) && year % 100) || !(year % 400))
       cout<<"The days in a month is: "<<29<<endl;
       else
       cout<<"The days in a month is: "<<28<<endl;
       break;
default: cout<<"Invalid month"<<endl;      
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote