Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

C-plus-plus coding errors

I am learning C++ and I have to complete an Object Oriented Program. I am struggling to understand why I am getting an error. Please give as much as detail as possible when explaining because it would be helpful in the journey of teaching myself C++. Below is my initial code and the error:

#include<iostream>
using namespace std;

class RectangularCube { //Defined the class Rectangular Cube
    private: //Access specifier - Declare two sides as private data field
        string color; //Private data field color that is string type
        double width;
        double height;

    public:
    double length; //Declare one side as a public data field

    //Contructor with parameteres
    RectangularCube(string newColor, double newWidth, double newHeight, double newLength) {
        color = newColor;
        width = newWidth;
        height = newHeight;
        length = newLength;
    }

    RectangularCube() { //No-arguments contructor with all three sides and color set to different values
        color = black;
        width = 5.145;
        height = 4.894;
        length = 10.123;
    }

    // Return Volume of this Rectangular Cube
    double getVolume() {
        return length * width * height;
    };

    //Return Surface Area of this Rectangular Cube
    double getSurfaceArea() {
        return 2(length * width) + 2(length * height) + 2(width * height)
    };
    
    //get and set functions for the two private sides and color data field
    double getColor();
    double getWidth();
    double getHeight();
    void setColor();
    void setWidth();
    void setHeight();

};

int main() {
    RectangularCube rectangularcube1();

    cout << "The Volume of the Rectangular Cube is: "
        << rectangularcube1.getVolume() << endl;
    return 0;
}

The Error

            color = black;
                    ^
RectangularCube.cpp:35:21: error: called object type 'int' is not a function or function pointer
            return 2(length * width) + 2(length * height) + 2(width * height)
                   ~^
RectangularCube.cpp:35:41: error: called object type 'int' is not a function or function pointer
            return 2(length * width) + 2(length * height) + 2(width * height)
                                       ~^
RectangularCube.cpp:35:62: error: called object type 'int' is not a function or function pointer
            return 2(length * width) + 2(length * height) + 2(width * height)
                                                            ~^
4 errors generated.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

By

2(length * width)

I assume you really mean

2*(length * width)

and this

 color = black;

should probably be

color = "black";
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading