import math
THRESHOLD = 0.1
passed = 0
tests = 0
def main():
test_get_rectangle_area()
test_get_average()
test_append()
test_distance()
test_get_shipping_cost()
def test_get_rectangle_area():
result = get_rectangle_area(0,0)
expected = 0
print_test("get_rectangle_area", abs(expected -
result) < THRESHOLD)
result = get_rectangle_area(3,4)
expected = 12
print_test("get_rectangle_area", abs(expected -
result) < THRESHOLD)
result = get_rectangle_area(5,5)
expected = 25
print_test("get_rectangle_area", abs(expected -
result) < THRESHOLD)
def get_rectangle_area(l,b):
return l*b
def test_get_average():
result = get_average(0,0,0)
expected = 0
print_test("get_average", abs(expected - result) <
THRESHOLD)
result = get_average(1,1,1)
expected = 1
print_test("get_average", abs(expected - result) <
THRESHOLD)
result = get_average(5,6,-11)
expected = 0
print_test("get_average", abs(expected - result) <
THRESHOLD)
def get_average(a,b,c):
return (a+b+c)/3
def test_append():
result = append("","")
print_test("append", result == "")
result = append("hello there","you")
print_test("append", result == "hello thereyou")
result = append("hi ","hi")
print_test("append", result == "hi hi")
def append(s,t):
return s+t
def test_distance():
result = distance(3,0,0,4)
print_test("distance", abs(5-result) <
THRESHOLD)
result = distance(0,0,6,8)
print_test("distance", abs(10-result) <
THRESHOLD)
result = distance(3,4,10,4)
print_test("distance", abs(7-result) <
THRESHOLD)
def distance(x1,y1,x2,y2):
return math.sqrt((x2-x1)**2 + (y2-y1)**2)
def test_get_shipping_cost():
std_len = 28.2
std_wid = 10
wt03 = 0.03
result =
get_shipping_cost(wt03,std_len,std_wid)
expected = 1.05
print_test("get_shipping_cost", abs(expected - result)
< THRESHOLD)
result = get_shipping_cost(0.05,10,20)
expected = 1.45
print_test("get_shipping_cost", abs(expected - result)
< THRESHOLD)
result = get_shipping_cost(0.2,20,20)
expected = 2.4
print_test("get_shipping_cost", abs(expected - result)
< THRESHOLD)
def get_shipping_cost(wt,l,b):
area = get_rectangle_area(l,b)
if area <= 282 and wt <= 0.05:
return 1.05 + 20*(wt-0.03)
else:
return 1.9 + 5*(wt-0.1)
def print_test(test_name, expression):
global tests
global passed
tests += 1
if(expression):
print(test_name + ': passed')
passed += 1
else:
print(test_name + ': failes')
if __name__ == '__main__':
main()
Designing functions Reminder: When designing functions, follow the given steps to reinforce good software development p...
2. Write a program with three functions that will be called from the main function The functions will calculate the volume, area and perimeter of a cuboid. You should able to pass three parameters such as length, width and height, and a function will return area, another will return volume and final one will return perimeter. Define all your variables in floating point numbers 3. Modify the problem#2 to calculate the volume, area and perimeter in a sing le function...
Project Objectives: To develop ability to write void and value returning methods and to call them -- Introduction: Methods are commonly used to break a problem down into small manageable pieces. A large task can be broken down into smaller tasks (methods) that contain the details of how to complete that small task. The larger problem is then solved by implementing the smaller tasks (calling the methods) in the correct order. This also allows for efficiencies, since the method can...
Note: The order that these functions are listed, do not reflect the order that they should be called. Your program must be fully functional. Submit all .cpp, input and output files for grading. Write a complete program that uses the functions listed below. Except for the printOdd function, main should print the results after each function call to a file. Be sure to declare all necessary variables to properly call each function. Pay attention to the order of your function...
Project 1 – Classes and Top-down Design Overview Software development projects using the object-oriented approach involve breaking the problem down into multiple classes that can be tied together into a single solution. In this project, you are given the task of writing some classes that would work together for providing a solution to a problem involving some basic computations. Learning Objectives The focus of this assignment is on the following learning objectives: • Be able to identify the contents of...
OpenSooq Assignment - Software Engineer Given two strings input of printable text, a and b . let the edit distance between a and b is least number of operations needed to transform a to b, write php code that calculate edit distance using: 1. hamming distance that only have substitute operations (ex. substitute letter X with letter Y). 2. Levenshtein distance: that have 3 possible operators: insert, delete or substitution operations the function should consider all possibilities but should not...
C++...please help follow exact steps output needs to be the exact same Create a class called Rational for performing arithmetic with fractions. Write a program to test your class. Use integer variables to represent the private data of the elass the numerator and the denominator. Provide a constructor that enables an object of this class to be initialized when it's declared. The constructor should contain default values in case no initializers are provided and should store the fraction in reduced...
C++ Question 1) Consider a class Point that models a 2-D point with x and y coordinates. Define the class point that should have the following Private data members x and y (of type int), with default values of 0 A constant ID of type int A private static integer data member named numOfPoints This data member should be o Incremented whenever a new point object is created. o Decremented whenever a point object is destructed. A default constructor An...
Lab 7: Void and Value-Returning Functions Lab 7: Void and Value-returning functions Due date: 11/6/19 Problem: Write a C++ program that calculates the areas of a rectangle and of an ellipse. Area = base * height Area = π * radius a * radius b Note: all images extracted from http://www.mathsisfun.com/area-calculation-tool.html ------------------------------------------------------------------------------------------------------------------------ Your task: implement in C++ the algorithm solution shown below. ------------------------------------------------------------------------------------------------------------------------ Part A (79...