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; }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education