
Explanation of Solution
Program code:
//include the required header files
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
//use the std namespace
using namespace std;
//create a string array MONTHARRAY
const string MONTHARRAY[12] = { " January", " February", " March", " April", " May", " June", " July", " August", " September", " October", " November", " December"};
//create a string array DAYARRAY
const string DAYARRAY[7] = {"Sun ", " Mon ", " Tue ", " Wed ", " Thu ", " Fri ", " Sat"};
int a,y,day,m,d, x;
//create integer variable month
int month;
//define two functions printMonth() and getFirst
void printMonth(int month, int startDay, int year);
int getFirst(int month, int day, int year);
//define the main() function
int main (void)
{
//prompt the user to enter the year later than 1582
cout<<"Please enter a year later than 1582: ";
//scan for the value
cin>>x;
//if the value of x is greater than 1582
if(x>1582)
{
//iterate a for loop
for (int i = 0; i<12; i++)
{
//call the methods
getFirst(i, 1, x);
printMonth(i, d, x);
}
}
//if the value of x is less than 1582
else
{
//print the statement
cout<<"That year is before 1582, please enter a better year: ";
//scan for the value
cin>>x;
}
//return 0
return 0;
}
//define the method getFirst()
int getFirst(int month, int day, int year)
{
//set the values
a = (14-month)/12;
y = year-a;
m = month+12*a-2;
d = (day+y+y/4-y/100+y/400+(31*m/12))%7;
//return the value of d
return d;
}
//define the method printMonth()
void printMonth(int month, int startDay, int year)
{
//create integer array to hold the dates
int daysInMonths[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
//create two integer variables
int copy = 1;
int counter = 1;
//print the values of M ONTHARRAY[]
cout<<MONTHARRAY[month]<<endl;
//finding leap year
//if the year is divisible by 4
if(year%4 == 0)
//set the daysInMonths[1] as 29
daysInMonths[1] = 29;
//iterate a for loop
for(int i = 0; i <=6; i++)
{
//print the values of DAYARRAY[]
cout<<DAYARRAY[i];
//if the value i is 6
if(i == 6)
//new line
cout<<endl;
}
//iterate a while loop
while(copy<=daysInMonths[month])
{
//if the value of counter is less than or equal to startDay
if(counter <= startDay)
//print the value of left and call the method setw()
cout<<left<<setw(5)<<" ";
//if the value of counter is greater than startDay
else
{
//print the value of left and call the method setw()
cout<<left <<setw(5) <<copy;
//increment the value of copy by 1
copy++;
}
//if the counter is divisible by 7
if(counter%7 == 0 )
//print a new line
cout<<endl;
//increment the counter by 1
counter++;
}
//print a new line
cout<<endl;
}
Explanation:
The above snippet of code is used create the calendar of any year later 1582. Check the leap year. In the code,
- Include the required header files.
- Use the “std” namespace.
- Create string array “MONTHARRAY[]” and “DAYARRAY[]”.
- Create the required integer variables.
- Declare two functions “printMonth()” and “getFirst()”.
- Define “main()” function.
- Prompt the user to enter the year later than 1582.
- Scan for the value.
- If the value of “x” is greater than 1582.
- Iterate a “for” loop.
- Call the method “getFirst()” and “printMonth()”.
- Iterate a “for” loop.
- If the value of “x” is less than 1582.
- Prompt the statement.
- Print the value of “x”.
- Return “0”.
- Define a method “printMonth()”.
- Declare integer array, “daysInMonth[]” and variables “copy”, “counter”.
- Print the values of the array “MONTHARRAY[]”.
- If the year is divisible by “4”.
- Iterate a “for” loop;
- Print the values of the array “DAYARRAY[]”.
- If the value of “i” is equal to “6”.
-
- Print a new line.
- Iterate a “while” loop.
- If the value of “counter” is less than or equal to “startDay”.
- Print the value of “left” and “setw(5)”.
- If the value of “counter” is greater than “startDay”.
- Print the value of “left” and “setw(5)”.
- Increment the value of “copy” by 1.
- If the value of “counter” is divisible by “7”.
- Print a new line.
- Increment the “counter” by 1
- If the value of “counter” is less than or equal to “startDay”.
- Print a new line.
- Iterate a “while” loop.
- Print a new line.
- Iterate a “for” loop;
Output:
Please enter a year later than 1582: 1992
January
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 30 31
February
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
March
Sun Mon Tue Wed Thu Fri Sat
;&#x...

Want to see the full answer?
Check out a sample textbook solution
Chapter 1 Solutions
Data Structures and Algorithms in C++
- you can select multipy optionsarrow_forwardFor each of the following, decide whether the claim is True or False and select the True ones: Suppose we discover that the 3SAT can be solved in worst-case cubic time. Then it would mean that all problems in NP can also be solved in cubic time. If a problem can be solved using Dynamic Programming, then it is not NP-complete. Suppose X and Y are two NP-complete problems. Then, there must be a polynomial-time reduction from X to Y and also one from Y to X.arrow_forwardMaximum Independent Set problem is known to be NP-Complete. Suppose we have a graph G in which the maximum degree of each node is some constant c. Then, is the following greedy algorithm guaranteed to find an independent set whose size is within a constant factor of the optimal? 1) Initialize S = empty 2) Arbitrarily pick a vertex v, add v to S delete v and its neighbors from G 3) Repeat step 2 until G is empty Return S Yes Noarrow_forward
- Please help me answer this coding question in the images below for me(it is not a graded question):write the code using python and also provide the outputs requiredarrow_forwardWhat does the reduction showing Vertex Cover (VC) is NP-Complete do: Transforms any instance of VC to an instance of 3SAT Transforms any instance of 3SAT to an instance of VC Transforms any instance of VC to an instance of 3SAT AND transforms any instance of 3SAT to an instance of VC none of the abovearrow_forwardPlease assist me by writing out the code with its output (in python) using the information provided in the 2 images below.for the IP Address, it has been changed to: 172.21.5.204the serve code has not been open yet though but the ouput must be something along these lines(using command prompt):c:\Users\japha\Desktop>python "Sbongakonke.py"Enter the server IP address (127.0.0.1 or 172.21.5.199): 172.21.5.204Enter your student number: 4125035Connected to server!It's your turn to pour! Enter the amount to your pour (in mL):Please work it out until it gets the correct outputsNB: THIS QUESTION IS NOT A GRADED QUESTIONarrow_forward
- need help with a html code and css code that will match this image.arrow_forwardneed help with a html code and css code that will match this image. Part B - A Navigation Part B is the navigation component of a page. Information you need includes: Color Codes: Visiting links: #ff6666 Unvisited links: #ccff66 Hovered links: white Search box: #2ec4b6 rebeccapurple white Font: Google Font (Roboto) Icons: Font Awesome (fa-quidditch, fa-search) This is a flexbox based navigation menu. Other then padding, all spacing/positioning should be controlled using flex properties. The home link in the nav should point to your assignment file (to triggers visited styling). In the "state" screenshot below, Home is visited, Services is hovered (the mouse doesn't show up in the screenshot) and Products is unvisited.arrow_forwardMGMT SS STATS, an umbrella body that facilitates and serves various Social Security Organizations/Departments within the Caribbean territories, stood poised to meet the needs of its stakeholders by launching an online database. The database will provide members and the public access to the complete set of services that can (also) be initiated face-to-face, and it will provide managed, private, secure access to a repository of public and/or personal information. Ideally, the database will have basic details of pension plans recorded in the registry, member plan statistics, and cash inflows and outflows from pension funds.For example, insured persons accumulate contributions. Records for these persons will include information on the insured persons able to acquire various benefits once work is interrupted due to sickness, death, retirement, and maternity or employment injury. They will also include information on pensions such as invalidity, disability, and survivors that stem from one…arrow_forward
- Why all appvif i want to sign in its required phone number why not using google or apple its make me frustratedarrow_forwardWhy is the accuracy of time important in data visualizations? Detail a scenario from your professional experience in which time was structured poorly in a data visualization. How did this affect the understanding of the data presented? How do you think this error or oversight occurred?arrow_forwardWrite the KeanStudent class. The UML diagram of the class is represented below: KeanStudent - fullName: String - keanID: int -keanEmailAddress: String cellPhoneNumber: String + numberOfStudent: int + KeanStudent() + KeanStudent(fullName: String, keanID: int, keanEmailAddress: String, cellPhoneNumber: String) +getFullName(): String +setFullName(newFullName: String): void +getKeanIDO): int +getKeanEmailAddress(): String +getCellPhoneNumber(): String + setCellPhoneNumber(newCellPhoneNumber: String): void +toString(): String 1. Implement the KeanStudent class strictly according to its UML one-to-one (do not include anything extra, do not miss any data fields or methods) 2. Implement a StudentTest class to test the class KeanStudent you just created. • Create two KeanStudent objects using a no-args constructor and one from the constructor with all fields. o Print the contents of both objects. 。 Print numberOfStudent. 3. Add comments to your program (mark where data fields, constructors,…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





