** Using Python 3 **
Write a Box class whose init method takes three parameters and uses them to initialize the length, width and height of a Box. It should also have a method named volume that returns the volume of the Box. Write a function named box_sort (not part of the Box class) that uses insertion sort to sort a list of Boxes from greatest volume to least volume.
code:
class Box:
def __init__(self,l,w,h):
self.length = l
self.width = w
self.height = h
def getVolume(self):
return self.length * self.width * self.height
def box_sort(boxes):
#traverse through each box object
for i in range(1, len(boxes)):
box = boxes[i]
#move the boxes from 0 to i-1 index which have greater
#volume than the current box
j = i-1
while j >=0 and box.getVolume() > boxes[j].getVolume() :
boxes[j+1] = boxes[j]
j -= 1
boxes[j+1] = box
return boxes
def main():
#create boxes and sort them
box1 = Box(4,6,2)
box2 = Box(1,2,3)
box3 = Box(3,4,6)
boxes = box_sort([box1,box2,box3])
for i in range(len(boxes)):
print(boxes[i].getVolume())
main()
** Using Python 3 ** Write a Box class whose init method takes three parameters and...
Use Python 3.7 to Write a function called volume_of_box() that takes three parameters (the length, width, and height of the box) and returns the volume of the box. Then, use that function in a program which prompts the user to enter the dimensions of a box and returns the volume. Your program should include input validation to ensure that the values entered are positive and should be able to accept float values. Many thanks for all your time and effort...
1) Translate the following equation into a Python assignment statement 2) Write Python code that prints PLUS, MINUS, O ZERO, depending on the value stored in a variable named N. 3) What is printed by: 3 - 1 while 5: while 10 Print ) Page 1 of 9 4) Write a Python while loop that reads in integers until the user enters a negative number, then prints the sum of the numbers. 1-2 of 9 4) Write a Python while...
Python Write a function (named largest_of_three) that takes three parameters and returns the largest. You can assume the parameters are either floats or ints.
Write a class named HalfOpenCylinder that has two data members: a double for the height in inches and a double for the radius in inches. It should have a constructor that takes two parameters and uses them to initialize the data members. It should have a default constructor that initializes the height to 10 and the radius to 2. It should have a method named surfaceArea that returns the the surface area (in square inches) of a cylinder with that...
Python Implement a class named BubbleStringList. In this class implement a method called add, that when given a string, it adds it to an internal list object. You can use the list object from the standard python library for the internal list. Next, implement a sort method that uses a BubbleSort to sort the list when called. Create another class called MergeStringList, that implements the same methods but uses a Merge Sort as the sorting algorithm. Create another class called...
Write a class named Taxicab that has three private data members: one that holds the current x-coordinate, one that holds the current y-coordinate, and one that holds the odometer reading (the actual odometer distance driven by the Taxicab, not the Euclidean distance from its starting point). The class should have an init method that takes two parameters and uses them to initialize the coordinates, and also initializes the odometer to zero. The class should have get members for each data...
Write a function updateAges(names, ages) that takes as parameters a list of names of people whose birthday it is today and a dictionary named ages, with names as keys and ages as values, and increments the age of each person in the dictionary whose birthday is today.
WRITING METHODS 1. Implement a method named surface that accepts 3 integer parameters named width, length, and depth. It will return the total surface area (6 sides) of the rectangular box it represents. 2. Implement a method named rightTriangle that accepts 2 double arameters named sideA and hypotenuseB. The method will return the length of the third side. NOTE To test, you should put all of these methods into a ‘MyMethods’ class and then write an application that will instantiate...
help ASAP 3. Write a string C++ function named UnsignedPartialSum() that takes two string parameters and an int parameter. If both string parameters represent binary numbers and the int parameter is equal to a positive number less than or equal to the length of the longest string parameter, the function should return a binary string whose length is equal to two times the length of the maximum length of the two string parameters whose value is equal to the sum...
I need help asap, Python language 2) Write a class to represent a class to represent a Car and its passengers. Write a constructor that takes one additional parameter a number, the total seats in the car. The constructor should save this as a datamember and also initialize an additional datamember, a list, to keep track of the passengers in the car. Write method addRider that takes an additional parameter a string of the passenger to be added to the...