0

hello guys...i just done my assignment and here's the 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

CelestialBody constructor is called
Planet constructor is called
Population  constructor is called

Population = 5000000000

orbit time = 1

size = 40000

but i am stuck in the earth class and constructor section.
I guess i was wrong in 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
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by JugglerDrummer
0

ending bracket needed after earth constructor before main, and note sure if you can put comma's in numbers. What problems are you encountering?

0

ok i got it..sorry

the errors was
\there are some compiling errors caused by -
line 13 - missed '}'
line 25 - class keyword in must belowercase
line 37 - class name must be with letter case exactly as declared
lines 46, 61 - missed '}' after function body

and the planet and celestialbody constructor wasn't correct

so i corrected it and got my end result but need one help on the population..
how to declare it?
i used unsigned long int population but the value was garbage values,,any help?
here's my coding..near perfect.

#include <iostream>
 
using namespace std;
 
class CelestialBody
{
 
protected:
double size;
public:
    CelestialBody (double );
};
 
class Planet : public CelestialBody
{
protected:
 
double orbit_time;
public:
  Planet(double , double);
 
};
 
class Earth : public Planet
 
{
 
protected:
unsigned long int population ;
 
public:
 
   Earth();
};
 
CelestialBody :: CelestialBody (double s) : size(s)
{
cout<<"CelestialBody is called"<<endl;
}
 

Planet :: Planet (double size, double time) : CelestialBody(size) , orbit_time(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;
 
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.