Below is some code for a rectangle class that needs to be completed. Add member function declarations to the class declaration and member function definitions below the declaration. For the accessor functions, you can add the definitions directly into the class declaration. The goal is to code the class so that it works wthout changing the main program #include using namespace std; // rectangle has a vertical height and horizontal width // The class below is a rectangle. It has two private // data members: height and width. // TODO: Complete the class declaration and definition. class rectangle { public: // TODO: declare a default constructor // Make the height and width = 1.    // TODO: declare member function void add // @param int height, int width // TODO: delcare member function void set // @param int height, int width    // TODO: declare member function void draw    // TODO: define accessor for width    // TODO: define accessor for height    private: int width; int height; }; // TODO: define the default constructor that // sets height and width to 1. rectangle::rectangle() { } // TODO: Implement add to increment the length void rectangle::add(int h, int w) { } // TODO: Implement set to overwrite the data members void rectangle::set(int h, int w) { } // TODO: Implement draw to draw a rectangle using '*' characters void rectangle::draw() {       } // TODO: Don't forget to define getWidth and getHeight int main() { // Declare 2 rectangles rectangle r1, r2;    // Print the unit rectangle cout << "r1 is " << r1.getHeight() << " x " << r1.getWidth() << endl;    // Set, print dimensions and draw r1.set(4, 3); cout << "r1 is " << r1.getHeight() << " x " << r1.getWidth() << endl; r1.draw();    // Assign, increment, print dimensions and draw r2 = r1; r2.add(3, 4); cout << "r2 is " << r2.getHeight() << " x " << r2.getWidth() << endl; r2.draw();    return 0; }

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter11: Inheritance And Composition
Section: Chapter Questions
Problem 1PE: In Chapter 10, the class clockType was designed to implement the time of day in a program. Certain...
icon
Related questions
Question

Below is some code for a rectangle class that needs to be completed. Add member function declarations to the class declaration and member function definitions below the declaration. For the accessor functions, you can add the definitions directly into the class declaration. The goal is to code the class so that it works wthout changing the main program

#include <iostream>
using namespace std;

// rectangle has a vertical height and horizontal width
// The class below is a rectangle. It has two private
// data members: height and width.
// TODO: Complete the class declaration and definition.
class rectangle {
public:
// TODO: declare a default constructor
// Make the height and width = 1.
  
// TODO: declare member function void add
// @param int height, int width

// TODO: delcare member function void set
// @param int height, int width
  
// TODO: declare member function void draw
  
// TODO: define accessor for width
  
// TODO: define accessor for height
  
private:
int width;
int height;
};

// TODO: define the default constructor that
// sets height and width to 1.
rectangle::rectangle()
{

}

// TODO: Implement add to increment the length
void rectangle::add(int h, int w)
{

}

// TODO: Implement set to overwrite the data members
void rectangle::set(int h, int w)
{

}

// TODO: Implement draw to draw a rectangle using '*' characters
void rectangle::draw()
{
  
  
}

// TODO: Don't forget to define getWidth and getHeight


int main()
{
// Declare 2 rectangles
rectangle r1, r2;
  
// Print the unit rectangle
cout << "r1 is " << r1.getHeight() << " x " << r1.getWidth() << endl;
  
// Set, print dimensions and draw
r1.set(4, 3);
cout << "r1 is " << r1.getHeight() << " x " << r1.getWidth() << endl;
r1.draw();
  
// Assign, increment, print dimensions and draw
r2 = r1;
r2.add(3, 4);
cout << "r2 is " << r2.getHeight() << " x " << r2.getWidth() << endl;
r2.draw();
  
return 0;
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning