Question

In: Computer Science

. In this lab you will be making a text-based calendar program that looks like: JANUARY...

. In this lab you will be making a text-based calendar program that looks like:
JANUARY 2018
S M Tu W Th F S
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
Your calendar should be able to print months in the future and in the past.
Activity #1
In C++ create a calendar program that has the following two functions:
▪ printMonth – this function has two parameters (month, year) and will print out the calendar for the specified month in the format discussed in the introduction to this lab.
▪ printYear – this function has one parameter (year) and will print out the calendar for all 12 months in that year.
In addition to the above functions you should also create a main function that will test your program. In the main function the program should ask the user if he/she wants a year or month calendar. If the user wants a year calendar the program should input the year. If the user wants a month calendar the program should input the month and year.
In order to print the calendar for a given month you need to write an algorithm to determine which day of the week the first day of the month is on. You can determine this using the following information:
1. Number of days in each month.
a. January – 31 days
b. February – 28 or 29 days
c. March – 31 days
d. April – 30 days
e. May – 31 days
f. June – 30 days
g. July – 31 days
h. August – 31 days
i. September – 30 days
j. October – 31 days
k. November – 30 days
l. December – 31 days
2. Leap years.
In a leap year February has an extra day, which is why February can be either 28 or 29 days long. Years that are evenly divisible by 4 are leap years except when the year is also evenly divisible by 100. There is also an exception to this rule since years that are evenly divisible by 100 but also evenly divisible by 400 are considered leap years. For example:
• 2009 is not a leap year because it is not evenly divisible by 4.
• 2008 was a leap year because it was evenly divisible by 4 and not evenly divisible by 100.
• 1900 was not a leap year because even though it was evenly divisible by 4 it was also evenly divisible by 100 (and not evenly divisible by 400).
• 2000 was a leap year because it is evenly divisible by 4, evenly divisible by 100 and evenly divisible by 400.

Solutions

Expert Solution

#include <iostream>
#include <iomanip>

using namespace std;

char months[13][100] = {"", "January","February","March","April","May","June","July","August","September","October","November","December"};
char days[7][100] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};

int isLeapYear(int year) {
    return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0));
}

unsigned int dayOfWeek(int y, int m, int d) { 
        m = (m + 9) % 12;
        y -= m / 10;
        unsigned int dn = 365*y + y/4 - y/100 + y/400 + (m*306 + 5)/10 + (d - 1);

        return (dn + 3) % 7;
}

int findDaysInMonth(int year, int month) {
        int days = 31;
        if((month==6) || (month==4) || (month==11) || (month==9)) {
                days = 30;
        }else if((month==2) && isLeapYear(year)) {
                days = 29;
        } else if(month == 2) {
                days = 28;
        }
        return days;
}

int printMonthCalendar(int year, int month) {
        int numOfDays = findDaysInMonth(year, month); 
        int startingDay = dayOfWeek(year, month, 1);
        for(int i=0; i<7; i++) {
                cout << setw(5) << days[i];
        }
        cout << endl;
        
        for(int i=1; i<startingDay; i++) {
                cout << setw(5) << "";
        }

        int day = 1;
        int weekDay = startingDay - 1;
        while(day <= numOfDays) {
                cout << setw(5) << day;
                day++;
                weekDay++;
                if(weekDay == 7) {
                        cout << endl;
                        weekDay = 0;
                }
        }
        cout << endl;
        return weekDay + 1;
}

void printYearCalendar(int year) {
        for(int month=1; month<=12; month++) {               
                cout << months[month] << ", " << year << endl;
                printMonthCalendar(year, month);
                cout << endl;
        }
}

int main() {
        // to print year calendar
        printYearCalendar(2019);

        // to print month calendar
        cout << endl << endl << "Month calendar" << endl;
        printMonthCalendar(2019, 10);
}
**************************************************

Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.

Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.


Related Solutions

The Calendar Program The purpose of this lab is to give you a chance to use...
The Calendar Program The purpose of this lab is to give you a chance to use some of the data stream tools we have been discussing in a simple application. The assignment is to write a calendar application which allows the user to select a date, and either retrieve a previously stored calendar entry, or save a calendar entry. Your program should present a GUI interface which allows the user to specify the month, day, and year of the calendar...
Develop a C++ program that looks for a given value in a text file full of...
Develop a C++ program that looks for a given value in a text file full of integer values Prompt the user for a value to search for in the file No input validation is required Open the accompanying text file named numbers.txt Search the contents of the text file You may not "hard-code" the quantity of values found in the file... Use a loop of some sort until the end of the text file is reached Maintain how many many...
What it Looks Like to the User The program will loop, asking the user for a...
What it Looks Like to the User The program will loop, asking the user for a bet amount from 0 to 100 (assume dollars, you can use ints or longs). If the user types a 0 that means she wants to quit. Otherwise, accept the amount as their bet and simulate a slot machine pull. Your program will print out a line that looks like a slot machine result containing three strings. Some examples are:  BAR 7 BAR, 7 7 cherries,...
Process: In this lab, you will be implementing a simple “Bop-it!”-like game. Your program will run...
Process: In this lab, you will be implementing a simple “Bop-it!”-like game. Your program will run for a single game. Start with implementing a “start menu”, output a line asking the user to push a keyboard key to start and wait for the user to push a key. The game will involve printing a line telling the user which key to press (chosen randomly by the program) and will wait a certain time for a response. After each successful action...
Who is making decisions on what core curriculum public colleges will have? And how the process looks like?
Who is making decisions on what core curriculum public colleges will have? And how the process looks like?How are pubic colleges get funded?If you want to propose new legislation about public education, where should you go?
PYTHON In this lab we will design a menu-based program. The program will allow users to...
PYTHON In this lab we will design a menu-based program. The program will allow users to decide if they want to convert a binary number to base 10 (decimal) or convert a decimal number to base 2 (binary). It should have four functions menu(), reverse(), base2(), and base10(). Each will be outlined in detail below. A rubric will be included at the bottom of this document. Menu() The goal of menu() is to be the function that orchestrates the flow...
3.24 LAB C++ : Program: Text message decoder (1) Use getline() to get a line of...
3.24 LAB C++ : Program: Text message decoder (1) Use getline() to get a line of user input into a string. Output the line. (3 pts) Ex: Enter text: IDK if I'll go. It's my BFF's birthday. You entered: IDK if I'll go. It's my BFF's birthday. (2) Search the string (using find()) for common abbreviations and print a list of each found abbreviation along with its decoded meaning. (3 pts) Ex: Enter text: IDK if I'll go. It's my...
How can I do the star pattern looks like: ( for example) ( you might not...
How can I do the star pattern looks like: ( for example) ( you might not notice the difference but there is space at the beginning of row 2 & 4) .* * * * * . * * * * * .* * * * * . * * * * * .* * * * * instead of : . * * * * * . * * * * * . * * * * * ....
Excluding the U.S., mention one country in the world that you think looks more like a...
Excluding the U.S., mention one country in the world that you think looks more like a Laissez-Faire Capitalism system and another country that looks more like a command system. Explain your reasoning. Also, one of the characteristics of the market system is that people are motivated by self-interest. Does it mean that there are no altruistic people in a market system? Explain.
draw a picture of what you think recombinant plasmid looks like. in your drawing, show the...
draw a picture of what you think recombinant plasmid looks like. in your drawing, show the approximate location of any antibiotic resistant gene, the gene of interest, the restriction of endonuclease cutting sites
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT