Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Chapter 11 Programming Exercise #9 Using the classes extDateType (Programming Exercise 8) and dayType (Chapter 10, Programming Exercise 5), design the class calendarType so that,

Chapter 11 Programming Exercise #9

Using the classes extDateType (Programming Exercise 8) and dayType (Chapter 10, Programming Exercise 5), design the class calendarType so that, given the month and the year, we can print the calendar for that month. To print a monthly calendar, you must know the first day of the month and the number of days in that month. Thus, you must store the first day of the month, which is of the form dayType, and the month and the year of the calendar. Clearly, the month and the year can be stored in an object of the form extDateType by setting the day component of the date to 1 and the month and year as specified by the user. Thus, the class calendarType has two member variables: an object of the type dayType and an object of the type extDateType.

Design the class calendarType so that the program can print a calendar for any month starting January 1, 1500. Note that the day for January 1 of the year 1500 is a Monday. To calculate the first day of a month, you can add the appropriate days to Monday of January 1, 1500. For the class calendarType, include the following operations:

a. Determine the first day of the month for which the calendar will be printed. Call this operation firstDayOfMonth.

b. Set the month.

c. Set the year.

d. Return the month.

e. Return the year.

f. Print the calendar for the particular month.

g. Add the appropriate constructors to initialize the member variables.

Here is what the output should look like:

image text in transcribed

Prior to this, I have completed some programming exercises that had led up to this exercise which granted me the output(without completing P.E. #9):

image text in transcribed

I am wanting to figure out how to get the 1st image's output as I am currently working out my definitions of my setdate.h file while removing any errors.

I have provided the code below.

Note: I Intentionally left dateTypeImp.cpp untouched when the error displays that it was already defined. The problem is what arises when you remove these excess redefinitions as more errors become apparent with the definitions.

Note: Please actually help me on this and not just create a new program answering the programming exercise question while disregarding the provided code.

main.cpp

//Header files #include #include #include "extDateType.h" #include "datetype.h" #include "DAYTYPE.H" #include "setdate.h"

//Standard Library using namespace std;

//Start the main() function.

int main()

{

//Friendly message explaining the purpose of the program //Honestly I'm just going to keep adding on to the friendly message in future assignments. cout

//Declare the required variables. int m, d, y, numDays, passed, remain;

//Declare new mon variable array for new format char mon[30];

//Create an object of the class and initialize it using constructor of the class. dateType date(0, 0, 0);

//create the derived class extDateType newmonth();

//Display the message to input the month of the date. cout

//Prompt the user to input the month of the date. cin >> m;

//Display the message to input the day of the date. cout

//Prompt the user to input the day of the date. cin >> d;

//Display the message to input the year of the date. cout

//Prompt the user to input the year of the date. cin >> y;

//Call the setYear function to set the year. date.setYear(y);

//Declare a boolean variable check to check whether the year is a leap year or not. bool check = date.isLeapYear(y);

//If the value of the variable check is not equal to false. if (check) //Display the message that the given year is a leap year.

cout

else //Display the message that the given year is not a leap year.

cout

//Call the setMonth function to set the month of the //date and to find the number of days in the current month numDays = date.setMonth(m);

//Display the number of days in the current month. cout

//Call the totalNumOfpassedDays function to calculate //the number of the days passed in the current year. passed = date.totalNumOfpassedDays(m, d);

//Display the number of the days passed in the current year cout

//Call the RemainingDays function to find the number of days remaining in the year. remain = date.RemainingDays(y);

//Display the number of the days remaining in the current year.

cout

//Call the NewDate function to calculate the new date. date.NewDate(3, 18, 2019, 25);

//Display the new date by calling the printDate function. cout

date.printDate();

//Prompt the user to enter the month in words //for new formatting purposes cout > mon;

cout

return 0; }

datetype.h

#ifndef DATETYPE_H_INCLUDED #define DATETYPE_H_INCLUDED

//Define the class dateType.

class dateType

{

//Declare the required variables under the //private access specifier. private: //Declare an integer variable to store the month. int dMonth;

//Declare an integer variable to store the day. int dDay;

//Declare an integer variable to store the year. int dYear;

//Declare an integer variable to store the number //of days in a month. int noDays;

//Declare an integer variable to store the number //of days passed in a year. int Passeddays;

//Declare the required member functions under the //public access specifier. public:

//Define the function setDate to set the full date void setDate(int month, int day, int year);

//Define the function setMonth to set the month of //the date. int setMonth(int month);

//Define the function setDay to set the day of //the date. void setDay(int day);

//Define the function setYear to set the year of //the date. void setYear(int year);

//Define the function getDay to get the day of //the date. int getDay() const;

//Define the function getMonth to get the month of //the date. int getMonth() const;

//Define the function getYear to get the year of //the date. int getYear() const;

//Declare the function printDate to print the date. void printDate() const;

//Declare the function isLeapYear to check whether a //year is leap year or not. bool isLeapYear(int year);

//Declare the function totalNumOfpassedDays to get //the number of days passed in a year. int totalNumOfpassedDays(int, int);

//Declare the function RemainingDays to find the /umber of remaining days in a year. int RemainingDays(int);

//Declare the function NewDate to calculate the new //date.

int NewDate(int, int, int, int);

//Declare the constructor of the class. dateType(int month = 0, int day = 1, int year = 1500);

};

#endif // DATETYPE_H_INCLUDED

DAYTYPE.h

#ifndef DAYTYPE_H_INCLUDED #define DAYTYPE_H_INCLUDED

#include #include #include "datetype.h" #include "extDateType.h" #include "setdate.h" #include

using namespace std;

class dayType: public dateType, public extDateType

{

public: //Declaring an array weekdays of string type and it is made as static

static string weekdays[7]; void setDay (string d); void print() const;

//Declaring getday function as const string getDay() const;

//Declaring nextDay function as const string nextDay() const;

//Declaring prevDay function as const string prevDay() const;

void addCalDay(int nDays);

dayType();

dayType(string d);

private: string weekday; };

#endif // DAYTYPE_H_INCLUDED

extDateType.h

#ifndef EXTDATETYPE_H_INCLUDED #define EXTDATETYPE_H_INCLUDED

#include #include #include "datetype.h" #include "extDateType.h" #include #include "setdate.h"

using namespace std;

//Base class extDateType class extDateType

{

public: static string months [12];

void setData(int, int, int);

string getMonth() const;

int getDay() const;

int getYear() const;

void printDate() const;

extDateType(int month = 0, int day = 1, int year = 1500);

private: //Declaration of yMonth to store the month string yMonth;

//Declaring yDay to store the day int yDay;

//Declaring yYear to store the year int yYear; };

#endif // EXTDATETYPE_H_INCLUDED

setdate.h

#ifndef SETDATE_H_INCLUDED #define SETDATE_H_INCLUDED

//Define the function getDay to get the day of the date. int dateType::getDay() const { //Return the day of the date. return dDay; }

//Define the function getMonth to get the month of the date. int dateType::getMonth() const

{ //Return the month of the date. return dMonth;

} //Define the function getYear to get the year of the date. int dateType::getYear() const { //Return the year of the date. return dYear; }

//Define the constructor of the class with the required parameters. dateType::dateType(int month, int day, int year) { //Initialize the day, month, year of the given date. dMonth = month; dDay = day; dYear = year;

}

#endif // SETDATE_H_INCLUDED

dateTypeImp.cpp

//Header files #include #include #include "datetype.h" #include "extDateType.h" #include "DAYTYPE.H" #include "setdate.h"

//Standard Library using namespace std;

//Define the function totalNumOfpassedDays to find the /umber of days passed in a year. int dateType::totalNumOfpassedDays(int month, int day) {

//Declare an integer variable to calculate the passed //days in a year. int i, passedDays = 0;

//Start the for loop from 1 to 12. for (i = 1; i

//Add the days of the current month passedDays += day;

//Store the value of the passedDays into the variable Passeddays. Passeddays = passedDays;

//Return the value of the variable passeddays. return passedDays;

}

//Define the function NewDate to calculate the new date. int dateType::NewDate(int month, int day, int year,

int adddays)

{ //Check whether the value of the total days % month is equal to 0 or not.

if ((day + adddays) % month) { //Add the number of days to be added in the date to the day of the previous date. dDay = day + adddays;

//Check if the total number of days is greater than 31. if (dDay>31)

{ //Find the absolute value of the days. dDay = abs(dDay - 31);

//Increase the month if the number of days is greater than 31. month++;

}

//Store the final value of the month into the variable dMonth. dMonth = month;

//Check if the value of the variable month is greater than 12. if (month>12)

{ //Assign 1 to the variable dMonth. dMonth = 1;

//Increase the value of the variable dYear. dYear++;

}

}

//Return an integer value to the function. return 0; }

//Define the function to find the remaining days in a year. int dateType::RemainingDays(int year) { //Declare an integer variable to store the number of days remaining in a year. int remainingDays;

//Check whether the returned value of the function isLeapYear is not equal to the false. if (isLeapYear(year))

{ //Calculate the remaining days in a leap year. remainingDays = 366 - Passeddays;

} else //Calculate the remaining days in a year. remainingDays = 365 - Passeddays;

//Return the total number of the days remaining in a year. return remainingDays;

}

void dateType::setDate(int month, int day, int year) { if (year >= 1) dYear = year; else dYear = 1500; if (1

switch(dMonth) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: if(1

} } int dateType::getDay()const { return dDay; } int dateType::getMonth()const { return dMonth; } int dateType::getYear()const { return dYear; }

//Checking whether the year is a leap year bool dateType::isLeapYear(int year) { if (((dYear % 4 == 0)&& (dYear % 100 !=0))|| dYear % 400 == 0) return true; else return false; }

//Function printDate void dateType:: printDate()const { cout

//Constructor dateType with three parameters dateType::dateType(int month, int day, int year) { setDate(month, day, year); }

DAYTYPE.cpp.

//Header files #include #include #include "datetype.h" #include "extDateType.h" #include "DAYTYPE.H" #include

//Standard Library using namespace std;

//Initialize weekdays of dayType string dayType::weekdays[7] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

//print function to print the weekday void dayType::print()const { cout

//Function setDay void dayType::setDay(string d) { weekday = d; } //Function addCalDay void dayType::addCalDay(int nDays) { int i; for ( i = 0; i

//Function dayType without parameter dayType::dayType() { weekday = "Monday"; } //Function dayType with a string as a parameter dayType::dayType(string d) { weekday = d; }

extDateType.cpp

//Header files #include #include #include "datetype.h" #include "extDateType.h" #include "DAYTYPE.H" #include

//Standard Library using namespace std;

//Declaring months of extDateType string extDateType::months[12] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};

//setData function void extDateType::setData(int month, int day, int year) { int p; for (p = 0; p

break; yMonth = months[(p+month) % 13]; yDay = day; yYear = year; } //getmonth function string extDateType::getMonth()const

{ return yMonth; }

//getday function int extDateType::getDay() const { return yDay; }

//getyear function int extDateType::getYear() const { return yYear; }

//printDate function void extDateType::printDate() const { cout

int i;

//Declaring dayHeader of string type string dayHeader; dayHeader = string("Sun") + char(186) + "Mon" + char(186) + "Tue" + char(186) + "Wed" + char(186) + "Thu" + char(186) + "Fri" + char(186) + "Sat" + char(186);

//for loop for (int p = 0; p

extDateType::extDateType(int month, int day, int year) { yMonth = month; yDay = day; yYear = year; }

Godspeed

I can post my previous code before my attempt with this exercise if need be.

Output: 1500 January SMTWTFS 123456 7 89 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

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

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What sorts of conflicts does the character use Anger for?

Answered: 1 week ago