Answer to Question #260612 in C++ for siri

Question #260612

Wap to create Shape class. It has two data member function. area() and display(). Area is dummy function. And Display only working. And derived another class Circle. Which also two member function area() display1(). By using abstract class display area of circle and as well as display function of Base class


1
Expert's answer
2021-11-03T04:22:19-0400
#include<iostream>
#include<string>


using namespace std; 


//class shape
class Shape
{
public:
	virtual void display()
	{
		
	}
	virtual float area(){
		return 0;
	}
};


//class Circle inheriting class Shape
class Circle: public Shape
{
private:
	float radius;
public:
	Circle(float radius){
		this->radius=radius;
	}


	void setRadius(float radius){
		this->radius=radius;
	}
	float getRadius(){
		return this->radius;
	}
	void display()
	{
		cout<<"Circle radius: "<<this->radius<<"\n";
		cout<<"Circle area: "<<this->area()<<"\n";
	}
	float area(){
		return 3.14*this->radius*this->radius;
	}
};






void main()
{
	
	Shape *s;
	Circle c(5);
	s=&c;
	s->display();


	int k;
	cin>>k;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS