Question: That is, copy the code from Month.cpp and paste it into your file lab4.cpp. #include #include using namespace std; class Month { friend class Date;
That is, copy the code from Month.cpp and paste it into your file lab4.cpp.
#include
#include
using namespace std;
class Month {
friend class Date;
friend ostream& operator
private:
enum EMonth { Jan=1, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec };
Month() : month(Jan) {} // default constructor
Month(int im) : month( static_cast(im) ) {} // value constructor
void setMonth(string m) { month = StringToEMonth(m); } // mutator functions
void setMonth(int im) { month = static_cast(im); }
/* Private helper member functions */
EMonth StringToEMonth(string);
int MonthToInt() { return static_cast(month); }
string MonthToString();
string MonthToString2();
EMonth month;
};
/* Definitions of helper member functions for class Month */
Month::EMonth Month::StringToEMonth(string m) {
if (m == "Jan") return Jan;
else if (m == "Feb") return Feb;
else if (m == "Mar") return Mar;
else if (m == "Apr") return Apr;
else if (m == "May") return May;
else if (m == "Jun") return Jun;
else if (m == "Jul") return Jul;
else if (m == "Aug") return Aug;
else if (m == "Sep") return Sep;
else if (m == "Oct") return Oct;
else if (m == "Nov") return Nov;
else if (m == "Dec") return Dec;
else {
cerr
exit(1);
}
}
string Month::MonthToString() {
switch (month) {
case Jan: return "Jan";
case Feb: return "Feb";
case Mar: return "Mar";
case Apr: return "Apr";
case May: return "May";
case Jun: return "Jun";
case Jul: return "Jul";
case Aug: return "Aug";
case Sep: return "Sep";
case Oct: return "Oct";
case Nov: return "Nov";
case Dec: return "Dec";
default:
cerr
exit(1);
}
}
string Month::MonthToString2() {
switch (month) {
case Jan: return "January";
case Feb: return "February";
case Mar: return "March";
case Apr: return "April";
case May: return "May";
case Jun: return "June";
case Jul: return "July";
case Aug: return "August";
case Sep: return "September";
case Oct: return "October";
case Nov: return "November";
case Dec: return "December";
default:
cerr
exit(1);
}
}
/* Definition of friend function operator
ostream& operator
out
return out;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
