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.
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.
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...
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).
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 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...
write a program in c++ that opens a file, that will be given to you and...
write a program in c++ that opens a file, that will be given to you and you will read each record. Each record is for an employee and contains First name, Last Name hours worked and hourly wage. Example; John Smith 40.3 13.78 the 40.3 is the hours worked. the 13.78 is the hourly rate. Details: the name of the file is EmployeeNameTime.txt Calculate the gross pay. If over 40 hours in the week then give them time and a...
Write a C program (using Code::blocks) that outputs a formatted header line and creates 10 children...
Write a C program (using Code::blocks) 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   ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT