CECS 282-05: C++ for Java Programmers Program 4- Overloading Operators Due: Apri
ID: 3735226 • Letter: C
Question
CECS 282-05: C++ for Java Programmers Program 4- Overloading Operators Due: April 5, 2018 Create a C++ class called up Date. It should have the following operations: upDate()- default constructor. This will set the date to May 11, 1959 (A very important date!!) . upDate(int M, int D, int Y)-overloaded constructor. This will set the date to the values passed in through the parameter list represented by Month, Day and Year. If any one of the parameters is out of range, the date is set to the default date. upDate( int J)-overloaded constructor-create a date using the Julian date upDate()-destructor. Be sure to de-allocate any memory that was allocated in the constructor void setDate(int M, int D, int Y) - works just like the constructor . int getMonth) - return the month in integer form . int getDay()- return the day of the month . int getYear()- return the year . string getMonthName() - return the name of the month Add the necessary class methods (functions) to support the following upDate DI(10,27,2010): 1/ overloaded constructor . upDate D2(D1) // copy constructor // assignment operator // add 5 days to D1, result is stored in D1 // subtract 7 days from DI, result is stored in D1 D1-D2; D1 += 5; D1--7 upDate D3 D2+5; // add 5 days to D2, assign result to D3 upDate D4-5+ D2; // add 5 days to D2, assign result to D4 upDate D5 D2-4; // subtract 4 days from D2, assign result to D5 intx -D5-D4; // days between D5 and D4. Can be negative or positive coutExplanation / Answer
#include <iostream>
using namespace std;
class upDate {
public:
upDate(){
date = new int(3);
date[0]=5;
date[1]=11;
date[2]=1959;
}
upDate(int M, int D, int Y){
date = new int(3);
if ((M>0 && M<13 ) && (D>0&&D<32)){
date[0]=M;
date[1]=D;
date[2]=Y;
} else {
date[0]=5;
date[1]=11;
date[2]=1959;
}
}
~upDate() {
delete date;
}
void setDate(int M, int D, int Y){
date = new int(3);
if ((M>0 && M<13 ) && (D>0&&D<32)){
date[0]=M;
date[1]=D;
date[2]=Y;
} else {
date[0]=5;
date[1]=11;
date[2]=1959;
}
}
int getMonth() {
return date[0];
}
int getDate() {
return date[1];
}
int getYear() {
return date[2];
}
private:
int *date;
};
int main() {
upDate *u = new upDate();
cout<<u->getMonth()<<" ";
u->setDate(1,2,2001);
cout<<u->getDate();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.