Physics and Astronomy
Home Our Teaching Resources C programming assess2-2017.html

# Assessment 2 (2017)

This assessment forms part of your module mark. The primary objectives of this assignment are to demonstrate the ability to :

1. Write functions.
2. Pass arrays to functions (that is to say, to pass the addresses of arrays to functions).

As mentioned below, you may re-use some of your answer to the first assessment if you wish, the main aims here are the two listed above.

Remember: you will make the best progress by doing the tasks in stages, making sure each stage works correctly before starting the next one. Read the Notes and Tips at the bottom before you start and be sure to ask me for help if you get stuck.

Before starting you should look at our expectations page and the module's policy on copying and acceptable and unacceptable collaboration in assessments, which in turn refer to the Physics policy on cheating and plagiarism.

## Solving a triangle

Your task is to write a program that can find the unknown sides and angles of a triangle given different combinations of input. You may re-use you sine rule code from the first assessment (we suggest taking a copy of the project and editing the copy).

1. Write a main() function that declares two arrays of three doubles, one for the sides and one for the angles of a triangle. Print a simple menu that gives the choice of entering:

1. Three sides
2. Two sides and the included angle
3. One side and its two adjacent angles
4. Or an option to quit.
2. For each of the first three possibilities have main() call a function which takes (the addresses of) the two arrays as arguments and:
1. Reads the appropriate numbers from the keyboard.
2. Sanity-checks them, and if they are wrong prints a helpful message and returns zero.
3. Otherwise calculates the missing values and returns one.

As always, do one of these at a time.

3. Once you have written the first of these, enclose the code inside a loop so that the loop only exits when the triangle input was correct (or the user chooses to quit).
4. As with the previous sine rule assessment the area of the triangle can be calculated from one angle and the lengths of the two sides that form it. Print out the area of the triangle calculated three times, once for each angle.
5. Finally, run the program three times, once for each option, and use the output from the first for the second two, manually checking that all three describe the same triangle. Expect to find mistakes!

### Notes and tips

#### Error checking the input

There are several checks to be made of the users input (for example "are any of the sides or angles zero or negative?"). These can look rather long but they are very simple and do not add much to the complexity of the code. It's just a question of asking "what are all the ways the user can enter invalid data" and checking for each possibilty.

#### Numbering the sides and angles

I suggest adopting the convention that angle N is opposite side N, (eg angle 1 is opposite side 1) in much the way that when writing out the formula if we call the sides a, b and c and the angles A, B and C then a is opposite A, etc.

### Output required

The output from your program runs should show some warnings from one or classes of non-valid input followed and the three working cases agreeing with each other.

## To hand in

For all assessments We require one ".c" text file for each task, uploaded to ELE. Do not upload a PDF, word-processor file etc. For each task you should hand in the program and some output pasted output into a comment at the end of your program:

```#include<stdio.h>
int main() {
// Your code here
}

/*
OUTPUT
Some output here
*/
```

The output should be fairly brief but enough to show that your code works. Basically we are looking for the minimum amount necessary to show your program worked for each separate class of the problem, including error checking where appropriate, rather than several similar runs.

### To copy and paste from the output terminal

The Windows output console has an "unusual" copy and paste mechanism:

1. Right-click in the console window and select "Select All".
2. Press <Return>.

You can now paste into Code::Blocks using Control-V