Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using the classes extDateType from the Chapter 11 class projects and dayType fro

ID: 3875851 • Letter: U

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 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<iostream>
#include<string>
using namespace std;

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 <iostream>
#include <string>


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 <iostream>


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 <string>

#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 <iostream>

#include <string>

#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 <iostream>

#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<get_Month();month++)

dayspassed+=get_day();

dayspassed+=get_day();

return dayspassed;

}

int dateType::numberOfDaysLeft()

{

int daysleft;

int days_passed=0;

for (int month=1;month<get_Month();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 <iostream>
#include "dateType.h"
#include "extDateType.h"

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;
}

Explanation / Answer

here is your Calender.cpp : ----------------------------->>>>>>>>>>>>

#include<iostream>
#include<ctime>
#include "dayType.cpp"
#include "extDateType.cpp"


using namespace std;

class Calender{
extDateType date;
dayType day;
public:
  Calender(){
   time_t now = time(0);
   tm *ltm = localtime(&now);
   date.setDate(1+ltm->tm_mon,ltm->tm_mday,1900+ltm->tm_year);
   day.setDay(ltm->tm_wday);
  }
  
  void showDayView(){
   system("cls");
   cout<<" ";
   date.printLongDate();
   cout<<" ";
   day.printDay();
  }
  void showNextDay(){
   if(date.get_day() == date.get_num_days_month()){
    if(date.get_Month() == 12){
     date.setYear(date.get_Year() + 1);
     date.setMonth(1);
    }
    else{
     date.setMonth(date.get_Month() + 1);
    }
    date.setDay(1);
   }
   else{
    date.ADD_TO_DATE(1);
   }
   day.returnNextDay();
  }
  void showPrevDay(){
   int temp = date.get_Month();
   if(date.get_day() == 1){
    if(date.get_Month() == 1){
     date.setYear(date.get_Year() - 1);
     date.setMonth(12);
    }
    else{
     date.setMonth(date.get_Month() - 1);
    }
    date.setDay(date.get_num_days_month());
   }
   else{
    date.setDay(date.get_day() - 1);
   }
   day.calculateDay(6);
  }
  
  void showMonthView(){
   system("cls");
   int temp = date.get_Month();
   while(temp == date.get_Month()){
    showPrevDay();
   }
   showNextDay();
   cout<<"                              ";
   date.printLongMonthYear();
   cout<<" ";
   cout<<" ------------------------------------------------------------------------------- ";
   cout<<" ------------------------------------------------------------------------------- ";
   cout<<" |                                                                             |";
   cout<<" |   Monday     Tuesday    Wednesday Thursday   Friday     Saturday   Sunday | ";
   cout<<" |                                                                             |";
   cout<<" |";
   int wkday;
   day.returnDay(wkday);
   for(int i = 1;i<wkday;i++){
    cout<<"           ";
   }
   int dtemp = wkday;
   for(int i = wkday-1;i<=31+dtemp+9;i++){
    if(i%7 == 0 && i != dtemp-1){
     cout<<"|";
     cout<<endl;
     cout<<" |                                                                             |";
     if(temp == date.get_Month())
      cout<<" |";
     else{
      showPrevDay();
      break;
     }
    }
    if(date.get_day() < 10){
     cout<<" ";
    }
    if(temp == date.get_Month()){
     cout<<"     "<<date.get_day()<<"    ";
     showNextDay();
    }
    else{
     cout<<"          ";
    }
   }
   cout<<" ------------------------------------------------------------------------------- ";
   cout<<" -------------------------------------------------------------------------------";
  }
  
  void showPrevMonth(){
   int temp = date.get_Month();
   for(int i = 0;i<= 31;i++){
    if(date.get_Month() == temp){
     showPrevDay();
    }
    else{
     showPrevDay();
     break;
    }
   }
  }
  
  void showNextMonth(){
   int temp = date.get_Month();
   for(int i = 0;i<=31;i++){
    if(date.get_Month() == temp){
     showNextDay();
    }
    else{
     break;
    }
   }
  }
  
};

void printMenu(){
system("cls");
cout<<"-------------------------------- Welcome To Calender App ----------------------------------- ";
cout<<" 1. Show Day View Calender ";
cout<<" 2. Show Month View Calender ";
cout<<" 3. Exit ";
}

void printSubMenu1(){
cout<<" 1. Show Next Day ";
cout<<" 2. Show Prev Day ";
cout<<" 3. Exit ";
}
void printSubMenu2(){
cout<<" 1. Show Next Month ";
cout<<" 2. Show Prev Month ";
cout<<" 3. Exit ";
}

int main(){
Calender c;
char choice = '0';

while(choice != '3'){
  printMenu();
  cin>>choice;
  switch(choice){
   case '1':
    {
     char ch = '0';
     while(ch != '3'){
      c.showDayView();
      printSubMenu1();
      cin>>ch;
      if(ch == '1'){
       c.showNextDay();
      }
      if(ch == '2'){
       c.showPrevDay();
      }
      if(ch == '3'){
       c = Calender();
      }
     }
     break;
    }
   case '2':
    {
     char ch = '0';
     while(ch != '3'){
      c.showMonthView();
      printSubMenu2();
      cin>>ch;
      if(ch == '1'){
       c.showNextMonth();
      }
      if(ch == '2'){
       c.showPrevMonth();
      }
      if(ch == '3'){
       c = Calender();
      }
     }
     break;
    }
  }  
}

return 0;
}

small changes to dayType Implementation : ------------------>>>>>>>>>>>>>>>

//Implementation file
#pragma once
#include <iostream>
#include <string>
#include "dayType.h"

using namespace std;
dayType::dayType(){
}
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);};

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote