The Function will be able to calculate the area of the following polygons: Right triangles, Rectangles, and regular polygons.
It will do so by taking the following inputs:
- numSides – a double of the number of sides the polygon has
- sideLengths – a double of the length or lengths of sides of the polygon
The program should determine if the inputs are formatted properly. The rules are:
- numSides must be a positive integer number with values greater than or equal to 3.
- When numSides is 3 or 4, sideLengths can either be a scalar or an array with two values.
- When numSides is greater than 4, sideLengths must be a scalar.
To determine if a number is an integer, you can use the rem function. rem returns the remainder of whole
number division. It has the following syntax: remainder = rem(numerator, denominator);
Where remainder is the remainder of numerator/denominator. To use this to find whether a
number is an integer, use rem in the following way: remainder = rem(number, 1);
When number is an integer, remainder will be 0. Otherwise, remainder will be nonzero.
To determine how many numbers are contained in an array, use the length function. The length
function has the following syntax: N = length(arrayName);
Where N is the number of elements (i.e. the number of numbers) contained in array arrayName.
3 different ways of calculating area of your polygon.
- When numSides is 3 and sideLengths is an array with two numbers, you will calculate the
area of a right triangle, where the two numbers inside of sideLengths are the sides of the
triangle that are not the hypotenuse.
When numSides is 4 and sideLengths is an array with two numbers, you will calculate the
area of a rectangle where the two numbers inside of sideLengths are your two different
lengths for the sides of your rectangle.
In all other valid cases, the scalar sideLengths is the length of all sides of your polygon, no
matter what numSides is.
As no language is mentioned so I used Matlab
answer is
Trending nowThis is a popular solution!
Step by stepSolved in 5 steps with 2 images
- 5arrow_forwardFinish the function below that takes in the length of the two parallel sides of a trapezoid a and b, which are separated by a distance h, and returns its area. In [ ]: defarea_of_trapezoid(a,b,h):# YOUR CODE HEREraiseNotImplementedError() In [ ]: """Check that area_of_triangle returns the correct output for several inputs""" assert abs(area_of_trapezoid(3,3, 5) - 15) <=.1 assert abs(area_of_trapezoid(3,4, 5) - 17.5)arrow_forwardChess bishop moves diagonally in any number of squares. Given two different squares of the chessboard, determine whether a bishop can go from the first square to the second one in a single move. The program receives four numbers from 1 to 8 each specifying the column and the row number, first two - for the first square, and the last two - for the second square. The program should output YES if a bishop can go from the first square to the second one in a single move or NO otherwise. Define a function called bishop_move # Example input ```4455``` # Example output ```YES``` #arrow_forward
- ***IN PSUEDOCODE ONLY - not a real programming language!!*** Question:A prime number is a number that is only evenly divisible by itself and 1. For example, the number 5 is prime because it can only be evenly divided by 1 and 5. The number 6, however, is not prime because it can be divided evenly by 1, 2, 3, and 6. Design a Boolean function called isPrime, that accepts an integer as an argument and returns True if the argument is a prime number, or False otherwise. Use the function in a program that prompts the user to enter a number and then displays a message indicating whether the number is prime. The following modules should be written: - getNumber, that accepts a Ref to an integer, prompts the user to enter a number, and accepts that input - isPrime, that accepts an integer as an argument and returns True if the argument is a prime number, or False otherwise - showPrime, that accepts an integer as an argument , calls isPrime, and displays a message indicating whether the…arrow_forwardDescription Xiao Zhang is often distressed because there are too many things to arrange. Now he has n tasks at hand, and each task has a starting times, and an ending time e;. To complete a task, he must do it from the starting time to the ending time, and Xiao Zhang can only perform one task at the same time. Xiao Zhang wants to know how many tasks he can accomplish at most. Input The first line is an integer n (1sns300000), indicating the number of tasks Xiao Zhang has at hand. In the next n lines, each line contains two integers s₁, e¡ (1≤s;arrow_forwardA polygon is convex if it contains any line segments that connects two points of the polygon. Write a program that prompts the user to enter the number of points in a convex polygon, enter the points clockwise, then displays the area of the polygon. For the formula for computing the area of a polygon,arrow_forward4.Rohan bought a gallon of milk with an original price of $4.25; today he gets a 15% discount before a 5% tax; display the final price of the milk.5.This function is named compound_interest, takes these arguments p r n t; compute and return a for displaya = p (1 + r/n) nt6.This function is named annuities, takes these arguments r i n; compute and return s for displays = r ((1 + i)^(n + 1))/i - rarrow_forwardTransient PopulationPopulations are affected by the birth and death rate, as well as the number of people who move in and out each year. The birth rate is the percentage increase of the population due to births and the death rate is the percentage decrease of the population due to deaths. Write a program that displays the size of a population for any number of years. The program should ask for the following data: The starting size of a population P The annual birth rate (as a percentage of the population expressed as a fraction in decimal form)B The annual death rate (as a percentage of the population expressed as a fraction in decimal form)D The average annual number of people who have arrived A The average annual number of people who have moved away M The number of years to display nYears Write a function that calculates the size of the population after a year. To calculate the new population after one year, this function should use the formulaN = P + BP - DP + A - Mwhere N is the…arrow_forwardA(n) operator performs division, but instead of returning the quotient it returns theremainder.a. modulusb. multiplicationc. exponentd. operandarrow_forwardarrow_back_iosarrow_forward_ios
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education