Send Close Add comments: (status displays here)
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.
A6: Asmt#6: Integration using trapezoids

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. Integration using trapezoids

6. Requirements
Write a C program to do the following.

The first integer value (not prompted nor echoed) determines how the output is displayed, in the manner of previous works. For more information, see Debugging via output .

You are given the following data as a list. All values are floating point approximations. You are to compute and output the following. If the requirements are unclear in any way, use any provided input and output to resolve the discrepancy.

See Guidelines for C programs .

7. Coding notes
The following coding examples and/or notes may be of use for this requirement.

To get started, you should be familiar with each program in the following pages.
Use the "+=" or "-=" (or similar) operators when they can be used. For example incrementing a counter or adding to a sum. It is best to not use the "++" or "--" operators except within for loops (where for loops are the best choice).
Use a while loop where a while loop is best. There is a major deduction for using a for loop when not appropriate. A for loop is best for going 0 to n-1 or from 1 to n or the other way.
All code should be written in single-entry single-exit style. This means no continue or break statements in loops and all return statements need to be at the end of a function (as in the main function).
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.
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.

8. Domain knowledge
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: In addition to specific domain knowledge, 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 integration.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.


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. Pseudo-code
The pseudo-code should be indented just like code.

Note: One should never put raw tabs in the middle of a line since they can appear different in different output media.

So, if one copy-pastes the pseudo-code, one can add singe line comments to each line (which gets cumbersome and inhibits readability) and then convert tabs to spaces, or one can use multi-line comments as in the following (no tab change necessary).
/// pseudo-code: /* (paste pseudo-code here) */

Remember to remove parentheses in the header comments and supply your own information.

14. Notes
Note: Echoing input and computations along the way are not part of the pseudo-code (unless important to the method).

Note: An order of the y value pairs is not specified. In the code, an order needs to be used - usually the easiest order to use. But the pseudo-code does not specify that order (unless important to the method).

15. Scoring rubric

CS 101 - A6 : Asmt#6: Integration using trapezoids 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:


16. End of page