Skip to content
Physics and Astronomy
Home Our Teaching Resources C programming assess1-2017.html
Back to top

Assessment 1

This assessment forms 13% of your module mark. The objective is to test your ability to do simple arithmetic and do simple sanity-checking of users' input.

Remember: you will make the best progress by doing the tasks in stages, making sure each stage works correctly before starting the next one. Be sure to ask me for help if you get stuck.

Be sure to read the expectations document.

1. A grand day out

35% of the assessment mark.

Write a program to solve the following problems connected to the cost of a coach trip. As always, remember not to have numbers such as "159" scattered through the code but to use variables with sensible names. NB: the numbers below are indicative; you must write a program that gives the correct results whatever the number of students and instructors.

Tip: To print a floating-point number to two decimal places write:

  printf("%.2f\n", x);
(Note: there is a decimal point after the percent sign, ie it is "percent point two f")

A computing class has 159 students and eight instructors. They wish to take a trip to the National Museum of Computing at Bletchley Park. They can hire 16-seater minbuses for £81 each plus VAT at 20% (i.e. you must add 20% to £81 to get the total cost).

  1. Calculate how many minbuses you will need and much will it cost to hire them.
  2. You estimate each van will do 31 miles per gallon and diesel costs £1.17 per litre. Use the internet or similar to find the distance from Exeter to Bletchley Park and the number of litres in a gallon and have your program use these numbers to calculate the estimated fuel cost.
  3. Calculate the total cost of the trip and the cost per person.
  4. Calculate the total amount of travelling expenses to be claimed by the instructors. (That is, the total for all the instructors, not the amount per instructor.)

Output required

Just the output from the program, for example:

We require 6 vans which will cost 13212.87
The diesel will cost 123.56
The total cost is 13336.43

2. The sine rule

65% of the assessment mark.

This assessment requires some basic checking of user input. To do this you may either edit the program to manually change the values of the variables or use scanf() to read them in from the keyboard.

To read in one double use: scanf("%lg", &x);
To read in two use scanf("%lg %lg", &x, &y); Do not put anything else inside the format string!

Revise the sine rule.

  1. Write a program to read in two angles, in radians, (or manually set the values of the variables and change them for each case) and the length of the side between them. As always, use sensible variable names.
  2. Check these values for invalid values (ie those for which could not be part of a triangle) and print a helpful message for each class of error. (If you have chosen to use scanf() you do not need to worry about the case where the user entered something that was not a number.) NB: the compiler defines the constant M_PI to be the value of π.
  3. Calculate the other angle and the other two sides.
  4. Print out the sum of the three angles. (Why do you think we ask you to do this?)
  5. The area of the triangle can calculated from one angle and the length of the two sides that form it. Print out the area of the triangle calculated three times, once for each angle. (Why do you think we ask you to do this?)

Output required

The output from your program runs should show some warnings from each class of non-valid input and one working case.

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:

int main() {
  // Your code here 

   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


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