[COLOR=indigo][B]
Can some one PLEASE post and example for :
virtual getresults() in the base class
where to define: results = 3.14 * dRadius * dRadius
return results;
and how to call it in derived classes
Susan
Education Direct Student Center
[COLOR=indigo][B]
Can some one PLEASE post and example for :
virtual getresults() in the base class
where to define: results = 3.14 * dRadius * dRadius
return results;
and how to call it in derived classes
Susan
Education Direct Student Center
Last edited by QueSue; 01-25-2003 at 11:12 AM.
Code:#include <iostream> using namespace std; class base { protected: double dRadius; public: explicit base(int init) : dRadius(init) {} virtual ~base() {}; virtual double getresults() const = 0; }; class derived: public base { public: explicit derived(int init) : base(init) {} double getresults() const; }; double derived::getresults() const { return 3.14 * dRadius * dRadius; } int main() { derived d(10); cout<< d.getresults() <<endl; }
*Cela*
[b]
[COLOR=indigo]
Thanks but that's about what I have here and it's loaded with errors
>>Thanks but that's about what I have here and it's loaded with errors
Then you should show us what the errors are and tell us what compiler you use because it compiles and runs perfectly for me.
*Cela*
[B][COLOR=indigo]
Thank you for responding to my post regardless if problem is solved
This is far as I can get with out errors:
Shape base class:
#if!defined(SHAPE_H)
#define SHAPE_H
class Shape {
public:
Shape();
virtual double getArea() const = 0;
protected:
double dArea;
};
#endif
Circle derived class:
#if!defined(CIRCLE_H)
#define CIRCLE_H
#include "Shape.h"
class Circle: public Shape {
public:
Circle();
double setRadius();
double getRadius();
double getArea();
private:
double dRadius;
};
#endif
Circle .ccp:
#include "Circle.h"
Circle::Circle(){
}
double Circle::getArea(){
return 3.14 * dRadius * dRadius;
}
Main Source file:
#include<iostream.h>
#include "Circle.h"
void main(){
}
There are a few problems with that code. That is not like the code cela gave you. Anyways lets see..
You never define the constructor for Shape class, your constructor doesn't take any parameters so the dArea member will never be set. This also goes for you Circle class, you never have a constructor that can set the radius. Try making some changes and looking at cela's code again.
I just need to add on not change. The requirement of this project is to bulid on the data and format given by instuctor. Thanks just the same.
try adding another constructor that takes a parameter to set the radius OR add a "mutator" function to access the radius and set it before you try to calculate the area. you cant find the area if the radius is not set to any value.
People I get it You don't know how or can't post a sample of
base class with virtual getresults
derived class that can call it
NO PROBLEM
Someone did post it, if you're not smart enough to understand the code you've been given, that's not our problem. Cela's code does exactly what you asked, it has a virtual base function and a derived class calls it. What more do you want?? I mean geez, if you ask for help and then completely ignore the help you're given why even waste our time?People I get it You don't know how or can't post a sample of
Lighten up Crimpy didn't see YOU post anything
I did say Thanks anyway !!!
cuz I wasn't here genius. The only reason I decided to post was I was reading what looked like an interesting thread and then I saw you insult everyone who was nice enough to try and help you.Lighten up Crimpy didn't see YOU post anything
No, you said "Oh, despite the fact that everyone posted perfectly knowledgeable, correct, and workable answers, I'll just assume that they don't know how to do it because I don't understand. Thanks anyway!!!" Moron.I did say Thanks anyway !!!
NO THAT"S WHAT YOU READ !!!!!!!!
If in fact I did insulted anyone other then crimpy I am truly sorry that wasn’t my intention at all.
I did count three Thanks and I meant it CELA, MRWIZARD, and PERSPECTIVE