Question

In: Computer Science

write a program on c++ that outputs a calendar for a given month in a given...

write a program on c++ that outputs a calendar for a given month in a given year, given the day of the week on which the 1st of the month was. The information in numeric format (months are: 1=Januay, 2=February 3=March, 4= April, 5= May, 6= June, 7= July... etc days are 1=Sunday, 2=Monday, 3= Tuesday, 4= Wednesday, 5= Thursday, 6= Friday and 7= Saturday ). The program output that month’s calendar, followed by a sentence indicating on which day the month ended.

ex: if the user enters for year: 2020 for month: 2 for day of week that 1st month fell: 7

The outcome should look like

Here is the calendar for February of 2020

Sun Mon Tue Wed Thu Fri Sat
------------------------------------------
                                                  1  
   2     3       4     5      6 7     8
   9    10     11   12    13    14   15
16   17     18   19    20 21   22
23   24     25   26    27    28   29
The month ends on a Saturday.

For the month of February, the program has to decide if the year is leap (29 days) or not.
              .

Solutions

Expert Solution

Code:

#include <iostream>
using namespace std;
int main()
{
int year,month,day,total=0;
string m[]={"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
string d[]={"Sunday","Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
cout<<"Enter year: ";
cin>>year;
cout<<"Enter month: ";
cin>>month;
cout<<"The day of the week on which the first of the month was: ";
cin>>day;
  
if(month == 1 ||month == 3||month == 5||month == 7||month == 8||month == 10||month == 12)
total = 31;
else if(month == 4||month == 6||month == 9||month == 11)
total = 30;
else
{
if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))
total = 29;
else
total = 28;
}
cout<<"\nHere is the calendar for "<<m[month-1]<<" of "<<year;
cout<<"\nSun\tMon\tTue\tWed\tThu\tFri\tSat\n";
int k,j;
for (k = 0; k < day-1; k++)
cout<<"\t";
for (j = 1; j <= total; j++)
{
cout<<j<<"\t";
if (++k > 6)
{
k = 0;
cout<<"\n";
}
}
k = k-1;
if(k<0)
k = 6;
cout<<"\nThe month ends on a "<<d[k]<<".";
return 0;
}

Please refer to the screenshot of the code to understand the indentation of the code:

Output:

For any doubts or questions comment below.


Related Solutions

Write a java program MyCalendar that outputs a monthly calendar for a given month and year....
Write a java program MyCalendar that outputs a monthly calendar for a given month and year. the output should be looks like this one at the bottom:( I don't know why it doesn't show right but the first day of the month is not Sunday it starts from Wednesday) F. Last’s My Calendar Enter month year? 10 2019 10/2019 Sun Mon Tue Wed Thu Fri Sat --------------------------------- 1 2 3 4 5 6 7 8 9 10  11 12 13 14...
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...
C++ Write a program that outputs an amortization schedule for a given loan. Must be written...
C++ Write a program that outputs an amortization schedule for a given loan. Must be written using user-defined functions must take at least 1 argument Output number of months, payment, interest to pay, principle to pay, and ending balance
Write a C++ program that prints a calendar for a given year. ONLY USING "#include<iostream>" and...
Write a C++ program that prints a calendar for a given year. ONLY USING "#include<iostream>" and "#include<cmath>" 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...
C++ Write a program that takes a string and integer as input, and outputs a sentence...
C++ Write a program that takes a string and integer as input, and outputs a sentence using those items as below. The program repeats until the input string is "quit". If the input is: apples 5 shoes 2 quit 0 the output is: Eating 5 apples a day keeps your doctor away. Eating 2 shoes a day keeps your doctor away.
C++. Write a program that asks the user to enter a single word and outputs the...
C++. Write a program that asks the user to enter a single word and outputs the series of ICAO words that would be used to spell it out. The corresponding International Civil Aviation Organization alphabet or ICAO words are the words that pilots use when they need to spell something out over a noisy radio channel. See sample screen output for an example: Enter a word: program Phonetic version is: Papa Romeo Oscar Golf Romeo Alpha Mike The specific requirement...
Write a C++ program that outputs to a file, final marks and average mark for a...
Write a C++ program that outputs to a file, final marks and average mark for a primary school class. Your program should also output to a second a file, the student names and their average mark in ascending order. This is an example of how your program in action could look like: Sample Input Please enter student name and student number Kgosi Kgosi 20150986 Please student marks for Setswana, Maths, Science, English, and Social Studies 80 70 80 65 100...
PYTHON PROGRAM: Write a program that determines the day of the week for any given calendar...
PYTHON PROGRAM: Write a program that determines the day of the week for any given calendar date after January 1, 1900, which was a Monday. This program will need to account for leap years, which occur in every year that is divisible by 4, except for years that are divisible by 100 but are not divisible by 400. For example, 1900 was not a leap year, but 2000 was a leap year.
Write a Java program for RSA encryption that has the following inputs and outputs: Given a...
Write a Java program for RSA encryption that has the following inputs and outputs: Given a message and an integer n = pq where p and q are odd primes and an integer e > 1 relatively prime to (p − 1)(q − 1), encrypt the message using the RSA cryptosystem with key (n, e).
Code in C Write a program whose inputs are three integers, and whose outputs are the...
Code in C Write a program whose inputs are three integers, and whose outputs are the largest of the three values and the smallest of the three values. Ex: If the input is: 7 15 3 the output is: largest: 15 smallest: 3 Your program must define and call the following two functions. The LargestNumber function should return the largest number of the three input values. The SmallestNumber function should return the smallest number of the three input values. int...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT