Question: convert this g++ code to a c++ code #include #include #include using namespace std; void printHeader (int); // prints month name , days and seperator

convert this g++ code to a c++ code

#include

#include

#include

using namespace std;

void printHeader (int); // prints month name , days and seperator

void printMonth (int, int&); // the first day of the next month

int FirstmonthFirstday (int );

void printsBlankSpaces (int);// prints the specified amount of spaces

int daysofamonth (int, bool); // takes the number of the month, a flag saying whether year is leap

int main ()

{

while(1)

{

begin:

bool leap;

int year,first_day;

int Present_Month = 1; // Setting current month as 1

int MD,option;

cout << "Enter an Option : 1)To display the calendar for any year 2)Exit"<

cin >>option; //giving option for user to exit or proceed further.

switch(option)

{

case 1: cout << "Enter the year that you want the calendar for: ";

cin >>year;

cout<

first_day=FirstmonthFirstday(year);

leap = ((year%4==0) && (year%100 !=0))||(year%400==0);

printsBlankSpaces(9);

cout << year << endl;

while (Present_Month <= 12)

{

MD = daysofamonth(Present_Month, leap); //returns how many

printHeader(Present_Month);

printMonth(MD, first_day);

cout << endl << endl << endl;

Present_Month += 1;

}

cout << endl;

break;

case 2: exit(0);

default:cout<<"Invalid Input, Enter Again "<

goto begin;

}

}

}

int FirstmonthFirstday(int year)

{

int start_date,first, second, third;

first = (year - 1)/ 4;

second = (year - 1)/ 100;

third = (year - 1)/ 400;

start_date = (year + first - second + third) % 7;

return start_date;

}

int daysofamonth (int month_num, bool is_leap_year)

{

/* If leapyear return 29 else return 30 or 31 */

if (month_num == 1) return(31);

else if (month_num == 2)

if (is_leap_year)

return(29);

else

return(28);

else if (month_num == 3)

return(31);

else if (month_num == 4)

return(30);

else if (month_num == 5)

return(31);

else if (month_num == 6)

return(30);

else if (month_num == 7)

return(31);

else if (month_num == 8)

return(31);

else if (month_num == 9)

return(30);

else if (month_num == 10)

return(31);

else if (month_num == 11)

return(30);

else if (month_num == 12)

return(31);

else

{

cout << "Exiting !! Wrong month number" << endl;

exit(1);

}

}

void printHeader (int month)

{

if (month == 1)

{

printsBlankSpaces(7);

cout << "January" << endl;

}

else if (month == 2) { printsBlankSpaces(7); cout << "February" << endl;}

else if (month == 3) { printsBlankSpaces(7); cout << "March" << endl; }

else if (month == 4) { printsBlankSpaces(7); cout << "April" << endl; }

else if (month == 5) { printsBlankSpaces(7); cout << "May" << endl; }

else if (month == 6) { printsBlankSpaces(7); cout << "June" << endl; }

else if (month == 7) { printsBlankSpaces(7); cout << "July" << endl; }

else if (month == 8) { printsBlankSpaces(7); cout << "August" << endl; }

else if (month == 9) { printsBlankSpaces(7); cout << "September" << endl; }

else if (month == 10) { printsBlankSpaces(7); cout << "October" << endl; }

else if (month == 11) { printsBlankSpaces(7); cout << "November" << endl; }

else if (month == 12) { printsBlankSpaces(7); cout << "December" << endl; }

else

{

cout << "Exiting !! Wrong month number" << endl;

exit(1);

}

cout << " S M T W T F S" <

cout << "____________________" << endl;

}

void printMonth (int numDays, int &weekDay)

{

int init_day = 1;

printsBlankSpaces(3*weekDay);

while (init_day <= numDays)

{

cout << setw(2) << init_day << " ";

if (weekDay == 6)

{

cout << endl;

weekDay = 0;

}

else weekDay += 1;

init_day += 1;

}

}

void printsBlankSpaces (int no_space)

{

while (no_space > 0)

{

cout << " ";

no_space -= 1;

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!