add the functions to overload the increment and decrement operators to increase
ID: 3530797 • Letter: A
Question
add the functions to overload the increment and decrement operators to increase the date by a day and decrease the date 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
we need to make sure we read and write to files in this assignment
#include "stdafx.h" //dont worry about this heading, its automatically generated
#include <iostream>
#include <fstream>
#include <stream>
using namespace std;
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 = 2000);
//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.
bool isLeapYear(int);
private:
int dMonth; //variable to store the month
int dDay; //variable to store the day
int dYear; //variable to store the year
};
void dateType::setDate(int month, int day, int year)
{bool error=false;
int max=28;
switch(month)
{ case 1 :
case 3 :
case 5 :
case 7 :
case 8 :
case 10:
case 12: if (day > 31)
error=true;
break;
case 4 :
case 6 :
case 9 :
case 11: if (day > 30)
error=true;
break;
case 2 : if(isLeapYear(year))
max=29;
if(day>max)
error=true;
}
if(error)
{cout<<"invalid date "<<month<<"/"<<day<<"/"<<year<<" entered. Jan 1, 2000 being used ";
month=1;
day=1;
year=2000;
}
dMonth = month;
dDay = day;
dYear = year;
}
bool dateType::isLeapYear(int year)
{ if((year%4==0&&year0!=0)||(year@0!=0))
return true;
return false;
}
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)
{
setDate(month, day, year);
}
int main()
{dateType d1(2,29,2011);
cout<<"First date is ";
d1.printDate();
cout<<endl;
dateType d2(2,29,2008);
cout<<"Second date is ";
d2.printDate();
cout<<endl;
system("pause");
return 0;
}
Explanation / Answer
Here you go. Correct postfix operators overloaded. Please rate so I can unhost. Comment if any question https://www.dropbox.com/s/s5sn9mifacgh1d1/dateType(overload postfix).cpp.txt
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.