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

I need help writting my Code, I need to keep it on a cs 1428 beginner level. Wri

ID: 3760928 • Letter: I

Question

I need help writting my Code, I need to keep it on a cs 1428 beginner level.

Write a menu driven C++ program that prints the day number of the year, given the date in the form of month-day-year. For example, if the input is 1-1-2006, then the day number is 1. If the input is 12-25-2006, the day number is 359. The program should check for a leap year. A year is leap if it is divisible by 4 but not divisible by 100. For example, 1992, and 2008 are divisible by 4 and not divisible by 400. A year that is divisible by 100 is a leap year if it is also divisble by 400. For example, 1600 and 200 are divisble by 400, however, 1800 is not a leap year because 1800 is not divisble by 400. Program terminates when the user type in n or N.

The program must contain these 7 functions:

1. A function that returns a boolean value indicating whether or not the day entered is a function between 1 and 31.

2. A function that returns a boolean value indicating whether or not the month entered is between 1 and 12.

3. A function that returns a boolean value indicating whether or not the year entered is greater than 0 and less than or equal to current year.

4 A function that returns a boolean value indicating whether or not the year entered is a leap year.

5.  A function that returns an integer value indicating the number of days in a month.

6.  A function that returns a string value indicating the name of month.

7.  A function that returns an integer value indicating actual number of day that is equivalent to day, month, and year that is entered.

Please help we have not gone over material connected to what he is wanting to do in this program. I have started the program and am reading further in the book to have a better understanding.

Explanation / Answer

CODE :

#include<stdio.h>
#include<iostream>
#include<string>
#include<time.h>
using namespace std;


bool checkDay(int day)
{
if(day>0&&day<=31)
{
  return true;
}
else
  return false;
}

bool checkMonth(int mm)
{
if(mm>0&&mm<=12)
{
  return true;
}
else
  return false;
  
}

bool checkYear(int yy)
{
time_t today = time(NULL);
struct tm *aTime = localtime(&today);
int currentYear = aTime->tm_year + 1900;

if(yy>0&&yy<=currentYear)
{
  return true;
}
else
  return false;
}

bool isleap(int yy)
{
if ((yy % 4 == 0) && !(yy % 100 == 0))
  return true;
else if (yy % 400 == 0)
  return true;
else
  return false;
}

int numDays(int mm, int yy)
{
int day;
if (mm == 4 || mm == 6 || mm == 9 || mm == 11)
  day= 30;
  
else if (mm == 02)
{
  bool leap = isleap(yy);

  if (leap == 0)
    day= 29;
  else
    day= 29;
}

else
day= 31;

return day;
}

string monthName(int mm)
{
string month;
if(mm==1)
{
  month= "January";
}
if(mm==2)
{
  month= "February";
}
if(mm==3)
  month= "March";
if(mm==4)
  month= "April";
if(mm==5)
  month= "May";
if(mm==6)
  month= "June";
if(mm==7)
  month= "July";
if(mm==8)
  month= "August";
if(mm==9)
  month= "September";
if(mm==10)
  month= "October";
if(mm==11)
  month= "November";
if(mm==12)
  month= "December";
  
cout<<"Month is : "<<month;
return month;
}

int exactDay(int dd,int mm, int yy)
{
int days=dd;
if(mm>1)
{
  for(int i=1;i<mm;i++)
  {
   days=days+numDays(i,yy);
  }
}
return days;
}
int main()
{
char date[10];
int dd,mm,yy;
char ch;
string month;
int day=0,exDay=0;

    cout<<"Enter Date in (mm-dd-yyyy) format : ";
    cin>>date;
    char a = '4';
    int d1= date[3] - '0';
    int d2=date[4] - '0';
    dd=d1*10+d2;

    int m1=date[0]-'0';
    int m2=date[1]-'0';
    mm=m1*10+m2;

    int y1=date[6]-'0';
    int y2=date[7]-'0';
    int y3=date[8]-'0';
    int y4=date[9]-'0';

    yy=y1*1000+y2*100+y3*10+y4;
while(true)
{
  cout<<" Menu : a. Check Day b. Check Month c. Check Year d. Check Leap Year e. Get Days in the month f. Get Month Name g. Get Exact Days Enter 'N' to Exit ";
  cin>>ch;
  switch(ch)
  {
   case 'a':
   case 'A':
    if(!checkDay(dd))
    {
     cout<<"Invalid Day! ";
    }
    else
     cout<<"Valid Day! ";
     break;
     
   case 'b':
   case 'B':
    if(!checkMonth(mm))
     cout<<"Invalid Month! ";
    else
     cout<<"Valid Month! ";
     break;
   case 'c':
   case 'C':
    if(!checkYear(yy))
     cout<<"Invalid Year! ";
    else
     cout<<"Valid Year! ";
     break;
     
   case 'd':
   case 'D':
    if(isleap(yy))
     cout<<"Leap Year ";
    else
     cout<<"Not Leap Year ";
     break;
   case 'e':
   case 'E':
    day=numDays(mm,yy);
    cout<<" Days :"<<day;
    break;
   case 'f':
   case 'F':
    month=monthName(mm);
    break;
   case 'g':
   case 'G':
    exDay=exactDay(dd,mm,yy);
    cout<<" Total Days : "<<exDay;
    break;
   case 'n':
   case 'N':
    return 0;
    break;
   default: cout<<"Wrong Input! ";
    break;
  }
}
}

OUTPUT :