//main
#include <iostream>
#include <iostream>
#include "Month.h"
#include "Day.h"
using namespace std;
#define NR_M 12
int main()
{
Month **month = new Month *[NR_M];
month[0] = new Month( "Jannuary", 31) ;
month[1] = new Month( "February", 28) ;
month[2] = new Month( "March ", 31);
month[3] = new Month( "April ", 30);
month[4] = new Month( "May ", 31);
month[5] = new Month( "June ", 30) ;
month[6] = new Month( "July", 31) ;
month[7] = new Month( "August ", 31);
month[8] = new Month( "September", 30) ;
month[9] = new Month( "October", 31) ;
month[10] = new Month( "November ", 30);
month[11] = new Month( "December ", 31);
cout << endl<< "__________Display Months_________"<<endl<<endl;
for (int i=0; i<= NR_M; i++){
month[i]->display();
}
cout<<endl;
return 0;
}
#ifndef MONTH_H
#define MONTH_H
class Month
{
private:
char *name;
int nrday;
public:
Month(char*, int = 0);
~Month();
Month(const Month& );
void display();
char *getMonth();
};
#endif // MONTH_H
#include "Month.h"
#include <string.h>
#include <iostream>
using namespace std;
Month::Month(char * called, int nr)
{
//ctor
this->nrday = nr;
if(called!=NULL){
this->name= new char[strlen(called)];
strcpy(this->name, called);
}else{
this->name = NULL;
}
cout << "Month Constructor "<< this << endl;
}
Month::~Month()
{
//dtor
cout << "Month Destructor "<< this << endl;
if (name != NULL){
delete[] this->name;
}
}
Month::Month(const Month& m)
{
//copy ctor
this->nrday = m.nrday;
if(m.name != NULL){
this->name=new char[strlen(m.name)];
strcpy(this->name, m.name);
}else{
this->name=NULL;
}
cout<<"Month copy constructor";
}
void Month::display(){
if(name != NULL){
cout<<"Month "<< this->name;
}
cout<<" has "<<this->nrday;
cout<<endl;
}
char * Month::getMonth(){
return name;
}

New Topic/Question
Reply



MultiQuote






|