Description
Computer Programming 1
LAB8 Quiz
Assoc. Prof. Dr. Hacer YALIM KELEΕ
Responsible Assistant: Zeynep ΓZDEMΔ°R (zynpozdemir@ankara.edu.tr)
Write five classes conforming the relation shown in UML class diagram below, i.e. a Square is a Rectangle, SquarePyramid inherit from multiple classes (Square and Triangle) and TrianglePrism inherit from multiple classes (Rectangle and Triangle). Write all the class implementations to Prism.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.
1
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., Square, Rectangle etc. Attributes are shown in the second partition, e.g., edge, width etc. Methods are shown in the third partition, e.g., get_volume(), get_area() etc.
Member functions:
– get area methods: calculates the area of the related shape and returns it.
– get perimeter methods: calculates the perimeter of the related shape and returns it.
– get_volume(self): calculates the volume of the TrianglePrism 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, perimeter and volume with 2 digit after decimal point. Hint: ‘{0:.2f}’.format(x)
Hints:
-You can use math library (import math).
– In this lab, we use equilateral triangle which all three sides have the same length.
Area of triangle =ππππ
Perimeter of triangle = 3β ππππ
Area of rectangle = π€πππ‘β β βπππβπ‘
Perimeter of rectangle = 2β (π€πππ‘β +βπππβπ‘)
Area of square = ππππ2
Perimeter of square = 4β ππππ
Area of SquarePyramid = area of square + 3* (area of triangle)
Area of TrianglePrism = 2*(area of triangle) + 3* (area of rectangle)
Volume of TrianglePrism = (area of triangle) * height
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
Submission:
1- Name your Shapes.py file as <student_id>.py; replace <student_id> using your student id number.
2- Upload your python file using the interface provided in e-kampΓΌs course page.
Good luck.
2




Reviews
There are no reviews yet.