Can anyone help me write extDateTypeImp.cpp, I already have the codes listed below. That is the only header file I am mi

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Can anyone help me write extDateTypeImp.cpp, I already have the codes listed below. That is the only header file I am mi

Post by answerhappygod »

Can anyone help me write extDateTypeImp.cpp, I already
have the codes listed below.
That is the only header file I am missing.
The class dateType defined in Programming
Exercise 6 prints the date in numerical form. Some
applications might require the date to be printed in another form,
such as March 24, 2019. Derive the class extDateType so
that the date can be printed in either form.
Add a member variable to the class extDateType so that
the month can also be stored in string form. Add a member function
to output the month in the string format, followed by the year—for
example, in the form March 2019.
Write the definitions of the functions to implement the
operations for the class extDateType.
Note: you may write a main.cpp to test
your class but will not be graded on the main.cpp.
Can Anyone Help Me Write Extdatetypeimp Cpp I Already Have The Codes Listed Below That Is The Only Header File I Am Mi 1
Can Anyone Help Me Write Extdatetypeimp Cpp I Already Have The Codes Listed Below That Is The Only Header File I Am Mi 1 (43.92 KiB) Viewed 33 times
dataTypeImp.cpp:
#include
#include "dateType.h"
using namespace std;
void dateType::setDate(int month, int day, int year)
{
if (year >= 1)
dYear =
year;
else
dYear =
1900;
if (1 <= month && month <=
12)
dMonth =
month;
else
dMonth = 1;
switch (dMonth)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
if (1 <= day
&& day <= 31)
dDay
= day;
else
dDay
= 1;
break;
case 4:
case 6:
case 9:
case 11:
if (1 <= day
&& day <= 30)
dDay
= day;
else
dDay
= 1;
break;
case 2:
if
(isLeapYear())
{
if
(1 <= day && day <= 29)
dDay
= day;
else
dDay
= 1;
}
else
{
if
(1 <= day && day <= 28)
dDay
= day;
else
dDay
= 1;
}
}
}
void dateType::setMonth(int m)
{
dMonth = m;
}
void dateType::setDay(int d)
{
dDay = d;
}
void dateType::setYear(int y)
{
dYear = y;
}
void dateType::print() const
{
cout << dMonth << "-"
<< dDay << "-" << dYear;
}
int dateType::getMonth() const
{
return dMonth;
}
int dateType::getDay() const
{
return dDay;
}
int dateType::getYear() const
{
return dYear;
}
int dateType::getDaysInMonth()
{
int noOfDays;
switch (dMonth)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
noOfDays =
31;
break;
case 4:
case 6:
case 9:
case 11:
noOfDays =
30;
break;
case 2:
if
(isLeapYear())
noOfDays
= 29;
else
noOfDays
= 28;
}
return noOfDays;
}
bool dateType::isLeapYear()
{
if (((dYear % 4 == 0) && (dYear
% 100 != 0)) || dYear % 400 == 0)
return true;
else
return
false;
}
dateType::dateType(int month, int day, int year)
{
setDate(month, day, year);
}
int dateType::numberOfDaysPassed()
{
int monthArr[13] = {0, 31, 28, 31, 30,
31, 30,
31,
31, 30, 31, 30, 31};
int sumDays = 0;
int i;
for (i = 1; i < dMonth; i++)
sumDays =
sumDays + monthArr;
if (isLeapYear() && dMonth >
2)
sumDays =
sumDays + dDay + 1;
else
sumDays =
sumDays + dDay;
return sumDays;
}
int dateType::numberOfDaysLeft()
{
if (isLeapYear())
return 366 -
numberOfDaysPassed();
else
return 365 -
numberOfDaysPassed();
}
void dateType::incrementDate(int nDays)
{
int monthArr[13] = {0, 31, 28, 31, 30,
31, 30,
31,
31, 30, 31, 30, 31};
int daysLeftInMonth;
daysLeftInMonth = monthArr[dMonth] -
dDay;
if (daysLeftInMonth >= nDays)
dDay = dDay +
nDays;
else
{
dDay = 1;
dMonth++;
nDays = nDays -
(daysLeftInMonth + 1);
while (nDays
> 0)
if
(nDays >= monthArr[dMonth])
{
nDays
= nDays - monthArr[dMonth];
if
((dMonth == 2) && isLeapYear())
nDays--;
dMonth++;
if
(dMonth > 12)
{
dMonth
= 1;
dYear++;
}
}
else
{
dDay
= dDay+nDays;
nDays
= 0;
}
}
}
NO 1 1 4567 1 date Type.h dateTypelmp.cpp extDateType.h extDateTypeImp.. 1 #ifndef dateType_H 2 #define dateType_H 3 4 class dateType 5 { 6 public: 7 void setDate(int, int, int); 8 void setMonth(int); 9 void setDay(int); 10 void setYear(int); 11 12 void print() const; 13 14 int numberOfDaysPassed(); 15 16 int numberOfDaysLeft(); 17 18 void incrementDate(int nDays); 19 20 int getMonth() const; 21 int getDayO const; 22 int getYear() const; 23 24 int getDays InMonth(); 25 26 bool isLeap Year(); 27 28 dateType(int = 1, int = 1; int = 1900); 29 30 private: 31 int dMonth; 32 int dDay; 33 int dYear; 34 }; 35 36 #endif CO
date Type.h date Typelmp.cpp extDateType.h extDateTypelmp.... 2 #ifndef extDateType_H 3 #define extDateType_H 4 5 #include <string> 6 7 #include "dateType.h" 8 9 using namespace std; 10 11 string months[] = {"January", "February", "March", "April", 12 "May", "June", "July", "August", 13 "September", "October", "November", "December"}; 14 15 class extDateType: public dateType 16 { 17 public: 18 void printLongDate(); 19 void setDate(int, int, int); 20 void setMonth(int m); 21 22 void printLongMonthYear(); S 1 23 24 extDateType(); 25 extDateType(int, int, int); 26 27 private: 28 string month; 29 }; 30 31 #endif 32
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply