Thread: help with my class-composition, i am noob

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    135

    help with my class-composition, i am noob

    //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
    Last edited by evildotaing; 11-29-2011 at 09:27 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ Noob Class Confusion
    By Freestyler in forum C++ Programming
    Replies: 16
    Last Post: 06-11-2009, 03:19 AM
  2. class composition constructor question...
    By andrea72 in forum C++ Programming
    Replies: 3
    Last Post: 04-03-2008, 05:11 PM
  3. Replies: 16
    Last Post: 11-10-2007, 03:51 PM
  4. NOOB class question
    By wart101 in forum C++ Programming
    Replies: 38
    Last Post: 01-12-2007, 12:29 AM
  5. noob help on queue class
    By robaster in forum C++ Programming
    Replies: 4
    Last Post: 04-29-2006, 10:20 AM