I am having trouble trying to figure out how i would display a month without having to display "January" like in my switch - if i try to just oputput it i get a number 1
Do i need to create memory for the date priceDate; private member? than copy in my copy constructor?
sorry about formatting. i had to move stuff over so it would display on this page properly
This is what i have. Do i need to create memory for the private member date?
class date
{
public:
typedef enum {INVALID, JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE,
JULY, AUGUST, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER}
Month;
date(Month month, int day, int year);
date(const date& date); // copy constructor
date(void); // default constructor
~date(void);
friend ostream& operator<<(ostream& out, const date& d);
private:
Month month;
int day;
int year;
};
also.
class stock
{
public:
stock(char const * const symbol, char const * const name, int sharePrice, date priceDate);
// sharePrice is given as a number of CENTS
stock(const stock& s); // copy constructor
stock(void); // default constructor
char const * const getSymbol(void) const;
stock& operator=(const stock& s);
stock& operator=(stock const * const s);
~stock(void);
// display column headers
static void displayHeaders(ostream& out); // display the headers when this instance is printed
// prints share price as DOLLARS
// (e.g. 2483 would print out as 24.83 and 200 would print out as 2.00)
friend ostream& operator<<(ostream& out, const stock& s);
friend class hashmap;
private:
int sharePrice;
char* name;
char* symbol;
date priceDate;
int removed;
};
now the functions.
date::date(Month month, int day, int year)
{
this->day = day;
this->month = month;
this->year = year;
}
/**
* date: copy constructor
* in: date
* out: out
* return: none
**/
date::date(const date& date):day(date.day),month(date.month),year(date.year)
{
}
date::date()
{
day = 0;
year = 0;
month = INVALID;
}
date::~date(void)
{
}
ostream& operator<<(ostream& out, const date& d)
{
switch(d.month)
{
case 1: out << "January " << d.day <<", " << d.year;
break;
case 2: out << "Febuary "<< d.day <<", " << d.year;
break;
case 3: out << "March "<< d.day <<", " << d.year;
break;
case 4: out << "April "<< d.day <<", " << d.year;
break;
case 5: out << "May "<< d.day <<", " << d.year;
break;
case 6: out << "June "<< d.day <<", " << d.year;
break;
case 7: out << "July " << d.day <<", " << d.year;
break;
case 8: out << "august "<< d.day <<", " << d.year;
break;
case 9: out << "September "<< d.day <<", " << d.year;
break;
case 10: out << "October "<< d.day <<", " << d.year;
break;
case 11: out << "November "<< d.day <<", " << d.year;
break;
case 12: out << "december "<< d.day <<", " << d.year;
break;
}
return out;
}