//Person.cpp
Code:
#include <iostream>
#include "Birth.h"
#include "Person.h"
using namespace std;
void Person::setNumber(int day, int month, int year, int num)
{
dob.setDay(day);
dob.setMonth(month);
dob.setYear(year);
number = num;
}
int Person::getNumber() const
{
return number;
}
void Person::print() const
{
dob.print();
cout << "Your number is " << number << endl;
}
Person::Person(int num):dob(day, month, year)
{
number = 0;
}
//person.h
Code:
#include "Birth.h"
#ifndef PERSON_H_
#define PERSON_H_
class Person
{
public:
void setNumber(int, int, int, int);
int getNumber()const;
void print()const;
Person();
private:
int number;
Birth dob;
};
#endif
//Birth.cpp
Code:
#include <iostream>
#include "Birth.h"
using namespace std;
void Birth::setDay(int d)
{
day = d;
}
int Birth::getDay() const
{
return day;
}
void Birth::setMonth(int m)
{
month = m;
}
int Birth::getMonth() const
{
return month;
}
void Birth::setYear(int y)
{
year = y;
}
int Birth::getYear() const
{
return year;
}
void Birth::print()const
{
cout << "Your dob is " << year << " " << month << " " << day << endl;
}
Birth::Birth()
{
day = 0;
month = 0;
year = 0;
}
//Birth.h
//Birth.h
Code:
#ifndef BIRTH_H_
#define BIRTH_H_
class Birth
{
public:
void setDay(int);
int getDay()const;
void setMonth(int);
int getMonth()const;
void setYear(int);
int getYear()const;
void print() const;
Birth();
private:
int year;
int month;
int day;
};
#endif
main.cpp
Code:
#include <iostream>
#include "Birth.h"
#include "Person.h"
using namespace std;
void main(void)
{
Birth a;
a.setDay(12);
a.setMonth(11);
a.setYear(2009);
a.print();
Person b;
b.setNumber(5);
b.print();
//a.setDay(12);
//a.setMonth(11);
//a.setYear(2009);
//a.print();
system ("pause");
}
I have no problem in anywhere expect the part where the and Person.cpp and Person.h which compostition from the birth.h and birth.cpp. What is wrong with my code, it not working. Is there anything I done wrong in person .cpp or person.h