Got it! This site uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website.nbsp; Note: This appears on each machine/browser from which this site is accessed.
You are not logged in. Go to Login page. You need to login before you can view more content. (content omitted that requires login)
5. Polygons with arrays
6. Requirements
Write a C program to do the following.
The first number in the data is a show parameter that should be handled as done in previous works.
Write a C program to read in units and the number of points that follow. The points represent a polygon where the last point is omitted and is the same as the first point. Determine the area of the complete polygon.
Also, determine and output the perimeter of the polygon.
The first data point is the base of every triangle.
Each vector in a polygon, from point to point, is called a leg of the polygon.
The last leg is inferred as the first point. It is needed for the area of the polygon and the for the perimeter of the polygon (if required for this work).
In this work, we are not interested in whether the any individual or overall triangle area is positive or negative.
For this program, you are to separate all declarations, input, processing, and output. This means using arrays. The maximum number of data points is 100. Use a for loop for input for any counter or header loops. Use a while loop for input for any trailer or endfile loops. Use a for loop for any processing or output loops if the range goes from 0 to n-1 or from 1 to n.
If the requirements are unclear in any way, use any provided input and output to resolve the discrepancy.
Domain knowledge is the background knowledge that is useful in solving a problem, designing a solution, implementing the solution, etc. The following domain knowledge may be useful for this requirement.
Note that in a previous assignment, A5, the triangle area was actually a parallelogram of two such triangles. A factor of 0.5 has been added to the page for the area of a triangle and the updated formula should be used here.
Note: In addition to specific domain knowledge, you should be familiar with all concepts covered to this point in the course.
8. Coding notes
The following coding examples and/or notes may be of use for this requirement.
The first point of every triangle is the first point of the data as (x0,y0). Triangles that contribute to the area are then triangles of pairs of adjacent points not counting the first (base) point.
For all works, there is a major deduction for submitting a program that does not terminate. For example, a program that contains an infinite loop.
There is a major deduction for statement repetition. Look at your final code. If there is repetition and we have covered a way to avoid it, remove it.
Make all necessary assumptions. Make no unnecessary assumptions.
In addition to specific coding examples, you should be familiar with all concepts covered to this point in the course.
9. Starter program
You are provided with the following starter program in file polygons2.c.
Do not remove any comment that starts with three slashes.
Here is the C code.
You are to fill in the missing parts of the program according to the work requirements (see above).
In the comments at the top, you are to fill in the author (your name), help received (person and type of help), and pseudo-code parts which are not in the solution (usually provided, but you need to add them). Remove the parentheses too.
10. Possible solution
Begin solution
Here is a possible solution to the above problem. Note: Once a solution is provided, or the day before the next class, further submissions for this work receive no credit.
End solution
11. Examples of input and output
Here are some examples of input and output for the above program code.
Here is an example input from file input1.txt.
For the above example input, here is the expected output.
Here is an example input from file input2.txt.
For the above example input, here is the expected output.
Here is an example input from file input3.txt.
For the above example input, here is the expected output.
Here is an example input from file input4.txt.
For the above example input, here is the expected output.
12. Pseudo-code
Pseudo-code is a "false" code. It is not really code, but a simplified English explanation that is somewhat similar to code. Pseudo-code is useful for understanding what a program does. For this work, the following can be used as the pseudo-code. Adjust if needed.
Note: Only some essential details are included. Some details, such as input, prompts, input echo, and obviously needed output are omitted.
The best way to copy-paste pseudo-code that includes indented code (e.g., with tabs) is as follows (in the code file) using a multi-line comment.
/*
(pasted pseudo-code here)
*/
13. Processing
It is best to separate input, processing and output into different parts of a program.
Since C has limited string handling capabilities (they can get complex), some processing involving string processing is moved to the output section of the code.
14. Scoring rubric
CS 101 - A8 : Asmt#8: Polygon area with arrays
Your grade: _ / 40
[LATE] Late or redo penalty: _ / -40
[SUBMIT] Not submitted properly: _ / -40
[RUN] Does not compile, run-time crash, etc.: _ / -40
[ETHICS] Ethical issues: _ / -40
[HEADER] Header comments not done as required: _ / -20
[STYLE] Inconsistant style or indentation: _ / -20
[CODE] Code guidelines ignored: _ / -40
[XCODE] Code used not yet covered: _ / -20
[REMOVED] Triple slash comments removed: _ / -20
[ADDED] Code added outside of marked areas: _ / -20
[OUTPUT] Functional requirements met: _ / 40
[CREDIT] Extra credit: _ / +8
Comments: