Define a C++ class managing numbers using specific methods listed below. (5 poin
ID: 3729358 • Letter: D
Question
Define a C++ class managing numbers using specific methods listed below.
(5 points) Define a C++ class named "Birthday" that manages a day (integer) and a month (integer). It should provide at least three methods: "isLater" to compare with another Birthday object and return true if it has a later date and false otherwise "isEqual" that compares with another Birthday object and return true if it has the same birthday and false otherwise hebirthdayintheformat of "mm/dd" such as "6/1" Write a main function to show how you can create Birthday objects, call the isLater method and print out the birthday information.Explanation / Answer
#include <iostream>
using namespace std;
class BirthDay{
private:
int day, month;
public:
BirthDay(int d, int m) {
day = d;
month = m;
}
bool isLatter(const BirthDay &oth) {
if(month > oth.month)
return true;
else if(month < oth.month){
return false;
}else{
if(day > oth.day)
return true;
else if(day < oth.day)
return false;
else
return true;
}
}
bool isEqual(const BirthDay &oth) {
return month == oth.month && day == oth.day;
}
string toString() {
return to_string(month)+"/"+to_string(day);
}
};
int main() {
BirthDay b1(23, 4);
BirthDay b2(24, 4);
cout<<b1.isLatter(b2c)<<endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.