Click here to Skip to main content
15,905,558 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Need help in C++ classes Pin
Rajesh R Subramanian21-Oct-08 5:22
professionalRajesh R Subramanian21-Oct-08 5:22 
GeneralRe: Need help in C++ classes Pin
Quecumber25621-Oct-08 6:02
Quecumber25621-Oct-08 6:02 
QuestionRe: Need help in C++ classes Pin
CPallini21-Oct-08 6:45
mveCPallini21-Oct-08 6:45 
AnswerRe: Need help in C++ classes Pin
Quecumber25622-Oct-08 3:42
Quecumber25622-Oct-08 3:42 
GeneralRe: Need help in C++ classes Pin
CPallini22-Oct-08 3:44
mveCPallini22-Oct-08 3:44 
GeneralRe: Need help in C++ classes Pin
Quecumber25622-Oct-08 5:25
Quecumber25622-Oct-08 5:25 
GeneralRe: Need help in C++ classes Pin
CPallini22-Oct-08 8:52
mveCPallini22-Oct-08 8:52 
AnswerRe: Need help in C++ classes Pin
Iain Clarke, Warrior Programmer21-Oct-08 6:18
Iain Clarke, Warrior Programmer21-Oct-08 6:18 
The idea of the assignment will be to teach you polymorphism. I'm assuming you'll want a base class of CPlanet, with more specialised inheriting classes which over-ride the member functions of CPlanet.

So, you would have CEarth, and CMercury both inheriting from CPlanet, and each overriding (eg) GetWeight (double dMass), and GetDistanceFromSun (), and so on.

// slightly advanced bit here
As there is no need for the CPlanet class to even have an implementation of GetDistanceFromSun, you could even leave it as a pure virtual member function, forcing any inheriting classes to implement it.
// end of slighty advanced bit.

You would end up with:
CEarth earth;
CMercury mercury;
double weight;

weight = earth.GetWeight (100);
cout << "100 kg on earth is : " << weight << endl;
weight = mercury.GetWeight (100);
cout << "100 kg on mercury is : " << weight << endl;


and could even end up with:
CPlanet *planet = GetNthPlanet (5);
double weight;
weight = planet->GetWeight (100);
cout << "100 kg on 5th planet is : " << weight << endl;

delete planet;

CPlanet *GetNthPlanet (int n)
{
  switch (n)
  {
  case 1:  return new CMercury;
  case 2:  return new CVenus;
  // and so on
  case 9:
    if ( (rand() %100) < 10)
      return CPluto;
    else
      return CPlanetoid;
  }
  return NULL; // FAIL!
}


I'm hesitant to write much more, as I don't want to spoonfeed you - if you don't struggle a bit, you don't learn.


Iain.
GeneralRe: Need help in C++ classes Pin
Quecumber25621-Oct-08 6:40
Quecumber25621-Oct-08 6:40 
QuestionGetting OS theme Pin
divilin thiyagaraj21-Oct-08 4:25
divilin thiyagaraj21-Oct-08 4:25 
AnswerRe: Getting OS theme Pin
David Crow21-Oct-08 4:51
David Crow21-Oct-08 4:51 
GeneralRe: Getting OS theme Pin
divilin thiyagaraj21-Oct-08 21:08
divilin thiyagaraj21-Oct-08 21:08 
GeneralRe: Getting OS theme Pin
Rajesh R Subramanian21-Oct-08 21:15
professionalRajesh R Subramanian21-Oct-08 21:15 
QuestionRe: Getting OS theme Pin
David Crow22-Oct-08 3:13
David Crow22-Oct-08 3:13 
AnswerRe: Getting OS theme Pin
Rajesh R Subramanian21-Oct-08 4:59
professionalRajesh R Subramanian21-Oct-08 4:59 
Questionhow to get the system IP address in mfc Pin
mathy21-Oct-08 3:30
mathy21-Oct-08 3:30 
AnswerRe: how to get the system IP address in mfc Pin
Iain Clarke, Warrior Programmer21-Oct-08 3:47
Iain Clarke, Warrior Programmer21-Oct-08 3:47 
QuestionRegarding string conversion Pin
H4u3221-Oct-08 3:25
H4u3221-Oct-08 3:25 
AnswerRe: Regarding string conversion Pin
Iain Clarke, Warrior Programmer21-Oct-08 3:45
Iain Clarke, Warrior Programmer21-Oct-08 3:45 
GeneralRe: Regarding string conversion Pin
H4u3221-Oct-08 3:52
H4u3221-Oct-08 3:52 
GeneralRe: Regarding string conversion Pin
Cedric Moonen21-Oct-08 4:42
Cedric Moonen21-Oct-08 4:42 
GeneralRe: Regarding string conversion Pin
Mark Salsbery21-Oct-08 4:58
Mark Salsbery21-Oct-08 4:58 
GeneralRe: Regarding string conversion Pin
H4u3221-Oct-08 5:09
H4u3221-Oct-08 5:09 
QuestionCrashes on application exit while hosting an VB ActiveX Control providing UI in a MFC application Pin
Martin081521-Oct-08 2:06
professionalMartin081521-Oct-08 2:06 
AnswerRe: Crashes on application exit while hosting an VB ActiveX Control providing UI in a MFC application Pin
Martin081522-Oct-08 4:47
professionalMartin081522-Oct-08 4:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.