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

C++ The class dateType defined in the previous project prints the date in numeri

ID: 3585387 • Letter: C

Question

C++

The class dateType defined in the previous project prints the date in numerical form. Some applications might require the date to be printed in another form, such as March 24, 2017. Derive the class extDateType and add member functions so that the date can be printed these forms:

March 24, 2017

March, 2017

Copy over dateType.h and dateType.cpp. Create a static array to hold the month names and static functions to access and modify the defaults. Write an appropriate constructor for the derived class. Write a program to test the extDateType class.

Here is the UML diagram for this class:

Turn in extDateClass.h, extDateClass.cpp, and your test program. Also turn in one or more screen shots showing the results of your testing.

**********************************************************

***********************************************************

Please make it match my code from last question here your go

#include <iostream>

using namespace std;

class Date{

  

private:

int day, month, year;

static Date defaultDate;

public:

void setDefaultDate(int aDay,int aMonth, int aYear);

void setDay(int aDay);

int getDay() const;

void addDay(int x);

void setMonth(int aMonth);

int getMonth() const;

void addMonth(int x);

void setYear(int aYear);

int getYear() const;

void addYear(int x);

int day_of_remain();

int day_of_passed();

bool leapYear(int x)const;

Date(int aDay , int aMonth, int aYear);

void setDate(int aDay , int aMonth, int aYear);

~Date(); //Destructor

};

  

Date Date::defaultDate(1,1,1500);

Date::Date(int aDay, int aMonth, int aYear)

{

if(aDay==0)

{

this->day = defaultDate.day;

}

else

{

setDay(aDay);

}

if(aMonth==0)

{

this->month = defaultDate.month;

}

else

{

setMonth(aMonth);

}

if(aYear==0)

{

this->year = defaultDate.year;

}

else

{

setYear(aYear);

}

}

int Date:: day_of_remain()

{

if(leapYear(year))

return (366 - day_of_passed());

else

return (365 - day_of_passed());

}

int Date:: day_of_passed()

{

int count[]={0,31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365};

if ((year % 4==0) && (year % 100 != 0) && (year % 400 == 0 )&& (month>=2)) ((count[month]+day)+1);

return (count[month-1]+day);

}

void Date::setMonth(int a) {

if(a > 0 && a <= 12)

{

month = a;

}

}

int Date:: getMonth() const {

return month;

}

void Date::addYear(int x)

{

year += x;

if(day == 29 && month == 2 && !leapYear(year))

{

day = 1;

month = 3;

}

}

bool Date::leapYear(int x) const {

if((x%4 == 0 && x%100 != 0) || (x%400==0))

{

return true;

}

else

{

return false;

}

}

void Date::setYear(int aYear){

year=aYear;

}

void Date::setDay(int aDay){

day=aDay;

  

}

  

void Date::setDate(int aDay , int aMonth, int aYear){

setDay(aDay);

setMonth(aMonth);

setYear(aYear);

cout<<month<<"/"<<day<<"/"<<year<<endl;

}

Date::~Date(){

cout<<"Date destructor"<<endl;

}

#include "DateType.h"

using namespace std;

int main()

{

Date MyDate(0,0,0);

MyDate.setDate(1,10,2017);

if(MyDate.leapYear(2017))

cout << "It is leap year ";

else

cout << "It is leap year ";

cout<<" remaining day of the year :"<<MyDate.day_of_remain();

cout<<" remaining day of the year :"<< MyDate.day_of_passed()<<endl;

}

is main file

Explanation / Answer

//DateType.h

#include <iostream>

using namespace std;

class Date{

private:

int day, month, year;

static Date defaultDate;

public:

void setDefaultDate(int aDay, int aMonth, int aYear);

void setDay(int aDay);

int getDay() const;

void addDay(int x);

void setMonth(int aMonth);

int getMonth() const;

void addMonth(int x);

void setYear(int aYear);

int getYear() const;

void addYear(int x);

int day_of_remain();

int day_of_passed();

bool leapYear(int x)const;

Date(int aDay, int aMonth, int aYear);

void setDate(int aDay, int aMonth, int aYear);

~Date(); //Destructor

};

-----------------------------------------------------------

//DateType.cpp

#include"DateType.h"

Date Date::defaultDate(1, 1, 1500);

Date::Date(int aDay, int aMonth, int aYear)

{

if (aDay == 0)

{

this->day = defaultDate.day;

}

else

{

setDay(aDay);

}

if (aMonth == 0)

{

this->month = defaultDate.month;

}

else

{

setMonth(aMonth);

}

if (aYear == 0)

{

this->year = defaultDate.year;

}

else

{

setYear(aYear);

}

}

int Date::day_of_remain()

{

if (leapYear(year))

return (366 - day_of_passed());

else

return (365 - day_of_passed());

}

int Date::day_of_passed()

{

int count[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };

if ((year % 4 == 0) && (year % 100 != 0) && (year % 400 == 0) && (month >= 2)) ((count[month] + day) + 1);

return (count[month - 1] + day);

}

void Date::setMonth(int a) {

if (a > 0 && a <= 12)

{

month = a;

}

}

int Date::getMonth() const {

return month;

}

void Date::addYear(int x)

{

year += x;

if (day == 29 && month == 2 && !leapYear(year))

{

day = 1;

month = 3;

}

}

bool Date::leapYear(int x) const {

if ((x % 4 == 0 && x % 100 != 0) || (x % 400 == 0))

{

return true;

}

else

{

return false;

}

}

void Date::setYear(int aYear){

year = aYear;

}

void Date::setDay(int aDay){

day = aDay;

}

void Date::setDate(int aDay, int aMonth, int aYear){

setDay(aDay);

setMonth(aMonth);

setYear(aYear);

cout << month << "/" << day << "/" << year << endl;

}

Date::~Date(){

cout << "Date destructor" << endl;

}

//added by cheggEA

int Date::getDay() const

{

return day;

}

//added by cheggEA

int Date::getYear() const

{

return year;

}

---------------------------------

//extDateType.h

#include"DateType.h"

#include<string>

class extDateType : public Date

{

static string arr_month[12];

public:

extDateType(string month, int day, int yr);

static void modify();

int getMonth(string );

void setMonth(string month);

void setDate(int day, string month, int yr);

void print();

};

--------------------------------

//extDateType.cpp

#include"extDateType.h"

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

extDateType::extDateType(string month, int day, int yr) :Date(day, getMonth(month), yr)

{

}

void extDateType::setMonth(string month)

{

int index;

for (int i = 0; i < 12; i++)

{

if (month.compare(arr_month[i]) == 0)

{

index = i;

break;

}

}

Date::setMonth(index + 1);

}

int extDateType::getMonth(string month)

{

int index = 0;

for (int i = 0; i < 12; i++)

{

if (month == arr_month[i])

{

index = i;

break;

}

}

return index+1;

}

void extDateType::setDate(int day, string month, int yr)

{

Date::setDate(day, getMonth(month), yr);

}

void extDateType::print()

{

cout << arr_month[Date::getMonth() - 1] << " " << getDay() << " " << getYear() << endl;

}

-----------------------------------------------------

//modified main

#include"extDateType.h"

using namespace std;

int main()

{

Date MyDate(0, 0, 0);

MyDate.setDate(1, 10, 2017);

if (MyDate.leapYear(2017))

cout << "It is leap year ";

else

cout << "It is leap year ";

cout << " remaining day of the year :" << MyDate.day_of_remain();

cout << " remaining day of the year :" << MyDate.day_of_passed() << endl;

//testing exDatetype

extDateType newdate("January",0,0);

newdate.setDate(24,"March", 2017);

newdate.print();

}

-----------------------------------------------

//output

10/1/2017
It is leap year

remaining day of the year :91
remaining day of the year :274
3/24/2017
March 24 2017

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