his C++ question is about a grid writer and no code is needed to be written, questions just need to be answered. The project uses a class named GridWriter to display circles and rectangles in a text grid. The GridWriter class is a collection type class similar to an IntCollection. It stores Circle and Rectangle objects that inherit from a base class named Shape. The GridWriter class has a member function named display that accepts a row count and column count as arguments, and prints out a text grid that shows the shapes that it stores. Consider the main function below. It creates a GridWriter, adds some shapes, and then displays a grid: int main() {         GridWriter gw;         // Add some circles...       gw.add(new Circle(10, 10, 9));       gw.add(new Circle(25, 20, 12));       gw.add(new Circle(25, 20, 5));         // Add a rectangle...       gw.add(new Rectangle(40, 0, 10, 10));         // Display the grid with 40 rows and 50 columns       gw.display(40, 50); } The console output is  the image attached in the assignment:   The code in the main function creates three Circle objects and one Rectangle object to the GridWriter. See if you can find the shapes in the output. The Shape class defines x and y. Both the circle and the rectangle class inherit these member variables. Similarly, the Shape class defines the getArea and containsPoint member functions, and the circle and rectangle inherit them. The circle and rectangle classes extend the Shape class by adding radius or height and width, respectively. Download the GridWriter.zip: http://fog.ccsf.edu/~mluttrel/cs110b/GridWriter.zip file and examine the classes. Carefully read through the code. When you are comfortable with the code, answer the following questions. Submit your answers in a text file.   1. The two argument constructor of the Shape class contains this code:   this->x = x;   this->y = y; Why is it necessary to put "this->" in front of x and y? If you are not sure then remove these lines and see if it changes the output, which may provide you a hint why it is necessary. Note: the answer to this question is not what happens if you remove "this->" but why do you need it.   2. In the containsPoint member function of Circle, why are this->x and this->y in scope, even though they are not defined as member variables in Circle.h?   3. What is the purpose of the keyword "virtual" in front of Shape::containsPoint and Shape::getArea? What is the purpose of the " = 0"?   4. In Circle.cpp the three argument Circle constructor is defined like this: Circle:: Circle(int x, int y, int radius) : Shape(x, y) { this->radius = radius; } What is the purpose of the ": Shape(x, y)" (shown in bold in the code above). What happens if you remove it?   5. List an example of polymorphism that you can find in the code base.

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

This C++ question is about a grid writer and no code is needed to be written, questions just need to be answered.

The project uses a class named GridWriter to display circles and rectangles in a text grid. The GridWriter class is a collection type class similar to an IntCollection. It stores Circle and Rectangle objects that inherit from a base class named Shape.

The GridWriter class has a member function named display that accepts a row count and column count as arguments, and prints out a text grid that shows the shapes that it stores.

Consider the main function below. It creates a GridWriter, adds some shapes, and then displays a grid:

int main() {

        GridWriter gw;

        // Add some circles...

      gw.add(new Circle(10, 10, 9));

      gw.add(new Circle(25, 20, 12));

      gw.add(new Circle(25, 20, 5));

        // Add a rectangle...

      gw.add(new Rectangle(40, 0, 10, 10));

        // Display the grid with 40 rows and 50 columns

      gw.display(40, 50); }

The console output is  the image attached in the assignment:

 

The code in the main function creates three Circle objects and one Rectangle object to the GridWriter. See if you can find the shapes in the output.

The Shape class defines x and y. Both the circle and the rectangle class inherit these member variables. Similarly, the Shape class defines the getArea and containsPoint member functions, and the circle and rectangle inherit them. The circle and rectangle classes extend the Shape class by adding radius or height and width, respectively.

Download the GridWriter.zip: http://fog.ccsf.edu/~mluttrel/cs110b/GridWriter.zip

file and examine the classes. Carefully read through the code. When you are comfortable with the code, answer the following questions. Submit your answers in a text file.

 

1. The two argument constructor of the Shape class contains this code:

  this->x = x;   this->y = y;

Why is it necessary to put "this->" in front of x and y? If you are not sure then remove these lines and see if it changes the output, which may provide you a hint why it is necessary. Note: the answer to this question is not what happens if you remove "this->" but why do you need it.

 

2. In the containsPoint member function of Circle, why are this->x and this->y in scope, even though they are not defined as member variables in Circle.h?

 

3. What is the purpose of the keyword "virtual" in front of Shape::containsPoint and Shape::getArea? What is the purpose of the " = 0"?

 

4. In Circle.cpp the three argument Circle constructor is defined like this:

Circle:: Circle(int x, int y, int radius) : Shape(x, y) { this->radius = radius; }

What is the purpose of the ": Shape(x, y)" (shown in bold in the code above). What happens if you remove it?

 

5. List an example of polymorphism that you can find in the code base. In other words, list a statement where the datatype of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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 11 1 1 1 1 1 1 1 1
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Passing Array as Argument
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.
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