Question
c++ please :)
First, ask the user to enter a year (4-digit) and what week day does this year starts with (String) For example, the year 201
6. You will need to define and implement the following functions: void PrintOneMonth (int MonthNumber, int Year,int StartDayN
Sample of output Enter year (must be in range 1000 Year <9999) 2018 What day of the week does Jan 1 fall on this year? monday
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>

#include <cstdlib>

#include <cmath>

#include <cstring>

using namespace std;

//Function declarations

void printOneMonth(int year,int month,int dayOfWeek);

bool isLeapYear(int year);

int GetYear();

int GetStartDayNember();

int DayPerMonth(int MonthNumber, int Year);

int main()

{

//Declaring variables

int getFirstDay;

int year;

  

//Getting the year entered by the user

year=GetYear();

getFirstDay=GetStartDayNember();

  

  

/* This for loop will display each month

* calender by calling the function

*/

for(int i=1;i<=12;i++)

{

printOneMonth(year,i,getFirstDay);

}

  

  

return 0;

}

//This function will display the month calender

void printOneMonth(int year,int month,int getFirstDay)

{

int days = 0;

string monthName;

days=DayPerMonth(month,year);

  

// Declaring string array

const string months[] = { "January", "February", "March", "April", "May", "June", "July",

"August", "September", "October", "November", "December" };

  

monthName=months[month-1];

  

cout << "\t"<<monthName<< " " << year << endl;

cout << "__________________________________" << endl;

cout << " Sun Mon Tue Wed Thu Fri Sat" << endl;

int i = 0;

int firstDay = 0;

  

  

switch (month)

{

case 1:

firstDay = getFirstDay;

break;

case 2:

firstDay = getFirstDay + 3;

break;

case 3:

firstDay = getFirstDay + 3;

break;

case 4:

firstDay = getFirstDay + 6;

break;

case 5:

firstDay = getFirstDay + 8;

break;

case 6:

firstDay = getFirstDay + 11;

break;

case 7:

firstDay = getFirstDay + 13;

break;

case 8:

firstDay = getFirstDay + 16;

break;

case 9:

firstDay = getFirstDay + 19;

break;

case 10:

firstDay = getFirstDay + 21;

break;

case 11:

firstDay = getFirstDay + 24;

break;

case 12:

firstDay = getFirstDay + 26;

break;

}

if(isLeapYear(year))

{

switch (month)

{

case 1:

firstDay = getFirstDay;

break;

case 2:

firstDay = getFirstDay + 3;

break;

case 3:

firstDay = getFirstDay + 4;

break;

case 4:

firstDay = getFirstDay + 7;

break;

case 5:

firstDay = getFirstDay + 9;

break;

case 6:

firstDay = getFirstDay + 12;

break;

case 7:

firstDay = getFirstDay + 14;

break;

case 8:

firstDay = getFirstDay + 17;

break;

case 9:

firstDay = getFirstDay + 20;

break;

case 10:

firstDay = getFirstDay + 22;

break;

case 11:

firstDay = getFirstDay + 25;

break;

case 12:

firstDay = getFirstDay + 27;

break;

}

}

int dayOfWeek = 0;

if ((firstDay % 7) >= 0)

{

if ((firstDay % 7) == 0)

{

dayOfWeek = 0;

}

else if ((firstDay % 7) == 1)

{

dayOfWeek = 1;

cout << " ";

}

else if ((firstDay % 7) == 2)

{

dayOfWeek = 2;

cout << "\t ";

}

else if ((firstDay % 7) == 3)

{

dayOfWeek = 3;

cout << "\t\t";

}

else if ((firstDay % 7) == 4)

{

dayOfWeek = 4;

cout << "\t\t ";

}

else if ((firstDay % 7) == 5)

{

dayOfWeek = 5;

cout << "\t\t\t";

}

else if ((firstDay % 7) == 6)

{

dayOfWeek = 6;

cout << "\t\t\t ";

}

}

for (i = 1; i <= days; i++)

{

if (i < 10)

cout << " " << i;

else

cout << " " << i;

if ((i + firstDay) % 7 == 0)

cout << endl;

}

cout << endl;

  

}

/* This function will check whether

* the year is leap year or not

*/

bool isLeapYear(int year)

{

if (year % 400 == 0){   

return true;

}

if (year % 100 == 0){   

return false;

}

  

if (year % 4 == 0){

return true;

}

return false;

}

int GetYear()

{

int year;

while(true)

{

cout<<"Enter Year :";

cin>>year;

if(cin.fail())

{

cout<<"** Invalid.Must be Numeric **"<<endl;

cin.clear();

cin.ignore(256, '\n');

}

else if(year<1000 || year>9999)

{

cout<<"** Invalid.Must be between 1000-9999 **"<<endl;

}

else

{

break;

}

}

return year;

}

int GetStartDayNember()

{

string week[]={"sunday","monday","tuesday","wednesday","thursday","friday","saturday"};

string s;

int flag=0;

while(true)

{

cout<<"Enter day of the week :";

cin>>s;

for (int i = 0; i < s.size(); i++)

{

if (s.at(i) >= 65 && s.at(i) <= 90)

{

s.at(i) = s.at(i) + 32;

}

}

for(int i=0;i<s.size();i++)

{

if(s.compare(week[i])==0)

{

flag=1;

return i;

}

}

if(flag==0)

{

cout<<"** Invalid.Please check the Spelling **"<<endl;

cin.clear();

cin.ignore(256, '\n');

}

}

}

int DayPerMonth(int MonthNumber, int Year)

{

// Declaring an array and initializing corresponding days in the month

int months[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

if(isLeapYear(Year))

{

if(MonthNumber==2)

return 29;

else

return months[MonthNumber-1];

}

else

{

return months[MonthNumber-1];

}

}

________________________

Output:

C: Program Files (x86)\Dev-Cpp MinGW64 bin CalenderValidateYrMonthSta... dune 2019 Sun Mon Tue Wed Thu Fri Sat 4 8 9 1 11 1 1

CProgram Files (x86)\Dev-Cpp\MinGW64 bi inCalenderValidateYearMonthSta. November 2019 Sun Mon Tue Wed Thu Fri Sat 6 9 1 11 1

Add a comment
Know the answer?
Add Answer to:
c++ please :) First, ask the user to enter a year (4-digit) and what week day...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C# program that prints a calendar for a given year. Call this program calendar....

    Write a C# program that prints a calendar for a given year. Call this program calendar. The program prompts the user for two inputs:       1) The year for which you are generating the calendar.       2) The day of the week that January first is on, you will use the following notation to set the day of the week:             0 Sunday                     1 Monday                   2 Tuesday                   3 Wednesday       4 Thursday                 5 Friday                      6 Saturday Your program should...

  • Write a C# program that prints a calendar for a given year. Call this program calendar....

    Write a C# program that prints a calendar for a given year. Call this program calendar. This program needs to use Switch Case in order to call the methods and format to print each month. The program prompts the user for two inputs:       1) The year for which you are generating the calendar.       2) The day of the week that January first is on, you will use the following notation to set the day of the week:      ...

  • Given the following enumeration, what is the output from the printf(): enum day { sun, mon,...

    Given the following enumeration, what is the output from the printf(): enum day { sun, mon, tue, wed, thu, fri, sat}; enum day d; d = mon; prrintf("%d\n", d); a. mon b. 1 c. MON d. 0

  • Suppose that today is April 1st of the year 2019. By entering your birthday, print what is a day ...

    C++ question Suppose that today is April 1st of the year 2019. By entering your birthday, print what is a day of the week you were born and how many days passed since you were born. Remember that January 1st of the year 2019 is Tuesday See the example below Read 1/1/2019 - Tue 90 Read 4/1/2019 - Mon 0 Read 4/1/2018 - Sun 365 Read 4/1/2017 -> Sat 730 Read 4/1/2016 Fri 1095 Read 4/1/2015-> Wed 1461 Bye... Wikipedia...

  • Create a calendar for the year 2019, for a particular month (of your choosing ), highlight a part...

    Create a calendar for the year 2019, for a particular month (of your choosing ), highlight a particular date (also your choosing) with an asterisk. Make sure the calendar displays the week, the days of the week and the year. Make sure the MSU Programming Class appears in the title of the Calendar. I will choose May 1st for the month and date. The code below is what I will be using. Please show where I can go to in...

  • Copy all the classes given in classes Calendar, Day, Month, & Year into BlueJ and then...

    Copy all the classes given in classes Calendar, Day, Month, & Year into BlueJ and then generate their documentation. Examine the documentation to see the logic used in creating each class. (Code given below) import java.util.ArrayList; import java.util.Iterator; class Calendar { private Year year; public Calendar() { year = new Year(); } public void printCalendar() { year.printCalendar(); } } class Year { private ArrayList<Month> months; private int number; public Year() { this(2013); } public Year(int number) { this.number = number;...

  • Use Java please Creating a calendar for a given year A shell for this assignment has...

    Use Java please Creating a calendar for a given year A shell for this assignment has been provided so that you can fill in the methods Homework 4 grading rubric 1. Output examples a. One Normal Year, 10% b. One Leap Year, 10% 2. Style Meaningful variable names, 10% b. Meaningful method names, 10 % c. Comments, Total: 10% . Do not comment every line. 5% . Comment non-obvious code. 5% a d. Indentation, 10% e. Block comment with name...

  • Can someone fix my coding please it's a calendar some days are placed wrong. I just...

    Can someone fix my coding please it's a calendar some days are placed wrong. I just want the Main menu to display first and second option and four option to end the program properly. Please remove option number 3 Find the number of days between 2 selected dates and the code that belongs to this function. #include<stdio.h> void days(int,int,int,int,int,int); int month(int,int); int mon[12]={31,28,31,30,31,30,31,31,30,31,30,31}; #define TRUE 1 #define FALSE 0 int days_in_month[]={0,31,28,31,30,31,30,31,31,30,31,30,31}; char *months[]= { " ", "\n\n\nJanuary", "\n\n\nFebruary", "\n\n\nMarch", "\n\n\nApril",...

  • 1. Kristen Pacheco owns a small restaurant that’s open seven days a week. Until recently, she...

    1. Kristen Pacheco owns a small restaurant that’s open seven days a week. Until recently, she forecasted the daily number of customers she would have using her intuition. However, she wanted to open another restaurant and recognized the need to adopt a more formal method of forecasting that could be used in both locations. Kristen decided to compare a three week moving average forecast with exponential smoothing forecasts using α = .7 and α = .3. She collected sales data...

  • Design "MyWeek" class: (1) Data members: the class contains one private data field weekList. "wee...

    Design "MyWeek" class: (1) Data members: the class contains one private data field weekList. "weekList" has datatype of ArrayList, which will contain String objects of week/weekend days. There are no duplicated days in the list. Valid days are "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun". The weekList is not necessarily to be ordered (2) Constructors The instance of MyWeek can be constructed with (a) no argument (initialized weekList to empty), or (b) with one String argument which is one valid...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT