15. Consider the class dateType given in Chapter 13. In this class, add the func
ID: 3653376 • Letter: 1
Question
15. Consider the class dateType given in Chapter 13. In this class, add the functions to overload the increment and decrement operators to increase the date by a day and decrease the data by a day, respectively; relational operators to compare two dates; and stream operators for easy input and output. (assume that the date is input and output in the form MM-DD-YYYY.) Also write a program to test your class.
i was given the dateType.h and dateTypeImp.cpp.
dateType.h
#ifndef dateType_H
#define dateType_H
class dateType
{
public:
void setDate(int month, int day, int year);
//Function to set the date.
//The member variables dMonth, dDay, and dYear are set
//according to the parameters.
//Postcondition: dMonth = month; dDay = day;
// dYear = year
int getDay() const;
//Function to return the day.
//Postcondition: The value of dDay is returned.
int getMonth() const;
//Function to return the month.
//Postcondition: The value of dMonth is returned.
int getYear() const;
//Function to return the year.
//Postcondition: The value of dYear is returned.
void printDate() const;
//Function to output the date in the form mm-dd-yyyy.
dateType(int month = 1, int day = 1, int year = 1900);
//Constructor to set the date
//The member variables dMonth, dDay, and dYear are set
//according to the parameters.
//Postcondition: dMonth = month; dDay = day; dYear = year;
// If no values are specified, the default
// values are used to initialize the member
// variables.
private:
int dMonth; //variable to store the month
int dDay; //variable to store the day
int dYear; //variable to store the year
};
#endif
dateTypeImp.cpp
//Implementation file date
#include <iostream>
#include "dateType.h"
using namespace std;
void dateType::setDate(int month, int day, int year)
{
dMonth = month;
dDay = day;
dYear = year;
}
int dateType::getDay() const
{
return dDay;
}
int dateType::getMonth() const
{
return dMonth;
}
int dateType::getYear() const
{
return dYear;
}
void dateType::printDate() const
{
cout << dMonth << "-" << dDay << "-" << dYear;
}
//Constructor with parameters
dateType::dateType(int month, int day, int year)
{
dMonth = month;
dDay = day;
dYear = year;
}
will i recieve an answer this time? All my other questions still have no responses
Explanation / Answer
Increment and decrement operator overloading... dateType Operator ++() { dDay++; } dateType Operator --() { dDay--; } relational operator overloading.. dateType boolean operator == (const dateType & leftOp, const dateType & rightOp) { if (leftOp.date == rightOp.date ) return true; else return false; } Stream operator overloading ..... for stream operator overloading these outside the class and keep them as friends .... declare this inside the class though friend istream& operator >>(istream &is,Base &obj); friend ostream& operator (istream &is,dateType &obj) { is>>obj.date; return is; } ostream& operatorRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.