// Im having a lot of trouble with this and i've spent hours trying to figure out how to fix it.
//Do any of you know which abstract class is being instantiated?
//VS says its the Shape class but i don't see whats wrong
class Shape
{
public:
Shape() {}
virtual double computeArea() = 0;
virtual void expand(int factor) = 0;
virtual void display() = 0;
virtual ~Shape() {}
//other member functions if you want to add;
};
class Circle: public Shape
{
public:
Circle(double r);
double computeArea()
{
return (3.14 * (radius * radius));
}
void expand(int factor)
{
radius = radius * factor;
}
void display()
{
cout << "Circle: (radius = " << radius << " )\n";
}
private:
double radius;
};
class Rectangle: public Shape
{
public:
Rectangle(doubl e wid, double len);
double computeArea()
{
return (length * width);
}
void expand(int factor)
{
width = width * factor;
length = length * factor;
}
void display()
{
cout << "Rectangle: (length = " << length << ", width = " << width << " )\n";
}
private:
double width, length;
};
class Cuboid: public Shape
{
public:
Cuboid(double wid, double len, double hei);
void computeVolume() ;
double computeArea()
{
return ((2 * width*length) + (2 * width*height) + (2 * length*height)) ;
}
void expand(int factor)
{
width = width * factor;
length = length * factor;
height = height * factor;
}
void display()
{
cout << "Cuboid: (length = " << length << ", width = " << width << ", height = " << height << " )\n";
}
private:
double width, length, height, volume;
};
class Cylinder: public Shape
{
public:
Cylinder(double r, double hei);
void computeVolume() ;
double computeArea()
{
return ((2 * 3.14*radius*hei ght) + (2 * 3.14*(radius*ra dius)));
}
void expand(int factor)
{
radius = radius * factor;
height = height * factor;
}
void display()
{
cout << "Cylinder: (height = " << height << ", radius = " << radius << " )\n";
}
private:
double radius, height, volume;
};
class Sphere: public Shape
{
public:
Sphere(double r);
void computeVolume() ;
double computeArea()
{
return (4 * 3.14*(radius*ra dius));
}
void expand(int factor)
{
radius = radius * factor;
}
void display()
{
cout << "Sphere: (radius = " << radius << " )\n";
}
private:
double radius, volume;
};
//Do any of you know which abstract class is being instantiated?
//VS says its the Shape class but i don't see whats wrong
class Shape
{
public:
Shape() {}
virtual double computeArea() = 0;
virtual void expand(int factor) = 0;
virtual void display() = 0;
virtual ~Shape() {}
//other member functions if you want to add;
};
class Circle: public Shape
{
public:
Circle(double r);
double computeArea()
{
return (3.14 * (radius * radius));
}
void expand(int factor)
{
radius = radius * factor;
}
void display()
{
cout << "Circle: (radius = " << radius << " )\n";
}
private:
double radius;
};
class Rectangle: public Shape
{
public:
Rectangle(doubl e wid, double len);
double computeArea()
{
return (length * width);
}
void expand(int factor)
{
width = width * factor;
length = length * factor;
}
void display()
{
cout << "Rectangle: (length = " << length << ", width = " << width << " )\n";
}
private:
double width, length;
};
class Cuboid: public Shape
{
public:
Cuboid(double wid, double len, double hei);
void computeVolume() ;
double computeArea()
{
return ((2 * width*length) + (2 * width*height) + (2 * length*height)) ;
}
void expand(int factor)
{
width = width * factor;
length = length * factor;
height = height * factor;
}
void display()
{
cout << "Cuboid: (length = " << length << ", width = " << width << ", height = " << height << " )\n";
}
private:
double width, length, height, volume;
};
class Cylinder: public Shape
{
public:
Cylinder(double r, double hei);
void computeVolume() ;
double computeArea()
{
return ((2 * 3.14*radius*hei ght) + (2 * 3.14*(radius*ra dius)));
}
void expand(int factor)
{
radius = radius * factor;
height = height * factor;
}
void display()
{
cout << "Cylinder: (height = " << height << ", radius = " << radius << " )\n";
}
private:
double radius, height, volume;
};
class Sphere: public Shape
{
public:
Sphere(double r);
void computeVolume() ;
double computeArea()
{
return (4 * 3.14*(radius*ra dius));
}
void expand(int factor)
{
radius = radius * factor;
}
void display()
{
cout << "Sphere: (radius = " << radius << " )\n";
}
private:
double radius, volume;
};
Comment