I am trying to run my program code but it isnt working can a

I am trying to run my program code but it is\'nt working, can anyone tell what am I missing?

here is my code:

//my shape.h file

#pragma once
#include <iostream>
using namespace std;


class Shape
{
protected:
int width, height;
double radius, pi;

public:
void set_rec(int w, int h)
{
  width = w; height = h;
}

void set_circle(double d, double p)
{
  radius = d, pi = p;
}

virtual int area(), perimeter();
virtual double areaOfCircle(), perimeterOfCircle();
};

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//my circle.h file

#pragma once
#include \"shape.h\"


class Circle : public Shape
{
public:
double areaOfCirlce()
{
  return (2 * radius) * pi;
}

double perimeterOfCircle()
{
  return (2 * pi) *radius;
}

};

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//my rectangle.h file

#pragma once
#include \"shape.h\"

class Rectangle : public Shape
{
public:
int area()
{
  return width * height;
}

int perimeter()
{
  return 2 * (width + height);
}

};

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//my test main file

#include \"Shape.h\"
#include \"Circle.h\"
#include \"Rectangle.h\"

int main()
{
Rectangle r;
Circle c;

Shape *p1= &r;
Shape *p2= &c;


p1->set_rec(4,8);
p2->set_circle(7,3.141592654);

cout << p1->area() << \"\ \";
cout << p1->perimeter() << \"\ \";
cout << p2->area() << \"\ \";
cout << p2->perimeter() << \"\ \";

cin.ignore(2);
return 0;
}

Solution

First, this is c++ code used to find the area and perimeter..

Now, here function hiding plays an important role in the above program here once derived class overloads the base class function then this function will be hide. Hence you need to take care about this concept while using virtual functions in c++..

I am trying to run my program code but it is\'nt working, can anyone tell what am I missing? here is my code: //my shape.h file #pragma once #include <iostre
I am trying to run my program code but it is\'nt working, can anyone tell what am I missing? here is my code: //my shape.h file #pragma once #include <iostre

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site