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

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...
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...
USING C# 1. Write a program that takes outputs a string, an integer and a floating-point...
USING C# 1. Write a program that takes outputs a string, an integer and a floating-point number separated by commas. Sample output: Bob Marley, 20, 5.2 2. 2. Write a program that asks the user for a string of letters of any size (no spaces), and finally a special character (values 33 to 47 in the Ascii table, or ‘!’ to ‘/’). Generate a random number of any size, integer or floating point, and combine those three pieces of information...
Write a C++ program that outputs a histogram of student Marks for a Mid-term-1 Examination. The...
Write a C++ program that outputs a histogram of student Marks for a Mid-term-1 Examination. The program should input each student’s Marks as an integer and store the Marks in a dynamic array. Marks should be entered until the user enters -1 for marks. The program should then scan through the Dynamic array and compute the histogram. In computing the histogram, the minimum value of a marks is 0 but your program should determine the maximum value entered by the...
Write a C program that outputs a formatted header line and creates 10 children processes each...
Write a C program that outputs a formatted header line and creates 10 children processes each of which displays a line of the output as shown below. Notice the values of Child no and x, they have to be the same as shown here while the processes PIDs values are based on the what your system assigns to these processes. Child    PID        PPID      X 0           13654    13653    5 1           13655    13653    10 2           13656    13653    15 3           13657    13653    20...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT