Reputation: 13
#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;
class Shape3D
{
public:
virtual double volumn() ;
virtual double surfaceArea() ;
};
class RightRectangularPyramid : public Shape3D
{
private:
double width;
double length;
double height;
public:
RightRectangularPyramid(double width, double length, double height) : Shape3D(width, length, height) {
this -> width = 0.0;
this -> length = 0.0;
this -> height = 0.0;
}
double volumn() override{
return width * length * height ;
}
double surfaceArea() override{
return (length * width) + (length * sqrt(height*height + (width/2.0)*(width/2.0))) + (width * sqrt(height*height + (length/2.0)*(length/2.0)));
}
};
class Sphere : public Shape3D
{
private:
double radius;
public:
Sphere(double radius){
this -> radius = radius;
}
double volumn() override{
return 4.0/3.0 * M_PI * pow(radius,2);
}
double surfaceArea() override{
return 4 * M_PI * pow(radius,2);
}
};
int main()
{
int tc;
cin >> tc;
if (tc == 1) {
Shape3D **shapes = new Shape3D*[3];
shapes[0] = new RightRectangularPyramid(1, 5.2, 7);
shapes[1] = new Sphere(10.6);
shapes[2] = new RightRectangularPyramid(3, 3.5, 4.13);
for (int i = 0; i < 3; i++) {
cout << "Volumn: " << (*shapes)->volumn() << endl;
cout << "Surface Area: " << (*shapes)->surfaceArea() << endl;
cout << "--------------------\n";
*shapes++;
}
} else if (tc == 2) {
RightRectangularPyramid rectangle;
Sphere sphere;
cout << rectangle.volumn() << endl;
cout << rectangle.surfaceArea() << endl;
cout << sphere.volumn() << endl;
cout << sphere.surfaceArea() << endl;
} else if (tc == 3) {
RightRectangularPyramid rectangle(171.5, 45.33, 31.02);
cout << rectangle.volumn() << endl;
cout << rectangle.surfaceArea() << endl;
} else if (tc == 4) {
Sphere sphere(34.25);
cout << sphere.volumn() << endl;
cout << sphere.surfaceArea() << endl;
} else if (tc == 5) {
RightRectangularPyramid rectangle(171.5, 45.33, 31.02);
Sphere sphere(34.25);
Shape3D *shape = &rectangle;
cout << shape->volumn() << " " << shape->surfaceArea() << endl;
shape = &sphere;
cout << shape->volumn() << " " << shape->surfaceArea() << endl;
} else if(tc == 6) {
}
}
any error
error: no matching function for call to 'Shape3D::Shape3D(double&, double&, double&)' RightRectangularPyramid(double width, double length, double height) : Shape3D(width, length, height)
erro : no matching function for call to 'RightRectangularPyramid::RightRectangularPyramid()' RightRectangularPyramid rectangle;
error: no matching function for call to 'Sphere::Sphere()' Sphere sphere;
and this more error https://ibb.co/nrV3H3p
Upvotes: 1
Views: 2111
Reputation: 349
error: no matching function for call to 'Shape3D::Shape3D(double&, double&, double&)'
This is because your Shape3D
class doesn't have a constructor that takes three double
s.
erro : no matching function for call to 'RightRectangularPyramid::RightRectangularPyramid()'
Since you defined RightRectangularPyramid(double width, double length, double height)
constructor in your code, compiler won't generate code for default constructor RightRectangularPyramid()
.
error: no matching function for call to 'Sphere::Sphere()'
Same reason as above.
While compiler error message is straightforward you probably need to either provide definition of those functions or update your code (most likely) so that your code won't automatically call those functions. To fix your code following changes are necessary:
Shape3D(double&,double&,double&)
from the class RightRectangularPyramid
's constructor.Sphere
and RightRectangularPyramid
with appropriate arguments.Shape3D
pure virtual.Upvotes: 1
Reputation: 88027
Here
RightRectangularPyramid(double width, double length, double height) : Shape3D(width, length, height) {
for some reason you are trying to pass the width length and height to a Shape3D constructor which doesn't exist. Just remove the constructor call
RightRectangularPyramid(double width, double length, double height) {
Here
RightRectangularPyramid rectangle;
you are trying to create a pyramid with no width, length and height, but you wrote the RightRectangularPyramid
constructor that needs a width, length and height. You need to add these values, e.g.
RightRectangularPyramid rectangle(1.0, 2.0, 3.0);
Here, same problem
Sphere sphere;
you are trying to create a sphere with no radius, but you wrote the Sphere
constructor that needs a radius. So you need to supply one, e.g.
Sphere sphere(99.9);
Sometimes compiler error messages are cryptic, but these seem rather obvious, the compiler told you exactly what was wrong.
Upvotes: 0