Question
c++

6. Define classes shape, and classes circle and square, which inherit from shape. At the bottom of the page is a sample progr
0 0
Add a comment Improve this question Transcribed image text
Answer #1

//C++ program

#include<iostream>
#include <utility>
#include <math.h>
using namespace std;

class shape{
   protected:
       pair <double,double> location;
   public:
       shape(double x=0,double y=0){
           location.first = x;
           location.second=y;
       }
       double area();
       double border();
  pair <double,double> where(){
           return location;
       }
};

class circle:public shape{
   private:
       double radius;
   public:
       circle(double x=0,double y=0,double r=0):shape(x,y){
           radius=r;
       }
       double area(){
           return M_PI*radius*radius;
       }
       double border(){
           return 2*M_PI*radius;
       }
};

class square:public shape{
   private:
       double edge;
   public:
       square(double x=0,double y=0,double e=0):shape(x,y){
           edge=e;
       }
       double area(){
           return edge*edge;
       }
       double border(){
           return 4*edge;
       }
};

Add a comment
Know the answer?
Add Answer to:
c++ 6. Define classes shape, and classes circle and square, which inherit from shape. At the bottom of the page is a sample program using these classes, followed by its output. (a) Class shape h...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT