See attached c program I need to continue on with this progr

See attached c++ program. I need to continue on with this program building on it to cread a top-level function named dayOfWeek (int month, int day, int year). The function should add validation code to the function that tests if any ofthe inputs are invalid. If so, the function should return -1 as the day of the week. in the mand function, I need to write a test driver that checks if dayOfWeek is returning the correct values. The set of test cases should includ at least two cases with invalid inputs. The next stepf I need to do us ot allow the user to print out a calendar for any given year to the screen and to the file.

/C++ program that prompts user to enter

//the month value , day value and year value

//and print the day of a weeek.

#include <iostream>

#include <string>

using namespace std;

//function prototypes

void getInput(int &month, int &day, int &year);

bool isLeapYear(const int year);

int getCenturyValue(const int year);

int getYearValue(const int year);

int getMonthValue(const int month, const int year);

int dayOfWeek(const int month, const int day, const int year);

//enumeration for month names

enum Months {None, January, February, March, April, May, June, July, August, September, October, November, December};

//string array for names of a week

string weekDays[] = {\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"};

//starting point of program execution

int main()

{

  

//declare and initialize the integer varibales

int month = 0;

int day = 0;

int year = 0;

  

//call getInput with three reference parameters to get input from user

getInput(month, day, year);

//Call dayOfWeek with month,day,year on WeekDays to get the week day

//dayOfWeek returns the index for the weekDays

cout << \"The day of the week is \"<<weekDays[dayOfWeek(month, day, year)] <<endl;

  

system(\"pause\");

return 0;

  

  

}

//Retuns true if the year is leap year

bool isLeapYear(const int year)

{

if (0 == (year % 400) || (0 == (year % 4) && (year % 100)))

return true;

else

return false;

}

//The method getCenturyValue that accepts an integer value year

//and returns the two digit integer value

int getCenturyValue(const int year)

{

return (2 * (3 - div(year / 100, 4).rem));

}

//The method returns the two digit value of a year

int getYearValue(const int year)

{

int mod = year % 100;

//div returns the value after dividing by 4 and gets the quotient

//and add the remainder on dividing by 100

return (mod + div(mod, 4).quot);

}

//The method getMonthValue that accepts the month and year

//values and returns month value

int getMonthValue(const int month, const int year)

{

switch (month)

{

case January:

if (isLeapYear(year))

return 6;

case October:

return 0;

case May:

return 1;

case August:

return 2;

case February:

if (isLeapYear(year))

return 2;

case March:

case November:

return 3;

case June:

return 4;

case September:

case December:

return 5;

case April:

case July:

return 6;

default:

return -1;

}

}

//The method dayOfWeek that accepts three inputs month and day and year

//and calls the getMonthValue and getYearValue and getCenturyValue to get the day of week

//as per given method.

int dayOfWeek(const int month, const int day, const int year)

{

return div(day + getMonthValue(month, year) + getYearValue(year) + getCenturyValue(year), 7).rem;

}

//The method getInput accept three reference varaibles

//and accepts the valid numbers

void getInput(int &month, int &day, int &year)

{

do

{

cout << \"Enter the month (1-12): \";

cin>>month;

if(month<0||month>12)

cout<<\"Invalid year\"<<endl;

  

}while(month<0 || month>12);

  

do

{

  

cout << \"Enter the day (1-31): \";

cin>>day;

if(day<0|| day>31)

cout<<\"Invalid day\"<<endl;

  

}while(day<0 || day>31);

  

  

do

{

  

cout << \"Enter the year: \";

cin>>year;

  

if(year<0)

cout<<\"Invalid year\"<<endl;

}while(year<0);

  

}

Solution

/* A program to find day of a given date */

#include<stdio.h>

int dayofweek(int d, int m, int y)

{

    static int t[] = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 };

    y -= m < 3;

    return ( y + y/4 - y/100 + y/400 + t[m-1] + d) % 7;

}

/* Driver function to test above function */

int main()

{

    int day = dayofweek(30, 8, 2010);

    printf (\"%d\", day);

    return 0;

}

See attached c++ program. I need to continue on with this program building on it to cread a top-level function named dayOfWeek (int month, int day, int year). T
See attached c++ program. I need to continue on with this program building on it to cread a top-level function named dayOfWeek (int month, int day, int year). T
See attached c++ program. I need to continue on with this program building on it to cread a top-level function named dayOfWeek (int month, int day, int year). T
See attached c++ program. I need to continue on with this program building on it to cread a top-level function named dayOfWeek (int month, int day, int year). T
See attached c++ program. I need to continue on with this program building on it to cread a top-level function named dayOfWeek (int month, int day, int year). T

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site