Description
Create an object-oriented program that uses inheritance to perform
calculations on a rectangle or a square.
Sample Output (Your output should be similar to the text in the following box)
Rectangle Calculator Continue? (y/n): y Rectangle or square? (r/s): s Continue? (y/n): n Thank you for using my app |
Specifications
Submission Instructions
# Python code for above problem
# parent class
class Shape( object ):
def __init__(self, height, width):
# constructor that initialises the object with
values
self.height = height
self.width = width
def area(self):
# method that prints the
area
print("Area:",self.height*self.width)
def perimeter(self):
# method
that prints the perimeter
print("Perimeter:",2*(self.height+self.width))
# child class
class Rectangle( Shape
):
def __init__(self, height, width):
Shape.__init__(self, height,
width)
class Square( Shape
):
def __init__(self, length):
Shape.__init__(self, length,
length)
def main():
while(True):
shape=input("Rectangle or Square?
(r/s): ")
if(shape[0]=='r'):
height=int(input("Height: "))
width=int(input("Width: "))
rectangle=Rectangle(height, width)
rectangle.perimeter()
rectangle.area()
elif(shape[0]=='s'):
length=int(input("Length: "))
square=Square(length)
square.perimeter()
square.area()
else:
print("Invalid option")
choice=input("Continue? (y/n):
")
if(choice[0]!='y'):
break
print("Thank you for using my app")
main()
Sample output:
# Mention in comments if any mistakes or errors are found. Thank you.
Description Create an object-oriented program that uses inheritance to perform calculations on a rectangle or a...
Create a program that calculates the area of various shapes. Console Specifications Create an abstract class named Shape. This class should contain virtual member function named get_area() that returns a double type. Create a class named Circle that inherits the Shape class and contains these constructors and member functions: Circle(double radius) double get_radius() void set_radius(double radius) double get_area() Create a class named Square that inherits the Shape class and contains these constructors and member functions: Square(double width) double get_width() void...
Using Python Write the following well-documented (commented) program. Create a class called Shape that has a method for printing the area and the perimeter. Create three classes (Square, Rectangle, and Circle) which inherit from it. Square will have one instance variable for the length. Rectangle will have two instance variables for the width and height. Circle will have one instance variable for the radius. The three classes will have methods for computing the area and perimeter of its corresponding shape....
I need help with the C++ for the following problem: Write a program uses objected oriented programming to calculate the area of a rectangle. The program should create a Rectangle class that has the following attributes and member functions: Attributes: width and length Member functions: setWidth(), setLength(), getWidth() , getLength(), getArea() Where width and length are the respect width and length of a Rectangle class. The setWidth() and setLength() member function should set the length and width, the getWidth(), getLenght(),...
Use DevC++ to implement a program uses objected oriented programming to calculate the area of a rectangle. The program should create a Rectangle class that has the following attributes and member functions: Attributes: width and length Member functions: setWidth(), setLength(), getWidth() , getLength(), getArea() Where width and length are the respect width and length of a Rectangle class. The setWidth() and setLength() member function should set the length and width, the getWidth(), getLenght(), and getArea() member function should get the...
Use C++ to implement a program uses objected oriented programming to calculate the area of a rectangle. The program should create a Rectangle class that has the following attributes and member functions: Attributes: width and length Member functions: setWidth(), setLength(), getWidth() , getLength(), getArea() Where width and length are the respect width and length of a Rectangle class. The setWidth() and setLength() member function should set the length and width, the getWidth(), getLenght(), and getArea() member function should get the...
Q2) Interface Create a program that calculates the perimeter and the area of any given 2D shape. The program should dynamically assign the appropriate calculation for the given shape. The type of shapes are the following: • Quadrilateral 0 Square . Perimeter: 4xL • Area:LXL O Rectangle • Perimeter: 2(L+W) • Area:LxW Circle Circumference: I x Diameter (TT = 3.14) Area: (TT xD')/4 Triangle (assume right triangle) o Perimeter: a+b+c O Area: 0.5 x base x height (hint: the base...
ASAP Please. Python Program Description Create an object-oriented program that allows you to enter data for employees. Specifications Create an abstract Employee class that provides private attributes for the first name, last name, email address, and social security number. This class should provide functions that set and return the employee’s first name, last name, email address, and social security number. This class has a function: get_net_income which returns 0. Create a Manager class that inherits the Employee class. This class...
C++ program. int main() { Rectangle box; // Define an instance of the Rectangle class double rectWidth; // Local variable for width double rectLength; // Local variable for length string rectColor; // Get the rectangle's width and length from the user. cout << "This program will calculate the area of a\n"; cout << "rectangle. What is the width? "; cin >> rectWidth; cout << "What is the length? "; cin >>...
Go to the Java API and review the Rectangle class briefly. As directed below, create a subclass of the Rectangle class called BetterRectangle as described below. Create another class called RectangleTester, which fully tests the BetterRectangle, by displaying a menu that allows a user to process data for multiple rectangles until they choose to quit. Be sure to include sample runs as block comments in your tester source code file. P9.10 The Rectangle class of the standard Java library does...
C++ ONLY PLEASE Problem Description: Objective: Create Inheritance Hierarchy to Demonstrate Polymorphic Behavior Create a Rectangle Class Derive a Square Class from the Rectangle Class Derive a Right Triangle Class from the Rectangle Class Create a Circle Class Create a Sphere Class Create a Prism Class Define any other classes necessary to implement a solution Define a Program Driver Class for Demonstration a) Create a Container to hold objects of the types described above b) Create and Add two(2) objects...