Question

In: Computer Science

Assume there is a function called frustumArea that has three input arguments and returns the area...

Assume there is a function called frustumArea that has three input arguments and returns the area of a frustum: area = frustumArea( height, majRadius, minRadius ). When the major and minor radii of a frustum are equal, the frustum is a cylinder. Write a new function named cylinderArea that uses the frustumArea function to compute and return the area of a cylinder. Do this for both Python and Matlab.

Solutions

Expert Solution

####below is the python code

# while pasting indentations\tabs may get disturbed, please refer pic for correct tabs

import math
def frustumArea( height, majRadius, minRadius ):
r1=majRadius;
r2=minRadius;
h=height;
area= math.pi*(r1**2+ r2**2+(r1+r2)*((r1-r2)**2+h**2)**0.5)
return area
  
def cylinderArea(height,radius):
area=frustumArea(height,radius,radius)
return area

print(cylinderArea(1,1))
print(frustumArea(1,1,1))

  

%%%%%%%%below is the matlab code


function area= frustumArea( height, majRadius, minRadius )
r1=majRadius;
r2=minRadius;
h=height;
area= pi*(r1^2+ r2^2+(r1+r2)*((r1-r2)^2+h^2)^0.5);
end
  
function area=cylinderArea(height,radius)
area=frustumArea(height,radius,radius);
end

cylinderArea(1,1)
frustumArea(1,1,1)

  


Related Solutions

In Python Create a function called ℎ?????. The function has as arguments a list called ??????...
In Python Create a function called ℎ?????. The function has as arguments a list called ?????? and a list call center. • List ?????? contains lists that represent points. o For example, if ?????? = [[4,2], [3,2], [6,1]], the list [4,2] represents the point with coordinate ? at 4 and y coordinate at 2, and so on for the other lists. Assume that all lists within points contain two numbers (that is, they have x, y coordinates). • List ??????...
Write a function called draw_card. It takes no arguments and returns an integer representing the value...
Write a function called draw_card. It takes no arguments and returns an integer representing the value of a blackjack card drawn from a deck. Get a random integer in the range 1 to 13, inclusive. If the integer is a 1, print "Ace is drawn" and return 1. If the integer is between 2 and 10, call it x, print "<x> is drawn" and return x (print the number, not the string literal "<x>"). If the number is 11, 12,...
Write a C function called weighted_digit_sum that takes a single integer as input, and returns a...
Write a C function called weighted_digit_sum that takes a single integer as input, and returns a weighted sum of that numbers digits. The last digit of the number (the ones digit) has a weight of 1, so should be added to the sum "as is". The second from last digit (the tens digit) has a weight of 2, and so should be multiplied by 2 then added to the sum. The third from last digit should be multiplied by 1...
Write a function called alternate that takes two positive integers, n and m, as input arguments...
Write a function called alternate that takes two positive integers, n and m, as input arguments (the function does not have to check the format of the input) and returns one matrix as an output argument. Each element of the n-by-m output matrix for which the sum of its indices is even is 1. All other elements are zero. For example, here is an example run: >> alternate(4,5) ans = 1 0 1 0 1 0 1 0 1 0...
C++ write a function called divideBy that takes two integers as its input and returns the...
C++ write a function called divideBy that takes two integers as its input and returns the remainder. If the divisor is 0, the function should return -1, else it should return the remainder to the calling function.
1) Write a single function CalcArea( ) that has no input/output arguments. Inside the function, you...
1) Write a single function CalcArea( ) that has no input/output arguments. Inside the function, you will first print a “menu” listing 2 items: “rectangle”, “circle”.  It prompts the user to choose an option, and then asks the user to enter the required parameters for calculating the area (i.e., the width and length of a rectangle, the radius of a circle) and then prints its area.  The script simply prints an error message for an incorrect option.   Here are two examples of...
Write python 3 code to define a function that uses three arguments, and returns a result....
Write python 3 code to define a function that uses three arguments, and returns a result. The function returns True if the first argument is more than or equal to the second argument and less than or equal to the third argument, otherwise it returns False. Write a python 3 code for function main, that does the following: creates a variable and assign it the value True. uses a while loop which runs as long as the variable of the...
Function named FunCount takes three arguments- C, an integer representing the count of elements in input...
Function named FunCount takes three arguments- C, an integer representing the count of elements in input list IP- input list of positive integers. Item- an integer value. Function FunCount returns an integer representing the count of all the elements of List that are equal to the given integer value Key. Example: Don’t take these values in program, take all inputs from user C = 9, IP= [1,1,4,2,2,3,4,1,2], Item = 2 function will return 3 IN C PROGRAMMING
Function named FunCount takes three arguments- C, an integer representing the count of elements in input...
Function named FunCount takes three arguments- C, an integer representing the count of elements in input list IP- input list of positive integers. Item- an integer value. Function FunCount returns an integer representing the count of all the elements of List that are equal to the given integer value Key. Example: Don’t take these values in program, take all inputs from user C = 9, IP= [1,1,4,2,2,3,4,1,2], Item = 2 function will return 3
2 Write a function named equivalentArrays that has two array arguments and returns 1 if the...
2 Write a function named equivalentArrays that has two array arguments and returns 1 if the two arrays contain the same values (but not necessarily in the same order), otherwise it returns 0. Your solution must not sort either array or a copy of either array! Also you must not modify either array, i.e., the values in the arrays upon return from the function must be the same as when the function was called. Note that the arrays do not...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT