Skip to content
School of Physics
Home Our Teaching Resources C programming exc.html
Back to top

PHY3134 Exercise 3

This is an assessed exercise and should be handed in next week for quick feedback. It will be returned the following week.

Objectives

  1. To pass pointers-to-structures to functions to enable the function to change the members of the original structure.
  2. To practice for ourselves the "data-orientated" analysis introduced in week 1.

Overview of the task

We ask you to write a program that includes a structure to represent a triangle. The user will type in either the lengths of two of the sides and the angle between them, or the length of one of the sides and the angles it makes with each of the other two sides. The program will then calculate the unknown sides and angles and the area of the triangle.

You may want to revise the sine rule, the cosine rule and how to calculate the area of a triangle.

The exercise

Analysis (25%)

This should take much less than 25% of the time so it's worth doing it well!

Download the analysis document and fill it in. Feel free to add any other issues you consider to be important. We are looking for bullet points, not paragraphs of text, remember you will need to be able to glance at it whilst you are programming.

You will be assessed not only for the analysis itself but also how it is reflected in your program.

Program and testing (75%)

Define a suitable structure for a triangle. Make it clear which angle corresponds to which pair of sides.

Allow the user to enter either the lengths of two of the sides and the angle between them, or the length of one of the sides and the angles it makes with each of the other two sides. Give them the choice and do some suitable sanity-checks.

Then calculate the unknown sides and angles and the area of the triangle. Use functions for self-contained tasks that make sense from a (mathematical) description of the problem.

Try out the checks you described in the analysis document.

Hand in

  • The filled-in analysis document.
  • The program.
  • The terminal "conversation" (printed two-per page if possible).

When things go wrong

If you've gone 15 minutes without making progress (outside of lab time) ask me for help, either in person or by email. Always show me the complete, latest code.
                                                                                                                                                                                                                                                                       

Validate   Link-check © Copyright & disclaimer Share
Back to top