Question: It's C++. I need to modify this code #include using namespace std; class Rectangle { int width, height; public: Rectangle(int x, int y) : width(x),

It's C++.

I need to modify this code

#include  using namespace std; class Rectangle { int width, height; public: Rectangle(int x, int y) : width(x), height(y) {} int area(void) { return width * height; } }; int main() { Rectangle obj (3, 4); Rectangle * foo, * bar, * baz; foo = &obj; bar = new Rectangle (5, 6); baz = new Rectangle[2] { {2,5}, {3,6} }; cout << "obj's area: " << obj.area() << ' '; cout << "*foo's area: " << foo->area() << ' '; cout << "*bar's area: " << bar->area() << ' '; cout << "baz[0]'s area:" << baz[0].area() << ' '; cout << "baz[1]'s area:" << baz[1].area() << ' '; delete bar; delete[] baz; return 0; } 

First make the objects triangles, and the pointers to those triangles. (Use the same variable names, but change the class name to "Triangle" or something similar.)

You'll be finding the area of those triangles. (1/2 base x height)

And, to help emphasis the difference between objects and the pointers to the objects, the output will not only contain the area's of the triangles, but the pointer to foo and the address of obj. Your output should look similar to this:

obj's area: 10.5 *foo's area: 10.5 obj address is 0x7ffefa0ffc70 foo is 0x7ffefa0ffc70 *bar's area: 15 baz[0]'s area:5 baz[1]'s area:9 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!