hello guys,i've started with classes and i've been given this program below to program and also i will post the source code if you need it.this program reads as folllows.
create a class called DATE that includs three pieces of information as data member a month(type int),a day(type int) and year(type int).your class should have a constructor with three parameters that uses the parameters to initialise the three data members,for the purpose of this exexcise,assume that the values provided for the year and day are correct,but ensure that the month value is in the range (1-12); if it is not,set the month to 1.provide a member function DISPLAYDATE that display the month,day and year separated by forward slashes(/).write a test program that demonstrate CLASSDATE's capabilities.
i'm new to this classes so please forgive me for including my full source code below. my problem firstly my class doesn't use the function display and it doesn't display the year entered.
create a class called DATE that includs three pieces of information as data member a month(type int),a day(type int) and year(type int).your class should have a constructor with three parameters that uses the parameters to initialise the three data members,for the purpose of this exexcise,assume that the values provided for the year and day are correct,but ensure that the month value is in the range (1-12); if it is not,set the month to 1.provide a member function DISPLAYDATE that display the month,day and year separated by forward slashes(/).write a test program that demonstrate CLASSDATE's capabilities.
i'm new to this classes so please forgive me for including my full source code below. my problem firstly my class doesn't use the function display and it doesn't display the year entered.
Code:
#include<iostream> using namespace std; class Date { public: Date(int MONTH,int DAY,int YEAR) { set(MONTH,DAY,YEAR); } void set(int MONTH,int DAY,int YEAR) { month=MONTH; day=DAY; year=YEAR; } int getmonth(int MONTH) { return MONTH; } int getday(int day) { return day; } int getyear(int year) { return year; } void display(int MONTH,int DAY,int YEAR) { cout<<"welcome today\n"<<getmonth(MONTH)<<getday(DAY)<<getyear(YEAR); cout<<endl; } private: int month; int day; int year; }; int main() { Date mymonth(00,00,0); char slash='/'; int month,day,year; cout<<"please enter the date today separated by the forward slash key(e.g 12/08/2004)\n"; cin>>month>>slash>>day>>year; cout<<"The date today is\n"<<mymonth.getmonth(month) <<slash <<mymonth.getday(day) <<slash <<mymonth.getyear(year) <<endl; return 0; }
Comment