C Help Problem Definition Build a Date class and a main func

C++ Help!

Problem Definition Build a Date class and a main function to test it Specifications Below is the interface for the Date class: it is our contract\" with you: you have to implement everything it describes, and show us that it works with a test harness that puts it through its paces. The comments in the interface below should be sufficient for you to understand the project (use these comments in your Date decaration), without the need of any further documentation. But of course, as always, you can ask us any questions you may have on Piazza class Date private: unsigned day; unsigned month string monthName; unsigned year; public: /I creates the date January 1st, 2000 Date) * parameterized constructor: month number, day, year - e.g. (3, 1, 2010) will construct the date March 1st, 2010 If any of the arguments are invalid (e.g. 15 for month or 32 for day) then the constructor will construct instead a valid Date as close as possible to the arguments provided e.g. in above example, Date(15, 32, 2010), the Date would be corrected to Dec 31st, 2010. In case of such invalid input, the constructor will issue a console error message Invalid date values: Date corrected to 12/31/2010. (with a newline at the end) Date(unsigned m, unsigned d, unsigned y);

Solution

#include<iostream.h>

#include<conio.h>

class Date

{

private:

unsigned day;

unsigned month;

string monthName;

unsigned year;

bool isLeap(unsigned y) const;

unsigned daysPerMonth(unsigned m, unsigned y) const;

string name(unsigned m) const;

unsigned number(const string &mn) const;

public:

Date();

Date(unsigned m, unsigned d, unsigned y);

Date(const string &mn, unsigned d, unsigned y);

void printNumeric() const;

void printAlpha() const;

};

Date getDate();

int main()

{

Date testDate;

testDate=getDate();

cout<<endl;

cout<<”Numeric: “;

testDate.printNumeric();

cout<<endl;

cout<<”Alpha: “;

testDate.printAlpha();

cout<<endl;

return 0;

}

Date getDate()

{

int choice;

unsigned monthNumber, day, year;

string monthName;

cout<<”Which date constructor? (Enter 1, 2 or 3)”<<endl

         <<”1-monthNumber”<<endl

         <<”2-monthName”<<endl

         <<”3-default”<<endl;

cin>>choice;

cout<<endl;

if(choice==1)

{

cout<<”month number?”;

cin>>monthNumber;

cout<<endl;

cout<<”day?”;

cin>>day;

cout<<endl;

cout<<”year?”;

cin>>year;

cout<<endl;

return Date(monthNumber, day, year);

}

if(choice==2)

{

cout<<”month name?”;

cin>>monthName;

cout<<endl;

cout<<”day?”;

cin>>day;

cout<<endl;

cout<<”year?”;

cin>>year;

cout<<endl;

return Date(monthName, day, year);

}

else

{

return Date();

}

void printNumeric() const

{

if(Date(const string &mn, unsigned d, unsigned y) == NULL)

cout<<\"Invalid Date\";

else

Date(const string &mn, unsigned d, unsigned y);

}

void printAlpha() const

{

if(Date(unsigned m, unsigned d, unsigned y) == NULL)

cout<<\"Invalid Date\";

else

Date(unsigned m, unsigned d, unsigned y);

}

C++ Help! Problem Definition Build a Date class and a main function to test it Specifications Below is the interface for the Date class: it is our contract\

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site