Question: Need help with C++ problem Tasks Implement each of the class methods in the lab file: Each of the setter functions should be close to

Need help with C++ problem

Tasks

Implement each of the class methods in the lab file:

Each of the setter functions should be close to identical. In each, only set the classs attribute if the argument is an acceptable value (eg day must be between 1 and 31, month between 1 and 12, etc). If the argument isnt acceptable, output an error message to the user.

Each of the getter functions will just return the raw value for the corresponding class attribute. They should be virtually identical.

The str function should return a string in a standard date format (your choice of format as long as it includes year, day, and month). Dont include newline characters. Use the getter functions to get the values rather than outputting the variables directly. Make sure that the month and date get outputted with two digits (eg if day=1, it should be display as 01)

The compDate function should return a -1 if other comes before itself, a 0 if the dates are the same, and a 1 if other comes after itself.

The class constructor should set each of the year, month, and date using the built in setter functions.

In int main, create two instances of the date class. With the first instance, use the constructor to set the instances attributes equal to a date of personal importance. With the second instance, use the classs setter functions to set the instances attributes to your graduation date (you can make up a date if you dont recall this offhand). Finally, output both dates and a statement about which date comes first.

Sample Output (note: your output will probably differ if you pick different dates or a date format)

Personal date: 1990-10-07

Graduation: 2016-12-20

I graduate after my personal date

This is what I have to start with...

#include  #include  #include  #include  using namespace std; class Date { private: int year; int month; int day; public: Date(int y, int m, int d); void setYear(int y); void setMonth(int m); void setDay(int d); int getYear(); int getMonth(); int getDay(); string str(); int compDate(Date d); }; string Date::str() { stringstream s; string r; s << getYear() << '-' << setw(2) << setfill('0') << getMonth() << '-' << setw(2) << setfill('0') << getDay(); s >> r; return r; } int main() { return 0; } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Certainly Lets go through each step needed to complete the C program as outlined in your problem sta... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!