Question: Write the definitions of the functions to implement the operations defined for the class dateType in Programming Exercise 6. Programming Exercise 6: Main.cpp #include //include

Write the definitions of the functions to implement the operations defined for the class dateType in Programming Exercise 6.

Programming Exercise 6:

Main.cpp

#include

//include the header file dateType.h

#include "dateType.h"

using namespace std;

int main()

{

//declare integer variables

int m, d, y, numDays, passed, remain;

//create an object ,date of class dateType

dateType date(0, 0, 0);

//read montn, day,year values from user

cout << "Enter Month as a number:";

cin >> m;

cout << "Enter Day:";

cin >> d;

cout << "Enter Year:";

cin >> y;

date.setYear(y);

bool check = date.isLeapYear(y);

if (check)

cout << "Leap year" << endl;

numDays = date.setMonth(m);

cout << "Number of days in the month is:" << numDays << endl;

passed = date.totalNumOfpassedDays(m, d);

cout << "Total number of days passed are:" << passed << endl;

remain = date.RemainingDays(y);

cout << "Total number of days remaining are:" << remain << endl;

//create a new date as follows

//month=3,day=18,year=2017

//Then set 25 days to add to the date

//result date is month=4,day=12,year =2017

date.NewDate(3, 18, 2017, 25);

//prints the new date

date.printDate();

system("pause");

return 0;

}

dateType.cpp

//Implementation file

//dateType.cpp

#include "dateType.h"

//Constructor with parameters

dateType::dateType(int month, int day, int year)

{

dMonth = month;

dDay = day;

dYear = year;

}

int dateType::totalNumOfpassedDays(int month, int day)

{

int i, passedDays = 0;

for (i = 1; i

{

if (i == month)

{

noDays = noDays + 1;

}

else

passedDays += setMonth(i);

}

passedDays += day;

Passeddays = passedDays;

return passedDays;

}

void dateType::NewDate(int month, int day, int year, int adddays)

{

if ((day + adddays) % month)

{

dDay = day + adddays;

dDay = abs(dDay - 31);

month++;

dMonth = month;

//set year to dYear

dYear = year;

if (month>12)

{

dMonth = 1;

dYear++;

}

}

}

int dateType::RemainingDays(int year)

{

int remainingDays;

if (isLeapYear(year))

{

remainingDays = 366 - Passeddays;

}

else

remainingDays = 365 - Passeddays;

return remainingDays;

}

int dateType::setMonth(int month)

{

int year1;

year1 = dYear;

if (month <= 12)

{

dMonth = month;

switch (month)

{

//include the case 1 also

case 1:

case 3:

case 5:

case 7:

case 8:

case 10:

case 12: noDays = 31;

break;

case 4:

case 6:

case 9:

case 11:noDays = 30;

break;

case 2:if (isLeapYear(year1))

noDays = 29;

else

noDays = 28;

}

}

else

{

cout << "Invalid Month" << endl;

dMonth = 0;

}

return noDays;

}

void dateType::setDay(int day)

{

if (day <= noDays)

{

dDay = day;

}

else

{

cout << "Invalid Day" << endl;

dDay = 0;

}

}

void dateType::setYear(int year)

{

dYear = year;

}

bool dateType::isLeapYear(int year)

{

if (((year % 4 == 0) && (year % 100 == 0)) || (year % 400 == 0))

return true;

else

return false;

}

//print the date as DD/MM/YYYY

void dateType::printDate()const

{

cout << "DATE: DD/MM/YYYY : " << dDay << "/" << dMonth << "/" << dYear << endl;

}

int dateType::getDay() const

{

return dDay;

}

int dateType::getMonth() const

{

return dMonth;

}

int dateType::getYear() const

{

return dYear;

}

dateType.h

#ifndef DATATYPE_H

#define DATATYPE_H

#include

using namespace std;

class dateType

{

private:

int dMonth; //variable to store the month

int dDay; //variable to store the day

int dYear;//variable to store the year

int noDays;

int Passeddays;

public:

int setMonth(int month);

void setDay(int day);

void setYear(int year);

int getDay() const;

int getMonth() const;

int getYear() const;

void printDate() const;

bool isLeapYear(int year);

int totalNumOfpassedDays(int, int);

int RemainingDays(int);

void NewDate(int, int, int, int);

dateType(int month = 0, int day = 0, int year = 0);

};

#endif DATATYPE_H

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!