Answer the given question with a proper explanation and step-by-step solution. C++ Virtual Methods Create the following 3 classes: 1. AppWindow class, containing: - A protected instance of a rectangle class Rect defining the AppWindow's position (x,y) and size (w,h). (You may use the Rect class you developed in the previous lab. In main(), the width and height are assumed to be public and called "w" and "h".) - The following constructors to initialize the dimensions: AppWindow(); // initialize member rect's dimensions to 0 AppWindow( float x, float y, float w, float h ); // initialize member rect's dimensions with the 4 floats AppWindow( const Rect& r ); // initialize member rect's dimensions with r's dimensions - A method to retrieve the member rectangle: const Rect& get_rect(); - A virtual method called resize(). When this method is called, your implementation is supposed to change the dimensions of the internal rectangle of the window. virtual void resize( int w, int h ); 2. CircleWin class, which inherits from AppWindow, containing: - A protected float called "radius". For this class, radius is considered to be the maximum dimension among w and h of the rectangle. - The same three constructors as AppWindow. You should only initialize the value of radius in this class, after using AppWindow's constructor to initialize the inherited rectangle. (Recall the initializer list.) - An overriden resize() method such that it will recompute the radius and print it out like this: "radius: ", where is the maximum dimension. Remember to still change the dimensions of the internal rectangle. 3. RectWin class, which also inherits from AppWindow, containing: - A protected float called "area". The area is equal to w * h. - The same three constructors as AppWindow. You should only initialize the value of area in this class, after using AppWindow's constructor to initialize the inherited rectangle. (Again, recall the initializer list.) - An overriden resize() method such that it will recompute the area and print it out like this: "area: ". Remember to still change the dimensions of the internal rectangle. Upload your three classes in a single header file named App.h. Your code will be tested for correctness using the file virtualMethods.cpp. SAMPLE OUTPUT radius: 4 radius: 10 area: 12 area: 40 virtualMethods.cpp #include #include #include "App.h" using namespace std; int main( int argc, const char* argv[] ) { Rect r( 2, 0, 4, 5 ); vector w; w.push_back( new CircleWin( 1, 1, 3, 2 ) ); w.push_back( new CircleWin( r ) ); w.push_back( new RectWin( 1, 1, 2, 3 ) ); w.push_back( new RectWin( r ) ); for( int i = 0; i < w.size(); i++ ) w[i]->resize( w[i]->get_rect().w, w[i]->get_rect().h * 2 ); 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

Answer the given question with a proper explanation and step-by-step solution.

C++

Virtual Methods

Create the following 3 classes:

1. AppWindow class, containing:

- A protected instance of a rectangle class Rect defining the AppWindow's position (x,y) and size (w,h). (You may use the Rect class you developed in the previous lab. In main(), the width and height are assumed to be public and called "w" and "h".)

- The following constructors to initialize the dimensions:

AppWindow(); // initialize member rect's dimensions to 0
AppWindow( float x, float y, float w, float h ); // initialize member rect's dimensions with the 4 floats
AppWindow( const Rect& r ); // initialize member rect's dimensions with r's dimensions

- A method to retrieve the member rectangle:

const Rect& get_rect();

- A virtual method called resize(). When this method is called, your implementation is supposed to change the dimensions of the internal rectangle of the window.

virtual void resize( int w, int h );

2. CircleWin class, which inherits from AppWindow, containing:

- A protected float called "radius". For this class, radius is considered to be the maximum dimension among w and h of the rectangle.

- The same three constructors as AppWindow. You should only initialize the value of radius in this class, after using AppWindow's constructor to initialize the inherited rectangle. (Recall the initializer list.)

- An overriden resize() method such that it will recompute the radius and print it out like this: "radius: <max>", where <max> is the maximum dimension. Remember to still change the dimensions of the internal rectangle.

3. RectWin class, which also inherits from AppWindow, containing:

- A protected float called "area". The area is equal to w * h.

- The same three constructors as AppWindow. You should only initialize the value of area in this class, after using AppWindow's constructor to initialize the inherited rectangle. (Again, recall the initializer list.)

- An overriden resize() method such that it will recompute the area and print it out like this: "area: <area>". Remember to still change the dimensions of the internal rectangle.

Upload your three classes in a single header file named App.h. Your code will be tested for correctness using the file virtualMethods.cpp.

SAMPLE OUTPUT
radius: 4
radius: 10
area: 12
area: 40

 

virtualMethods.cpp

#include <iostream>
#include <vector>

#include "App.h"

using namespace std;

int main( int argc, const char* argv[] )
{
   Rect r( 2, 0, 4, 5 );

   vector<AppWindow*> w;

   w.push_back( new CircleWin( 1, 1, 3, 2 ) );
   w.push_back( new CircleWin( r ) );
   w.push_back( new RectWin( 1, 1, 2, 3 ) );
   w.push_back( new RectWin( r ) );

   for( int i = 0; i < w.size(); i++ )
       w[i]->resize( w[i]->get_rect().w, w[i]->get_rect().h * 2 );

   return 0;
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 6 steps with 3 images

Blurred answer
Knowledge Booster
Types of Loop
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