computer science questions

home / study / engineering / computer science / computer science questions and answers / for…

home / study / engineering / computer science / computer science questions and answers / for the first part of this lab, you will write a class (rectangle) which represents a rectangle …

Your question has been answered

Let us know if you got a helpful answer. Rate this answer

Question: For the first part of this lab, you will write a class (Rectangle) which represents a rectangle s…

For the first part of this lab, you will write a class (Rectangle) which represents a rectangle shape. The Rectangle class will have two functions (getArea() and getPerimeter()), plus a constructor. Your class will store the width and the height of the rectangle, as floating point value instance variables. The constructor will take two arguments (width, height), and will initialize those instance variables to the supplied values. The getArea() will return the area of the rectangle, calculated in the body of the function using this formula: area = width * height The getPerimeter() will return the perimeter of the rectangle, calculated in the body of the function using this formula: perimeter = width * 2 + height * 2 Write some code to create a few Rectangle instances, testing the constructor with different values, as well as tests the two functions. Note: It is not recommended to use user input for testing, but rather type the values directly into the code where you instantiate your Rectangle instances. For a wider variety of tests, try creating more Rectangle instances, with different parameters. Part 2 For the second part of this lab, you will a class (Circle) which represents a circle shape. The Circle class will have two functions (getArea() and getPerimeter()), plus a constructor. Your class will store the radius of the circle, as a floating point value instance variable. The constructor will take one arguments (radius), and will initialize that instance variable to the supplied value. The getArea() will return the area of the circle, calculated in the body of the function using this formula: area = π * radius2 The getPerimeter() will return the perimeter (circumference) of the circle, calculated in the body of the function using this formula: 2 perimeter = 2π * radius Write some code to create a few Circle instances, testing the constructor with different radius values, as well as tests the two functions.

Part 3 For the third part of this lab, you will a class (Shape) which represents a general shape. Modify the Rectangle and Circle classes from parts 1 and 2 to have the Shape class as a parent class (i.e. add an inheritance relationship between Circle and Shape, as well as between Rectangle and Shape). Create some code in main that creates a few instances of each class (Rectangle, Circle), and adds each to a vector of Rectangle instances or a vector of Circle instances, as well as testing the getArea() and getPerimeter() member functions.

I did first two parts. Only need to do 3rd part

code should be in PYTHON