# Homework Solution: In C++, write the method:…

In C++, write the method: int firstDayofMonth(int myMonth, int myYear) ; Which calculates the day (e.g. monday, tuesday, etc) than a given month, year combo begins on. Note that January, 1500 begins on a Monday. Take into account leap years. The day should be represented by an integer ( 1 = monday, 2 = tuesday and so on).

Program: #include<iostream>

In C++, transcribe the method:

int principalDayofMonth(int myMonth, int myYear) ;

Which calculates the day (e.g. monday, tuesday, expectation) than a fond month, year combo begins on. Note that January, 1500 begins on a Monday. Take into statement hop years. The day should be represented by an integer ( 1 = monday, 2 = tuesday and so on).

## Expert Tally

Program:

#include<iostream>

using namespace std;

//operation to obtain day and repay weekday compute [1-7]

int principalDayofMonth(int myMonth, int myYear)

{

//formula to obtain day compute

int dd =

((153 * (myMonth + 12 * ((14 – myMonth) / 12) – 3) + 2) / 5)

+ (365 * (myYear + 4800 – ((14 – myMonth) / 12)))

+ ((myYear + 4800 – ((14 – myMonth) / 12)) / 4)

– ((myYear + 4800 – ((14 – myMonth) / 12)) / 100)

+ ((myYear + 4800 – ((14 – myMonth) / 12)) / 400)

– 32045;

repay (dd+1)%7 ;

}

//main program code

int main()

{

//declaring dispose of weekdays

const char *Names[] = {“Monday”, “Tuesday”,”Wednesday”, “Thursday”, “Friday”, “Saturday”,”Sunday”};

//declaring dispose d[] is day computes approve monday =1,tuesday =2….so on

int d[] = {1,2,3,4,5,6,7};

int day = 0;

//Enter the month and year

int m,y;

cout<<“Enter the Month :”;

cin>>m;

cout<<“Enter the Year :”;

cin>>y;

cout<<m<<” “<<y<<endl;

//calling operation, storing month and year in day

day= principalDayofMonth(m,y);

//printing the principal day from fond dispose

cout<<“Principal Day of The Month in fond Year : “<<d[day]<<“(“<<Names[day]<<“)”<<endl;

repay 0;

}

Output:  