Thread: can anyone help me on this inheritance problem

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    61

    can anyone help me on this inheritance problem

    hello guys...i just done my assignment and here's the code


    Code:
    #include <iostream>
    
    using namespace std;
    
    class CelestialBody
    {
    
    private:
    double size;
    public:
        CelestialBody (double );
    ;
    
    class Planet : public CelestialBody
    {
    private:
    
    double orbit_time;
    public:
      Planet(double , double);
    
    };
    
    Class Earth : public Planet
    
    {
    
    private:
    unsigned long int population ;
    
    public:
    
       Earth();
    };
    
    Celestialbody :: Celestialbody (double) :
    size(SIZE)
    {
    cout<<"CelestialBody is called"<<endl;
    }
    
    Planet :: Planet (double) : size(SIZE) , orbit_time(ORBIT_TIME)
    {
    cout <<  "Planet constructor is called"<<endl;
    
    
    
    
    
    Earth :: Earth ()
    
    : Planet (1,40000), population (3000000000)
    
    {
    
    cout <<" Earth constructor is called."<<endl;
    cout <<"Population =" <<population <<endl;
    cout<<"orbit time = "<<orbit_time<< endl;
    cout<< "size =" <<size <<endl;
    
    
    
    int main ()
    
    
    {
    Earth earth;
    
    return 0;
    
    }
    the output should be like this
    Code:
     
    CelestialBody constructor is called
    Planet constructor is called
    Population  constructor is called
    
    Population = 5000000000
    
    orbit time = 1
    
    size = 40000
    all looks fine but
    but i am stuck in the earth class and constructor section.
    I think i was mistaken in the area of calling of the CelestialBody constructor to initialize the
    data members of both the Planet and CelestialBody.
    I didn't declared SIZE and ORBIT_TIME but it will not effect the end results will it?
    any help plez..i did my homework..need for it to be compiled..

  2. #2
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    Aside from lacking a closing curly brace, which is an error present elsewhere in the code too, the Earth constructor looks ok.

    What exactly are you unsure about?
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inheritance problem
    By logicwonder in forum C++ Programming
    Replies: 5
    Last Post: 10-07-2006, 10:14 AM
  2. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  3. Multiple inheritance problem
    By Magos in forum C++ Programming
    Replies: 8
    Last Post: 02-21-2006, 09:27 AM
  4. Inheritance using Stack Class Problem
    By dld333 in forum C++ Programming
    Replies: 17
    Last Post: 12-06-2005, 11:14 PM
  5. Replies: 5
    Last Post: 11-07-2005, 11:34 PM