Question
Using the classes extDateType from the Chapter 11 class projects and dayType from the Chapter 10 class projects, design the class calendarType so that, given
Using the classes extDateType from the Chapter 11 class projects and dayType from the Chapter 10 class projects, design the class calendarType so that, given the month and the year, you 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. Your calendarType class will have two private instance variables: firstDay of type dayType to hold the first day of the month and date of type extDateType to hold the month and year for the calendar. The calendarType object must use as much of the functionality of its object variables as possible. In fact, the only functionality required of calendarType is to determine the first day of the month and to actually print the calendar
dayType chap 10
//Header file
#include
class dayType { public: dayType();
string day[8]; int dayNumber; int tempDay;
void setDay(int day); void printDay(); void returnDay(int &day); void returnNextDay(); void returnPreviousDay(); void calculateDay(int changeDay);
};
//Implementation file
#include
using namespace std;
void dayType::printDay() { cout << "Today is: " << day[dayNumber] << "day" << endl;};
void dayType::setDay(int day) { dayNumber=day;};
void dayType::returnDay(int &day) { day=dayNumber;};
void dayType::returnNextDay() { dayNumber++;};
void dayType::returnPreviousDay() { dayNumber--;};
void dayType::calculateDay(int changeDay) { tempDay=(dayNumber+changeDay); dayNumber=(tempDay%7);};
//Main file
#include
using namespace std;
int main() { dayType today;
int day; int changeDay;
cout << "------------------------------------------------------------------" << endl; cout << "Default day is Sunday " << endl; cout << "Type in a number corresponding to set the day" << endl << "1: Monday" << endl << "2: Tuesday" << endl << "3: Wednesday" << endl << "4: Thursday" << endl << "5: Friday" << endl << "6: Saturday" << endl << "7: Sunday" << endl;
while (day<0 || day>7) cin >> day;
today.setDay(day); today.printDay();
today.returnDay(day); today.printDay();
cout << "-----------------------------------------------------------------" << endl; cout << "If it were tomorrow, then the following statement would be true: " << endl; today.returnNextDay(); today.printDay(); today.dayNumber--;
cout << "-----------------------------------------------------------------" << endl; cout << "If it were yesterday, then the following statement would be true:" << endl; today.returnPreviousDay(); today.printDay(); today.dayNumber++;
cout << "-----------------------------------------------------------------" << endl; cout << "Add a number of days to today and see what day it will be: " << endl; cin >> changeDay;
today.calculateDay(changeDay); today.printDay();
return 0; };
dayType::dayType() { dayNumber=1; day[1]="Mon"; day[2]="Tues"; day[3]="Wednes"; day[4]="Thurs"; day[5]="Fri"; day[6]="Satur"; day[7]="Sun"; };
extDateType
extDateType.h
#pragma once
#include
#include "dateType.h"
using namespace std;
class extDateType: public dateType
{
public:
static string Name_Month[12];
void printLongDate();
void setDate(int, int, int);
void setMonth(int m);
void printLongMonthYear();
extDateType();
extDateType(int, int, int);
private:
string dName_Month;
};
extDateTypeImp.cpp
#include
#include
#include "dateType.h"
#include "extDateType.h"
using namespace std;
// give the names of the month in order to format it out
void extDateType::printLongDate()
{
cout << dName_Month << " " << get_day() << ", " << get_Year();
}
void extDateType::printLongMonthYear()
{
cout << dName_Month << " " << get_Year();
}
void extDateType::setDate(int m, int d, int y)
{
dateType::setDate(m, d, y);
dName_Month = Name_Month[m - 1];
}
void extDateType::setMonth(int m)
{
dateType::setMonth(m);
dName_Month = Name_Month[m - 1];
}
string extDateType::Name_Month[] = {"January", "February", "March", "April",
"May", "June", "July", "August",
"September", "October", "November", "December"};
extDateType::extDateType()
{
dName_Month = "January";
}
extDateType::extDateType(int m, int n, int d)
: dateType(m, n, d)
{
dName_Month = Name_Month[m - 1];
}
dateType.h
#pragma once
class dateType
{
public:
dateType (int month=1, int day=1, int year=0001);
void setDate(int month, int day, int year);
void setMonth(int);
void setDay(int);
void setYear(int);
void print() const;
int numberOfDaysLeft();
int numberOfDaysPassed();
void ADD_TO_DATE(int nDays);
int get_Month() const;
int get_day() const;
int get_Year() const;
int get_num_days_month();
bool Leap_Year();
private:
int z_Month;
int z_Day;
int z_Year;
};
dateTypeImp.cpp
#include
#include "dateType.h"
using namespace std;
void dateType::setDate(int month, int day, int year)
{
if (year >= 1)
z_Year = year;
else
z_Year = 0001;
if (1 <= month && month <= 12)
z_Month = month;
else
z_Month = 1;
switch (z_Month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
if(1 <= day && day <= 31)
z_Day = day;
else
z_Day = 1;
break;
case 4:
case 6:
case 9:
case 11:
if (1 <= day && day <= 30)
z_Day = day;
else
z_Day = 1;
break;
case 2: if (Leap_Year())
{
if (1 <= day && day <= 29)
z_Day = day;
else
z_Day = 1;
}
else
{
if (1 <= day && day <= 28)
z_Day = day;
else
z_Day = 1;
}
}
}
void dateType::setMonth(int m)
{
z_Month = m;
}
void dateType::setDay(int d)
{
z_Day = d;
}
void dateType::setYear(int y)
{
z_Year = y;
}
void dateType::print() const
{
cout << z_Month << "-" << z_Day << "-" << z_Year;
}
int dateType::get_Month() const
{
return z_Month;
}
int dateType::get_day() const
{
return z_Day;
}
int dateType::get_Year() const
{
return z_Year;
}
int dateType::get_num_days_month()
{
int numDays;
switch (z_Month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
numDays = 31;
break;
case 4:
case 6:
case 9:
case 11:
numDays = 30;
break;
case 2: if(Leap_Year())
numDays = 29;
else
numDays = 28;
}
return numDays;
}
bool dateType::Leap_Year()
{
if (((z_Year % 4 == 0) && (z_Year % 100 != 0)) || z_Year % 400 == 0)
return true;
else
return false;
}
dateType::dateType(int month, int day, int year)
{
z_Month = month;
z_Day = day;
z_Year = year;
}
int dateType::numberOfDaysPassed()
{
int dayspassed=0;
for (int month=1;month dayspassed+=get_day(); dayspassed+=get_day(); return dayspassed; } int dateType::numberOfDaysLeft() { int daysleft; int days_passed=0; for (int month=1;month days_passed+=get_day(); if (Leap_Year()) return 366 - numberOfDaysPassed(); else return 365 - numberOfDaysPassed(); return daysleft; }; void dateType::ADD_TO_DATE(int nDays) { int day=get_day()+nDays; int month=get_Month(); int countm=0; int year=0; while (day>get_day()+nDays) { day=day-get_day(); countm++; if (countm==12) { year++; countm=0; } if(month>=12) month=0; month++; } setMonth (get_Month()+countm); setDay(day); setYear (get_Year()+year); } main.cpp #include using namespace std; int main() { dateType d(1, 2, 1960); extDateType ed(6, 10, 1981); int num; ed.printLongDate(); cout << endl; ed.print(); cout << endl; cout << "Days gone in the year: " << ed.numberOfDaysPassed(); cout << endl; cout << "Days left in the Year: " << ed.numberOfDaysLeft() << endl; ed.print(); cout << endl; system("pause"); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started