Question
Sorry, for not posting the template you should use in the full question( use C programming Language) 1. Design a function called print_dog_years that takes
Sorry, for not posting the template you should use in the full question( use C programming Language)
1. Design a function called print_dog_years that takes a integer that represents a dogs age in human years and prints the dogs age in dog years. NOTE: a dogs age in dog years is seven times the number of human years it has lived. 2. Design a function called get_average that takes three integers numbers and returns the floating point average of the three numbers. 3. Design a function called get_rectangle_area that takes two floating point numbers that represent the length and width of the rectangle in cm. The function should return the area of that rectangle in cm squared.
4. Design a function called is_speeding that takes an integer representing the speed of a car in km/hr and an integer representing the speed limit in km/hr. Remember: the arguments MUST be in this order (speed before speed limit). If the speed of the car is not over the limit, the function should print: You are X km/hr below the legal limit where X is the difference between the speed of the car and the speed limit. If the speed of the car is over the limit, the function should print: Slow down! You are going Y km/hr where Y is the speed of the car 5. Design a function called get_max that takes as arguments three integers and returns the biggest of the three values. 6. Design a function called distance that takes four floating point numbers as arguments that represent 2 points and calculates and returns the distance between the two points. The formula for the distance between two points (x1,y1) and (x2,y2) is: d = ! (%)%+ (%)% The order of the arguments must be: the first 2 numbers are the x,y coordinate of one point and the second two numbers are the x,y coordinate of the second point. RECALL: including math.h gives you access to a square root function and a power function! The prototypes and descriptions of these functions are provided here for your reference: double pow(double x, double y) Returns x raised to the power of y. double sqrt(double x) Returns the square root of x. 7. Design a function called get_shipping_cost that takes the weight of the letter in kgs and the length and width of a letter in cm and calculates and returns the cost of shipping that letter. Each argument is a floating point number. This function must call the get_rectangle_area function. The rules for shipping cost calculations are as follows: If the letter is not bigger than the max area of 282cm2 and the weight is not more than 0.05kg it is a standard size letter and should be charged: $1.05 for the baserate + additional 2 cents per 1 gram of weight above 0.03kg Otherwise the letter is non-standard and should be charged: $1.90 for the baserate + additional 0.5 cents per 1 gram of weight above 0.1kg Example: If the package is 12 by 10 cm and weighs 0.24 kgs, it is a non-standard package and 140 grams over the 0.1kg non-standard weight limit, therefore the shipping cost should be approximately: 1.90 + 1.4 * 0.5 = 2.6
TEMPLATE
void print_dog_years(int age) { printf("dog is %d ", age); }
/* * purpose: calculates the floating point average of numbers n1, n2 and n3 * parameters: int n1, int n2, int n3 - numbers * returns: double - the average */ double get_average(int n1, int n2, int n3) { double avg = 0;
// you need to complete this!
return avg; }
/* * purpose: increments the test count * determines whether the given boolean expression result is true or false * increments the number of tests passed it is true * parameters: int expr - the result of a boolean expression */ void print_test(int expr) { test_count++; if (expr) { printf("passed "); tests_passed++; } else { printf("failed "); } printf(" "); }
void test_print_dog_years() { printf("testing print_dog_years ");
print_dog_years(0); print_dog_years(5); printf(" "); }
void test_get_average() { printf("testing get_average ");
double result, expected = 0;
result = get_average(0,0,0); expected = 0; printf("expected: %f, result: %f ", expected, result); print_test(fabs(expected-result) // fabs returns the absolute value of the given value
result = get_average(0,0,9); expected = 3.0; printf("expected: %f, result: %f ", expected, result); print_test(fabs(expected-result)
result = get_average(2, 4, 7); expected = 13/3.0; printf("expected: %f, result: %f ", expected, result); print_test(fabs(expected-result)
printf(" "); }
INSTRUCTION
We have got you started and provided you with the tests, prototype and implementation for print_dog_years and the tests, prototype and function stub (incomplete function) for get_average. This is intended to provide you with a template for testing your functions making use of the print_test function and two global variables included in the starter file. Take time to understand the code that is given so you can use this approach to test the remaining functions. You will notice the test_print_dog_years function does not use the print_test function as print_dog_years does not return a result and therefore the console output must be visually inspected for correctness by reading the console output to see if it is as expected. You will notice we do not use == to compare the result to the expected when they are floating point numbers as there is inaccuracy in floating point calculations. We therefore take the difference between the two values and ensure that this difference is very small (< THRESHOLD). You may use == with integer type comparisons (ie. if result to the expected are type int: result == expected) We encourage you to test your code before you submit. Ensure you test all possible paths of control through your function if it contains conditions as we will do this when we grade your submission.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started