We help IT Professionals succeed at work.

# polymorphism

on
296 Views
hi guys,

should be easy for you guys...Standard Polymorphism...

Class Shape - Base Class

#ifndef SHAPE_H
#define SHAPE_H

class Shape{

public:
virtual void read() const = 0;
virtual void print() const = 0;

};
#endif

Class Circle - Derived Class

#ifndef CIRCLE_H
#define CIRCLE_H

#include "Shape.h"
#include "Point.h"

class Circle:public Shape
{
Point center;

public:

Circle();
void setCircle(int x, int y, double r)const;
int getX()const;
int getY()const;
virtual void print()const;
};
#endif

{
int x;
int y;
cout<<"Entering a circle x y radius: ";
cin>>x;
cin>>y;
}

Once I have the input form the user, I need to push rad into radius which is a public data member...I can't figure out how to this...It won't let me do this within the function definition because it's a const member function...Also, I would like to set the center of the circle with the use of the Point object center that was defined as public but it gives me errors when I try to do center.setX(x) (setX is a member function of class Point)...Here, I will inlcude the .h and cpp file for the class point...

#ifndef POINT_H
#define POINT_H

#include <iostream>
#include "Shape.h"

class Point
{

int xCoor;
int yCoor;

public:

Point();
Point(int x, int y);
void setX(int x);
void setY(int y);
int getX()const;
int getY()const;

};
#endif

#include <iostream>
#include "Point.h"

Point::Point(int x, int y)
{
xCoor = x;
yCoor = y;
}

void Point::setX(int x)
{
xCoor = x;
}

void Point::setY(int y)
{
yCoor = y;
}

int Point::getX()const
{
return xCoor;
}

int Point::getY()const
{
return yCoor;
}

Can anyone help plz??

Mike

Comment
Watch Question
Senior Software Engineer
CERTIFIED EXPERT
Commented:
This problem has been solved!
###### Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

Deciding to stick with EE.

Mohamed Asif

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant