Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I interrupted at create object using new operator, help me solve it. Type the fu

ID: 3540732 • Letter: I

Question

I interrupted at create object using new operator, help me solve it.
Type the full code and using comment // to explain what is my wrong.


Based on the program above, modify it to include the following a member function that returns the volume of a square object a default constructor that initializes the length of the object to 2. a destructor that prints a statement, ex: "destructing object with length 2" in the main function, do the following in order:! create an object using the new operator Invoke area Q and volume() functions on the object appropriately to print out the values. Delete the object in (j). Create an dynamic array of 5 objects using the new operator Using a for loop, call some functions on each object in (iv), Invoke the set, data(..) function passing the value of the counter + 1 invoke the area() and volume() functions on each object appropriately to print out the values. Delete the object in (iv).

Explanation / Answer

#include <iostream>
#include <math.h>
//#include <new>
using namespace std;
class Square
{
    private: int length;
    public:
    void set_data(int x)
    {
        length = x;
    }
    int area()
    {
        return pow(length,2);
    }
    int volume()
    {
        return (length*length*length);
    }
    Square()
    {
        length=2;
    }
    Square(int leng):length(leng)
    {
        cout<<"constructing object with length 2"<<endl;
    }
    ~Square()
    {
    cout<<"destructing object"<<endl;
    }
};

int main()
{

    Square * sq1 = new Square(); // create object using new operator
    float area, volume;
    area = sq1->area();
    cout << "Area of square given by " << area << endl;
    volume = sq1->volume();
    cout << "Volume of square given by " << volume << endl;
    delete sq1;
    return 0;
}