Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

We write computer programs to help us quickly make sense of, and make choices with, data. Those choices can fall into different categories. Sometimes those

We write computer programs to help us quickly make sense of, and make choices with, data. Those choices can fall into different categories. Sometimes those choices depend on whether the data fits some valid criteria, as in our recitation example with the train cars. Sometimes those choices are deciding between different categories, such as our homework assignment with the Widgets. Sometimes those choices are between different calculations that need to be done in different circumstances, such as in our recitation activity with postage rates or our lecture example with geometric calculations. All of these examples have something in common. They all require us to communicate logical rules to the computer, and create branches of computer code that will run under different circumstances.

This project will require you to write a computer program that branches in two different places (i.e. has two different sets of conditional statements). The first will be to determine if the input data is formatted in an acceptable way. The second is to make the correct calculation, depending on the values of the data itself.

image text in transcribed

image text in transcribed

image text in transcribedimage text in transcribed

Problem Statement Polygons are geometric shapes characterized by having a finite number of sides occurring in a 2D plane. They are the most familiar shapes to us (triangles, rectangles, etc). Some kinds of polygons have very simple rules for calculating the area of the shape and angles between sides. Others are very complicated. We polygons for innumerable applications. One crucial use of polygons is in computer visualization. To draw 3D shapes in animation and video games, we sometimes use many, many 2D polygons connected with each other at different angles. If the polygons are small enough, the human eye does not see them, and instead sees a more seamless 3D shape. Diminishing returns - 15 years ago even doubling the amount of triangles resulted in a much better mesh. Now, multiplying the amount by 10 hardly does. Image taken from https://wccftech.com/difference-polygon-count-resolution-xbox-one/ In this project, you will write a function that takes in inputs that can describe polygons with different numbers of sides. The function will return a logical variable letting the user know whether the data was formatted correctly. If the data was formatted correctly, it will calculate the area of that shape. Otherwise, it will return a 0 . Parameters Your function will be able to calculate the area of the following polygons: - Right triangles - Rectangles - Regular polygons, which are polygons with any number of equal-length sides, with equal angles between all sides 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 sideLengths can be either a scalar double (a single number) or an array with two numbers. numsides must always contain an integer number with a value 3 or larger. Additionally, sideLengths can only be an array when numSides is equal to 3 or 4 . The outputs will be: - format - a logical variable that is true when your inputs are formatted correctly, and false otherwise - area - the area of your polygon. This will be 0 if format is false. Procedure - Part 1, Formatting First, your program should determine if the inputs are formatted properly. The rules are as follows: - 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, rema inder 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. Procedure - Part 2, Area Calculations You will have 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. Please use the methods described on the website linked here to calculate the area of the polygon. Testing Once you are done writing your function, you should test with various different parameters. Examples of how you might call your function, assuming a function name of polygonArea, are as follows: [ format1, area1 ]= polygonArea (3,[45]); \&Valid right triangle [ format2, area ]= polygonArea (4,[10,8.5]); oValid rectangle [ format 3 , area3 ]= polygonArea (8,4);V Vilid octagon [ format 4, area 4]= polygonArea (6,[34]);% invalid [ format5, area5 ]= polygonArea (3,[123]); \% Invalid [ format 6, area ]= polygonArea (14.5,3);; Invalid These are just examples. Please make sure all branches and aspects of your program are correct through additional tests

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Strategic Database Technology Management For The Year 2000

Authors: Alan Simon

1st Edition

155860264X, 978-1558602649

Students also viewed these Databases questions