[SOLVED] COM1001 Lab 7

30.00 $

Category: Tags: ,
Click Category Button to View Your Next Assignment | Homework

You will receive the following solution file(s) instantly after successful payment:

zip file icon Lab-7-80firj.zip (888.4 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
πŸ”’ Securely Powered by:
Secure Checkout
5/5 - (1 vote)

Write five classes conforming the relation shown in UML class diagram below, i.e. a Rectangle is a Shape, a Circle is a Shape, a Triangle is a Shape, and a Square is a Shape. Write all the class implementations to Shapes.py. Test your code with the sample main function provided to you (Main.py). It must print the sample output provided to you (output.txt). You can also create and test your own main functions.

Details:

In the diagram, class notations consist of three parts; (1) class name, (2) class attributes, (3) class methods. The name of the class appears in the first partition, e.g., Shape, Rectangle etc. Attributes are

1

shown in the second partition, e.g., name, color, width etc. Methods are shown in the third partition, e.g., get_name(), get_area() etc.

Member functions:

  • – Β get methods: returns the related attribute of the class. For ex; get_name(self) returns name attribute.
  • – Β set methods: sets the related attribute of the class. For ex; set_name(self, n) assign the input n to self.name.
  • – Β get_area(self): calculates the area of the shape and returns it.
  • – Β get_perimeter(self): calculates the perimeter of the shape and returns it.
  • – Β __str__(self): returns a string representation of the class. For the output format, please check

    provided output file (output.txt). Note that, print the area and perimeter with 2 digit after decimal point. Hint: ‘{0:.2f}’.format(x)

    Hints:

    – You can use math library (import math) Area of rectangle = 𝑀𝑖𝑑𝑑h βˆ— h𝑒𝑖𝑔h𝑑

    Area of circle = 𝑝𝑖 βˆ— π‘Ÿπ‘Žπ‘‘π‘–π‘’π‘ 2
    Area of triangle = 𝑒 βˆ— 𝑒 βˆ’ 𝑒𝑑𝑔𝑒1 βˆ— 𝑒 βˆ’ 𝑒𝑑𝑔𝑒2 βˆ— (𝑒 βˆ’ 𝑒𝑑𝑔𝑒3)

    𝑒 = (𝑒𝑑𝑔𝑒1+𝑒𝑑𝑔𝑒2+𝑒𝑑𝑔𝑒3)/2

    Area of square = 𝑒𝑑𝑔𝑒2
    Perimeter of rectangle = 2 βˆ— (𝑀𝑖𝑑𝑑h + h𝑒𝑖𝑔h𝑑) Perimeter of circle = 2 βˆ— 𝑝𝑖 βˆ— π‘Ÿπ‘Žπ‘‘π‘–π‘’π‘ 
    Perimeter of triangle = 𝑒𝑑𝑔𝑒1 + 𝑒𝑑𝑔𝑒2 + 𝑒𝑑𝑔𝑒3 Perimeter of square = 4 βˆ— 𝑒𝑑𝑔𝑒

    Testing: You are provided with an output file. You can test your program from the command line using the following commands. (>: stands for command prompt)

    > python Main.py > my_output.txt

    The outputs, which you generate using the print() function in the source codes, are redirected to my_output.txt file. You can then check if my_output.txt file is exactly the same with the provided output.txt file, using diff command from the command prompt: > diff output.txt my_output.txt

  • Lab-7-80firj.zip