I have to create an abstract class "shape" with one pure virtual function print, that outputs the name of the shape. Derive class circle and rectangle from the shape. In the main function create an array that can hold any type of the derived classes. Put one circle and one rectangle into this array. Print the names of the objects. Delete objects (that means that you have to have a destructor . You do not have to put any code in the destructor, just cout name of the class, that it belongs to.
can somebody please fix these codes for me i would really appreciate it. please guys i need ur help... thanks - #include<iostream>
-
using namespace std;
-
-
class Rectangle {
-
public:
-
Rectangle (double,double);
-
Rectangle (double,double,double,double);
-
bool check_square(double, double);
-
void show_check_sqaure_result(bool);
-
private:
-
double x,y;
-
double length,width;
-
};
-
-
class Circle {
-
public:
-
Circle (Rectangle);
-
};
-
-
Rectangle::Rectangle(double l,double w)
-
{
-
length = l;
-
width = w;
-
cout<<"The area is "<<length*width<<" unit sqaure."<<endl;
-
check_square(l,w);
-
}
-
-
Rectangle::Rectangle(double x0,double y0,double x1, double y1)
-
{
-
double a = (x1>x0) ? (x1-x0):(x0-x1);
-
double b = (y1>y0) ? (y1-y0):(y0-y1);
-
cout<<"The area is "<<a*b<<" unit sqaure."<<endl;
-
check_square(a,b);
-
}
-
-
bool Rectangle::check_square(double a, double b)
-
{
-
double c;
-
c = a-b;
-
show_check_sqaure_result(c);
-
}
-
-
void Rectangle::show_check_sqaure_result(bool k)
-
{
-
if (k==0)
-
cout<<"It is a square.";
-
else
-
cout<<"It is NOT a square.";
-
cout<<endl;
-
}
-
-
Circle::Circle(Rectangle)
-
{
-
cout<<"The area of respective circle is"<<endl;
-
}
-
-
int main()
-
{
-
Rectangle A(4.6,10, 3, 9);
-
Circle B(A);
-
Rectangle C(1,1);
-
Circle D(C);
-
system("pause");
-
}
3 3222
What is the point of passing Rectangle as an argument to Circle's constructor and ignoring it there?
And why is square of the shape calculation there, if it's not in the requirements?
what you have posted looks like random, incoherant code from the Internet that is no where close to being anything that resembles your question. I recommend you break down the question, like this ...
1. You need to create an abstract class "shape"
--- what makes a class abstract?
2. It needs a virtual function - print()
--- what's a virtual function?
3. Derive class Circle and Rectangle from Shape.
--- how do you derive a class?
4. Create an array that will hold any type of derived class.
--- what kind of array will it be?
5. Print the names of the objects.
--- how do you print the names?
You need to have a good understanding of classes and then inheritence. But, you need to break the question down if it's not making sense.
jkmyoung 2,057
Recognized Expert Top Contributor
I think you want a different constructor for the circle, and different methods for a circle. One thing which would define a circle would be it's radius.
So have a radius variable inside the circle shape, and force the constructor to pass a radius in, not a rectangle.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Tim Cadell |
last post by:
I found an odd situation that probably isn't doing what is intended.
class A {
function A() {
// normal constructor for class1
}
function B() {
// a general purpose method
}
|
by: Bob |
last post by:
Has anyone tried (and succeded?) in specifying the appropriate connect
string for a hierarchical dataset using MyODBC?
It's where you specify MSDATASHAPE as your "Provider" but then need to...
|
by: WittyGuy |
last post by:
Hi all,
Though I know the concepts of both abstract class & virtual
function (like derived class pointer pointing to base class...then
calling the function with the pointer...), what is the real...
|
by: santosh |
last post by:
Hello,
I was going through the Marshal Cline's C++ FAQ-Lite.
I have a doubt regarding section 33.10.
Here he is declaring a pure virtual destructor in the base class.
And again defining...
|
by: romayankin |
last post by:
Can someone explain what am I doing wrong?
Header:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class CMyBase {
private:
CMyBase(const CMyBase& obj); /* Disable copy constuctor */
void...
| |
by: al pacino |
last post by:
hi,
i want to know how does c++ compiler prohibits the creation of instance
of an abstract class?
i think it must be checking on the vtable entry if there is an entry
with zero(indicting...
|
by: mfabricius |
last post by:
Hi,
I am probably trying to do something really stupid.
There is a class shape:
class Shape
{
public:
Shape();
|
by: Stodge |
last post by:
Yet another SWIG question (YASQ!).
I'm having a problem with using an abstract base class. When
generating the Python bindings, SWIG thinks that all the concrete
classes that derive from this...
|
by: Angus |
last post by:
Hello
I want to use polymorphic feature.
Eg if I had a base Shape class and a derived Circle class I could do
things like this:
Shape myShape;
MyCircle* pCircle = &myShape;...
|
by: Magnus.Moraberg |
last post by:
Lets say I have the following -
class Shape
{
...
virtual void Plot();
PrintInfo();
}
class Circle : public Shape
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| | |