Starting from:

$24.99

CS104 Homework 10 Solution


1.  Please check the source code generate_random_number_file.py given. You can generate a file with a randomly generated integer on each line. Please use this file to create six files for n=10, n=100, n=1000, n=10000, n=100000, n=1000000. Implement the sorting algorihms for insertion sort, bubble sort, selection sort and, merge sort. The source code for these algorithms are given available on lecture slides. Sort the content of each file using these solutions, time the performance and create a table showing value of n, sorting algorithm and time it takes.
2.  Write an inheritance hierarchy for classes Quadrilateral, Trapezoid, Parallelogram,
Rectangle and Square. Use Quadrilateral as the super-class of the hierarchy. Create and use a Point class to represent the corners in each shape and has attributes that represent x and y coordinates of a point. Each quadrilateral will have four Point objects. Make the hierarchy as deep (i.e., as many levels) as possible. Specify the attrributes (fields and methods) for each class. Write a main program that instantiates objects of your classes and asserts each object’s area (except Quadrilateral) for some test cases.
3. (25 pts) Please implement a recursive method that takes a list as input, reverts the list and returns only the odd numbers. For example when you submit [1, 2, 3, 4] as input it shall return [3, 1], when you submit [3, 5, 9, 2, 3, 3, 4] it shall return [3, 3, 9, 5].
4. (25 pts) Please implement Team class that can be used as follows:
if __name__ == "__main__":
team_a = Team("Red Team", 6, 2, 2) team_b = Team("Blue Team", 5, 3, 2)
team_a.report() team_b.report()
The output of the report methods will be as follows:
Team: Red Team, Matches:6, Wins:2, Loses:2, Draws:2
Team: Blue Team, Matches:5, Wins:3, Loses:2, Draws:0

More products