Hi I am currently writing a code that finds the birthday of someone!
-The class should have a three parameter default constructor that allows the date to be set when a new Date object is created.
-If the user creates a Date object without any arguments or if the arguments have invalid values:
• month should be between 1 and 12
• date should be between 1 and the number of days in the selected month
then the default values should be 1,1,2001.
The class should have member functions that allow to print the date in any of the three following formats:
• 3/15/13
• March 15, 2013
• 15 March 2013
I need to test this class in a program that creates a date object with default parameters and another with program defined ones (no need to ask the user) and uses the class functions to print those dates using the three different printing functions.
This is my code so far:
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71 |
#include <iostream>
using namespace std;
class Date
{
private:
int month;
int day;
int year;
public:
void getInfo( int month, int day, int year);
void printOne(void);
void printTwo(void);
void printThree(void);
Date();
};
void Date::getInfo(int m, int d, int y)
{
month=m;
day=d;
year=y;
}
void Date::printOne()
{
switch(month)
{
case 1:
cout<<"January"<<day<<","<<year;
break;
case 2:
cout<<<"February"<<day<<","<<year;
break;
case 3:
cout<<"March"<<day<<","<<year;
break;
case 4:
cout<<"April"<<day<<","<<year;
break;
case 5:
cout<<"May"<<day<<","<<year;
break;
case 6:
cout<<"June"<<day<<","<<year;
break;
case 7:
cout<<"July"<<day<<","<<year;
break;
case 8:
cout<<"August"<<day<<","<<year;
break;
case 9:
cout<<"September"<<day<<","<<year;
break;
case 10:
cout<<"October"<<day<<","<<year;
break;
case 11:
cout<<"November"<<day<<","<<year;
break;
case 12:
cout<<"December"<<day<<","<<year;
break;
}
}
Date::Date()
{month=1;day=1;year=2001;}
void Date::printTwo()
{
cout<<month<<"/"<<day<<"/"<<year<<endl;
} |
I really need to know if I am on the right track with using classes. For the printout function I feel like i need to use a switch in order to convert the numbers into strings i.e. 3=march or 12=december. ANY advice is APRECIATED!!