Answered Essay: The class dateType defined in the previous project prints the date in numerical form. Some

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:

UML Diagram

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

Once you have completed this project, you will demonstrate that you are able to:

Extend a base class utilizing inheritance.

Access the public members of the base class from the derived class.

Apply the constructor of the base class from the derived class.

Expert Answer

 

Below is your code: –

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

Output screen after running it : –

Buy Essay
Calculate your paper price
Pages (550 words)
Approximate price: -

Help Me Write My Essay - Reasons:

Best Online Essay Writing Service

We strive to give our customers the best online essay writing experience. We Make sure essays are submitted on time and all the instructions are followed.

Our Writers are Experienced and Professional

Our essay writing service is founded on professional writers who are on stand by to help you any time.

Free Revision Fo all Essays

Sometimes you may require our writers to add on a point to make your essay as customised as possible, we will give you unlimited times to do this. And we will do it for free.

Timely Essay(s)

We understand the frustrations that comes with late essays and our writers are extra careful to not violate this term. Our support team is always engauging our writers to help you have your essay ahead of time.

Customised Essays &100% Confidential

Our Online writing Service has zero torelance for plagiarised papers. We have plagiarism checking tool that generate plagiarism reports just to make sure you are satisfied.

24/7 Customer Support

Our agents are ready to help you around the clock. Please feel free to reach out and enquire about anything.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

HOW OUR ONLINE ESSAY WRITING SERVICE WORKS

Let us write that nagging essay.

STEP 1

Submit Your Essay/Homework Instructions

By clicking on the "PLACE ORDER" button, tell us your requires. Be precise for an accurate customised essay. You may also upload any reading materials where applicable.

STEP 2

Pick A & Writer

Our ordering form will provide you with a list of writers and their feedbacks. At step 2, its time select a writer. Our online agents are on stand by to help you just in case.

STEP 3

Editing (OUR PART)

At this stage, our editor will go through your essay and make sure your writer did meet all the instructions.

STEP 4

Receive your Paper

After Editing, your paper will be sent to you via email.

× How can I help you?