Question

In: Computer Science

Please submit a screenshot of where your code got compiled, executed, showing the execution result Write...

Please submit a screenshot of where your code got compiled, executed, showing the execution result

Write a program/function in python that will perform the following functions, when the program is executed, to demonstrate the features of an OOP language—ADT, inheritance, and polymorphism:

  1. Prompt a list of options—the main menu, below to compute the area of selected shape with input parameters:
    1. triangle
    2. rectangle
    3. square
    4. circle
    5. parallelogram
    6. Exit
  2. Per the selected option, prompt grader to enter the corresponding required parameters as described below:
    1. base and height
    2. length and width
    3. side
    4. radius
    5. base and height
  3. Your program should validate the number of input parameter(s) and the parameter(s).
    1. If the number of parameter(s) is incorrect OR the parameter is invalid (e.g., 0 or -3), display the message—input parameter(s) is/are incorrect, and allow grader to re-enter the correct parameter(s)
    2. If the input parameter(s) is/are valid, display the computed area based on the input parameter(s), and then allow grader to go back to the main menu to select any one of options.
    3. Assuming the unit is ft for all input parameters.

Please DO NOT hard-code any input values, output values in your code.

Solutions

Expert Solution

Below is the answer:

def AreaCircle():

  Radius=0

  while(Radiius<=0):

    Radius = float(input('Enter the Circle Radius (>0) = '))

  A = 3.1457 * Radius * Radius

  return A

   

   

def AreaRectangle():

  Flag=1

  while(Flag):

    Flag=0

    Dim = (input('Enter the Length and Width = '))

    x = (Dim.split(' '))

    if(len(x)==2):

      if(float(x[0])==0 or float(x[1])==0): Flag=1

    else:

      Flag=1

  A = float(x[0])*float(x[1])

  return A



def AreaSquare():

  Side=0

  while(Side<=0):

    Side = float(input('Enter the Square Side (>0) = '))

  A = Side * Side

  return A



def AreaParallelogram():

  Flag=1

  while(Flag):

    Flag=0

    Dim = (input('Enter the Base and Height (>0) = '))

    x = (Dim.split(' '))

    if(len(x)==2):

      if(float(x[0])==0 or float(x[1])==0): Flag=1

    else: Flag=0   

  x = (Dim.split(' '))

  A = float(x[0])*float(x[1])

  return(A)



def IsValid(Side1,Side2,Side3):

  Flag=0;

  Sum = Side1 + Side2

  if(Sum>Side3 and Flag==0):

     Flag=1    



  Sum = Side2 + Side3

  if(Sum>Side1 and Flag==0):

     Flag=1    



  Sum = Side1 + Side3

  if(Sum>Side2 and Flag==0):

     Flag=1    

  return Flag



def Area(Side1,Side2,Side3):

   u = float(Side1)

   v = float(Side2)

   w = float(Side3)

    

   s = (u+v+w)/2

   A = math.sqrt(s*(s-u)*(s-v)*(s-w))

   return(A)

    







Command=6

Flag=1

while(Flag):

  Command=6

  while(Command<0 or Command>5):

    print("\nFor Triangle,  Press --> 1")

    print("For Rectangle,   Press --> 2")

    print("For Square,    Press --> 3")

    print("For Circle,    Press --> 4")

    print("For Parallelogram, Press --> 5")

    print("To QUIT,      Press --> 0")

    Command= int(input('Enter the Shape No. (1 to 5): '))

  Ar=0;

  if(Command == 0):

    Flag=0

  if(Command == 2):

    Ar = AreaRectangle();

    print("Area of Rectangle = %s"%Ar)

  if(Command == 3):

     Ar = AreaSquare();

     print("Area of Square = %s"%Ar)

  if(Command == 4):

     Ar = AreaCircle();

     print("Area of Circle = %s"%Ar)

  if(Command == 1):

    x=[]

    while(len(x)!=3):

      Sides= input('Enter three sides of a triangle followed by space: ')

      x = Sides.split()

    a = int(x[0])

    b = int(x[1])

    c = int(x[2])

    TriangleValidFlag = IsValid(a,b,c)

    if(TriangleValidFlag):

       print("TRUE: The sides are valid.")

       Ar = Area(a,b,c)

       print("Area = %s"%Ar)

    if(TriangleValidFlag==0):

       print("FALSE: The sides are not valid")

  if(Command == 5):

    Ar = AreaParallelogram();

    print("Area of parallelogram = %s"%Ar)

Related Solutions

Write assembler code to print even numbers from 1-20. Submit code and screenshot. I am coding...
Write assembler code to print even numbers from 1-20. Submit code and screenshot. I am coding in NASM on a SASM system.
2. Run the following C program, and submit the screenshot of the result. Also briefly explain...
2. Run the following C program, and submit the screenshot of the result. Also briefly explain the result. #include <sys/types.h> #include <stdio.h> #include <unistd.h> #define SIZE 5 int nums[SIZE] = {0,1,2,3,4}; int main() { int i; pid_t pid; pid = fork(); if (pid == 0) { for (i = 0; i < SIZE; i++) { nums[i] *= -i; printf("CHILD: %d ",nums[i]); /* LINE X */ } } else if (pid > 0) { wait(NULL); for (i = 0; i <...
Please complete this worksheet showing all calculations for this case. Submit this to your professor for...
Please complete this worksheet showing all calculations for this case. Submit this to your professor for grading. Complete all colored spaces. CONCH REPUBLIC ELECTRONICS Student Name: Student Assumptions, provided in the text Equipment $      34,500,000.00 Salvage value $       3,500,000.00 R&D $          750,000.00 Marketing study $          200,000.00 Year 1 Year 2 Year 3 Year 4 Year 5 Sales(units) 64000 106000 87000 78000 54000 Depreciation rate 14.29% 24.49% 17.49% 12.49% 8.93% Price $                480.00 VC $                205.00 per unit FC $       5,100,000.00...
Please show screenshot outputs and fully functional code for the Java program. Write the following methods...
Please show screenshot outputs and fully functional code for the Java program. Write the following methods to   1) read the content of an array of 5 doubles public static double[] readingArray() 2) find and print:the smallest element in an array of 5 double public static void smallest(double [] array) 3) find and print:the largest element in an array of 5 doubles pubic static void largest (double [] array) In the main method - invoke readingArray and enter the following numbers...
Directly copy the source code and paste into the Word file. Screenshot of running result must...
Directly copy the source code and paste into the Word file. Screenshot of running result must be presented. 1. (20 points) Write the “Hello, world!” program. 2. (30 points) Write a program to calculate the sum from -5 to10. Use the for loop to do the calculation. 3. (20 points) Write a complete C++ program that asks the user to enter the necessary information about the cylinder, calculate the volume in a function (named as calculate_vol, using reference to pass...
in LINUX Inspect the login.defs file in your VM and provide a screenshot showing: LOGIN_RETRIES and...
in LINUX Inspect the login.defs file in your VM and provide a screenshot showing: LOGIN_RETRIES and LOGIN_TIMEOUT PLEASE SHOW THE STEPS
please select and submit a corporate Code of Ethics from a company of your choosing. For...
please select and submit a corporate Code of Ethics from a company of your choosing. For your response, first, tell me about the company and why you selected it. Second, describe the Code of Ethics and what appealed to you about the Code. Third, explain the ethical lens perspective that is communicated through the Code of Ethics for the corporation you chose.
PLEASE UPLOAD EXCEL FILE OR A SCREENSHOT SHOWING FORMULAS Must be submitted in excel with any...
PLEASE UPLOAD EXCEL FILE OR A SCREENSHOT SHOWING FORMULAS Must be submitted in excel with any math done with formulas within cells. The Jackpots Dreams Cards Company is a card manufacturer. All direct materials and conversion costs are applied to all of Proball Trading Cards’ products at an even rate throughout the manufacturing process. For August, the beginning work in process inventory for the Finishing Department was 9,600 units that averaged 65 percent complete. Ending work in process inventory was...
PLEASE UPLOAD EXCEL FILE OR A SCREENSHOT SHOWING FORMULAS Must be submitted in excel with any...
PLEASE UPLOAD EXCEL FILE OR A SCREENSHOT SHOWING FORMULAS Must be submitted in excel with any math done with formulas within cells. Electric Car Co (ECC). currently manufactures two different types of fully electronic cars in 2021. Type 8Y is a large SUV whereas Type 8W will be the fastest car in the world with 10 rocket thrusters. ECC has decided to use ABC costing instead of traditional costing. The 2021 budget to manufacture these new types include manufacturing overhead...
Name your functions countOnesLoop() and countOnesWhere() and submit your code in a file named countOnes.py. Write...
Name your functions countOnesLoop() and countOnesWhere() and submit your code in a file named countOnes.py. Write a function that consists of a set of loops that run through an array and count the number of ones in it. Do the same thing using the where() function (use info(where) to find out how to use it) (in python)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT