Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(1).Prompt the user for the month and year to print (2).Output the calendar in an output file. The code is provided below. ***************************Main.cpp********************************** //preprocessor directives

(1).Prompt the user for the month and year to print

(2).Output the calendar in an output file.

The code is provided below.

***************************Main.cpp**********************************

//preprocessor directives and header files #include "calendarType.h" #include "extDateType.h" #include "dateType.h" #include #include

//standard library using namespace std;

//const int to hold array size const int SIZE = 12;

//create a string array to hold the names of each month string mNames[SIZE] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};

//Create getIntMonth definition int getIntMonth(string month) { for (int i = 0; i < 12; i++) { if(month==mNames[i]) { return i+1; } } return 0; }

//Void prototype for getInput void getInput(int &m, int&y) { //Display friendly user message and purpose of the alteration of the program cout << "Hello there! This program should print the calendar for a given month and year" << endl; //Initialize string month; string month; //User's input cin >> month >> y;

//While loop if month is invalid while(getIntMonth(month)==0) { cout << "INVALID MONTH, please re-enter the month: "; //Display message of checker if month is invalid cin >> month; //month input } m = getIntMonth(month); //store the returned value into m }

//Commented out sections from assignments 2-5 // Leave local variables alone for month, day, year parameter purposes //Step into main int main() { //local variables int m, d, y; //int passed, remain; dateType date(0,0,0); //calling the constructors extDateType extDate(0,0,0); calendarType dayType(0,0,0);

//message explaining the purpose of the program to the user //cout << "Hi there! " << endl; //cout << "The reason you're here is to see if the " // << "program can identify a leap year." << endl; //cout << "Another reason is for the test the class of this program" // << " and prove the rules of the class type." << endl;

//prompt the user to enter the values //cout << "Enter a Month of your choice: "; //cin >> m; //cout << "Enter a Day of your choice: "; //cin >> d; //cout << "Enter a Year of your choice: "; //cin >> y; //cout << endl;

d = 1;// set d to 1 as default getInput(m, y); //store month and year

//call the member functions dayType.setDate(m, d, y); //extDate.setDate(m, d, y); //date.setDate(m, d, y);

//check to make sure if it is a leap year //bool check = date.isLeapYear(y); //if (check) // cout << "Leap year:"; //else // cout << "Not a leap year:";

//display the chosen date in numerical form //date.printDate(); //extDate.setMonth(m,mNames,SIZE); dayType.setMonth(m,mNames,SIZE);

//display the date chosen in long form //extDate.printLongDate();

//call the rest of the member functions //date.numOfDays(m); //passed = date.numOfDaysPassed(m, d);//store the returned value into passed //remain = date.remainingDays(y);//store the returned value into remain

//display the amount of days passed //cout << " The number of days that have passed are: " // << passed << endl;

//display the amount of days remaining //cout << "The amount of days remaining are:" << " " << remain << endl;

//call the newDate function to calculate the new date //date.newDate(m, d, y, 25);

//display the new date by calling the printDate function //cout << "The new date is: "; //date.printDate();

//calculate the first day of the month dayType.firstDayOfMonth();

//display the months calendar dayType.printMonthCalendar();

return 0; }*************************DATETYPE.H****************************

#ifndef date_H #define date_H //begin class definition class dateType { public: void setDate(int month, int day, int year); //Function to set the date. //The member variables dMonth, dDay, and dYear are set //according to the parameters //Postcondition: dMonth = month; dDay = day; // dYear = year int getDay() const; //Function to return the day. //Postcondition: The value of dDay is returned. int getMonth() const; //Function to return the month. //Postcondition: The value of dMonth is returned. int getYear() const; //Function to return the year. //Postcondition: The value of dYear is returned. void printDate() const; //Function to output the date in the form mm-dd-yyyy. bool isLeapYear(int year); //Function to determine whether the year is a leap year. dateType(int month = 1, int day = 1, int year = 1900); //Constructor to set the date //The member variables dMonth, dDay, and dYear are set //according to the parameters //Postcondition: dMonth = month; dDay = day; // dYear = year //If no values are specified, the default values are //used to initialize the member variables. int numOfDays (int month); //function to count up the number of days int numOfDaysPassed (int month, int year); //function to count the number of days passed for the date chosen int remainingDays(int year); //function to count the number of days left remaining in the year int newDate(int month, int day, int year, int addDays); //function to create a new date by adding a fixed amount of days private: int dMonth; //variable to store the month int dDay; //variable to store the day int dYear; //variable to store the year int passedDays; //variable to store the days that have passed int noDays; //variable to store the # of days int daysRemaining; // variable to store the days left in a year }; #endif

******************extDateType.h*************************

#ifndef EXTDATETYPE_H_INCLUDED #define EXTDATETYPE_H_INCLUDED //preprocessor directives #include  #include "dateType.h" //standard library using namespace std; //begin the derived class class extDateType: public dateType { public: void setDate(int month, int day, int year); //function to set the date void setMonth(int month, string mNames[],const int SIZE); //function to set the name of the month void printLongDate(); //function to print out the name of the month with the days and year extDateType(int month = 1, int day = 1, int year = 1900); //constructor based on dateTypeImp.cpp private: int eMonth; //variable to store the month int eDay; //variable to store the day int eYear; //variable to store the year string eMonths; //variable to store the name of the month };//end the derived class #endif // EXTDATETYPE_H_INCLUDED

****************calendarType.h***********************

#ifndef CALENDARTYPE_H_INCLUDED #define CALENDARTYPE_H_INCLUDED //preprocessor directives #include  #include "dateType.h" #include "extDateType.h" //standard library using namespace std; //begin the derived class calendarType class calendarType: public dateType { public: void printMonthCalendar(); //function to print the calendar for the month chosen void setMonth(int month, string mNames[],const int SIZE); //function to set the month void setDate(int month, int day, int year); //function to set the date int firstDayOfMonth(); //function to find what day of the week the first day is int getMonth() const; //function to return the month. //postcondition: The value of cMonth is returned. int getYear() const; //function to return the year. //postcondition: The value of cYear is returned. calendarType(int month = 1, int day = 1, int year = 1500); //constructor based on dateTypeImp.cpp private: int firstDay;//variable to hold the value of the day of the week int cDay;//variable to store the day int cMonth;//variable to store month int cYear;//variable to store the year string cWeekDays;//variable to store the name of the day string cMonthNames;//variable to store the name of the month }; //end class header file #endif // CALENDARTYPE_H_INCLUDED

******************dateTypeImp.cpp***********************

//preprocessor directives and header files #include "dateType.h" #include  #include  using namespace std; //define the function newDate int dateType::newDate(int month, int day, int year, int addDays) { //add the current number of days to the fixed amount dDay = day + addDays; //see if the total number of days is > 31 if (dDay>31) { //make sure the day is not negative by finding the absolute value dDay = abs(dDay - 31); //increase the month if the number of days is > than 31 month++; } //store the value of the month into the variable dMonth dMonth = month; //check if the value of the variable month is > than 12 if (month>12) { //assign 1 to the variable dMonth dMonth = 1; //increment the variable dYear dYear++; } return 0; } //define the function numOfDaysPassed int dateType::numOfDaysPassed(int month, int day) { //declare local variables for a counter and for the passed days int i, passed = 0; //start the for loop from 1 to 12 for (i = 1; i <= 12; i++) { //check if i is the month if (i == month) { //exit from the loop break; } else //store the number of days passed in a year passed += numOfDays(i); } //add the days of the current month passed += day; //store the value of the passed into the variable PassedDays passedDays = passed; //return the value of the variable passedDays return passedDays; } //define the function remainingDays int dateType::remainingDays(int year) { //declare local variable for the remaining days int daysRemaining; //check whether leap year or not if (isLeapYear(year)) { //Calculate the remaining days in a leap year daysRemaining = 366 - passedDays; } else //Calculate the remaining days in a year. daysRemaining = 365 - passedDays; //return the total number of the days remaining in a year return daysRemaining; } //define the function numOfDays int dateType::numOfDays(int month) { //declare a variable to store the year of the date int nYear; //assign the value of the variable dYear to the variable nYear nYear = dYear; //check if the value of the variable month is less than 12 if (month <= 12) { //assign the value of the variable month to the variable dMonth dMonth = month; //begin Switch statement to determine noDays switch (month) { //assign 31 to the variable noDays for the case 1, 3, 5, 7, 8, 10, and 12 case 1: case 3: case 5: case 7: case 8: case 10: case 12: noDays = 31; break; //assign 30 to the variable noDays for the case 4, 6, 9, 11 case 4: case 6: case 9: case 11:noDays = 30; break; //check whether the year is a leap year or not for case 2 case 2: if (isLeapYear(nYear)) { //assign 29 for the variable noDays noDays = 29; } else { //assign 28 for the variable noDays noDays = 28; } } } else { //if an invalid month, display the message that the given month is invalid cout << "Invalid Month" << endl; //set the value of the variable dMonth to 0 dMonth = 0; } //return the value of the variable noDays return noDays; } //define the function setDate void dateType::setDate(int month, int day, int year) { if (year >= 1) dYear = year; else dYear = 1990; if (1 <= month && month <= 12)//validating month range 1-12 dMonth = month; else dMonth = 1; switch (dMonth) { //jan, march, may, july, aug, oct, and dec all have 31 days case 1: case 3: case 5: case 7: case 8: case 10: case 12: if (1 <= day && day <= 31) dDay = day; else dDay = 1; break; //months april, june, sept, and nov all have 30 days case 4: case 6: case 9: case 11: if (1 <= day && day <= 30) dDay = day; else dDay = 1; break; //feb DEPENDS case 2: if (isLeapYear(year))//check to see if leap year { if (1 <= day && day <= 29)//true dDay = day; else dDay = 1; } else { if (1 <= day && day <= 28)//false dDay = day; else dDay = 1; } } } //define the function getDay int dateType::getDay() const { return dDay; } //define the function getMonth int dateType::getMonth() const { return dMonth; } //define the function getYear int dateType::getYear() const { return dYear; } //define the function printDate void dateType::printDate() const { cout << " " << dMonth << "-" << dDay << "-" << dYear; } //constructor with parameters dateType::dateType(int month, int day, int year) { setDate(month,day,year); } //define the function isLeapYear bool dateType::isLeapYear(int year) { //function to see if the year picked is actually a leap year if (((dYear % 4 == 0) && (dYear % 100 != 0))|| dYear % 400 == 0) return true; else return false; }

*******************extDateTypeImp.cpp******************

//preprocessor directives and header files #include "extDateType.h" #include "dateType.h" #include  //standard library using namespace std; //define the function setDate void extDateType::setDate(int month, int day, int year) { if (year >= 1) eYear = year; else eYear = 1990; if (1 <= month && month <= 12)//validating month range 1-12 eMonth = month; else eMonth = 1; switch (eMonth) { //jan, march, may, july, aug, oct, and dec all have 31 days case 1: case 3: case 5: case 7: case 8: case 10: case 12: if (1 <= day && day <= 31) eDay = day; else eDay = 1; break; //months april, june, sept, and nov all have 30 days case 4: case 6: case 9: case 11: if (1 <= day && day <= 30) eDay = day; else eDay = 1; break; //feb DEPENDS case 2: if (isLeapYear(year))//check to see if leap year { if (1 <= day && day <= 29)//true eDay = day; else eDay = 1; } else { if (1 <= day && day <= 28)//false eDay = day; else eDay = 1; } } } //function definition for printLongDate void extDateType::printLongDate() { cout << " " << eMonths << " " << eDay << ", " << eYear << endl; } //function definition for setMonth void extDateType::setMonth(int month, string mNames[], const int SIZE) { //since arrays are 0 based we have the use the value stored one element back eMonths = mNames[month - 1]; //store the string for the months name into the private variable } //constructor based on dateType.cpp extDateType::extDateType(int month, int day, int year) { setDate(month,day,year); }

**************calendarTypeImp.cpp**************

//preprocessor directives #include "calendarType.h" #include "extDateType.h" #include "dateType.h" #include  #include  #include  //standard library using namespace std; //define the function getMonth int calendarType::getMonth() const { return cMonth; } //define the function getYear int calendarType::getYear() const { return cYear; } //define the function setDate void calendarType::setDate(int month, int day, int year) { if (year >= 1) cYear = year; else cYear = 1990; if (1 <= month && month <= 12)//validating month range 1-12 cMonth = month; else cMonth = 1; switch (cMonth) { //jan, march, may, july, aug, oct, and dec all have 31 days case 1: case 3: case 5: case 7: case 8: case 10: case 12: if (1 <= day && day <= 31) cDay = day; else cDay = 1; break; //months april, june, sept, and nov all have 30 days case 4: case 6: case 9: case 11: if (1 <= day && day <= 30) cDay = day; else cDay = 1; break; //feb DEPENDS case 2: if (isLeapYear(year))//check to see if leap year { if (1 <= day && day <= 29)//true cDay = day; else cDay = 1; } else { if (1 <= day && day <= 28)//false cDay = day; else cDay = 1; } } } //function definition for setMonth void calendarType::setMonth(int month, string mNames[], const int SIZE) { cMonthNames = mNames[month - 1]; //store the string for the months name into the private variable } //define the function firstDayOfMonth int calendarType::firstDayOfMonth() { int month = this->cMonth;//assign the value in cMonth to month //using the this pointer int year = this->cYear;//assign the value in cYear to year //using the this pointer int day = 1; int y = year - (14 - month)/12; int m = month + 12 * ((14 - month) / 12) - 2; //this statement determines the firstDay by //modulus 7 to tell which day of the week in wDays is needed firstDay = (day + y + y / 4 - y / 100 + y / 400 + (31 * m / 12)) % 7; return firstDay; } //define the function printMonthCalendar void calendarType::printMonthCalendar() { //variable to hold the number of days in a specific month int numberOfDaysInMonth; //counter to make sure to watch how many days //have passed before a new week int dayOfWeekCounter = 0; cout << endl;//whitespace //switch statement to print the months name for the calendar //and store the number of days for a specific month; switch (cMonth) { case 1: cout< 6)//statement to move to a new week { cout<<" "<                    

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Why can't the private market provide a public good?

Answered: 1 week ago

Question

Design a job advertisement.

Answered: 1 week ago