coursework 1 - University of East Anglia

advertisement
University of East Anglia
School of Information Systems
SYS1CS20: Coursework Sheet 1
Notes about coursework for SYS1CS20:
There are 4 small pieces of coursework set fortnightly worth a total of 20% of the
course and one project set in week 8 worth 30%. Answers to the coursework should
consist of written solutions to the questions (preferably typed, print out of any source
code and a floppy disk with any projects/source code as required by the question.
Please put your work in some kind of file/binder and attach the disk sensibly. Also
make sure your name and registration number are on both the written work and the
disk. Work should be handed in on Fridays by 17:00, but if you think you will be
unable to meet a deadline come and see me or email me and I may make allowances.
It is better to hand in a partial attempt than hand in nothing and don't be afraid to ask
for help.
Coursework 1.
Hand in to the sys general office by 17:00 Friday 11th Feb. Source code is a sufficient
solution for question 1 (please print out the code in addition to handing in a floppy)
but question 2 requires a brief written solution in addition to the source code.
1. Create a CodeWarrior project on your floppy disk and add a file called
coursework1.cpp to the project. Declare the following variables in the main function
integers
a, b, c and d
doubles
w, x, y and z
Initialise the variables to the following values
a=21, b=9, c=5, w=22.0, x=5.5, y=6.5
Write code to perform the following calculations storing and printing out the results to
the screen.
i.
d=a/b
ii. d=a%b
iii. z=w/x
iv. d=a+(b/c)
v.
d=a+(b/c) - (b*c)
vi.
d=((b+a)/c)-a-b
vii.
z=(w/(y+x))*x
(see seminar sheet 1, question 4)
2. A shopkeeper is having trouble with metric measurements but is required by law to
display quantities in kilograms. He needs a program to convert kilograms to pounds.
Follow the 4-step development method to design a solution to this problem and
implement your solution (create a new file for the problem called convert.cpp but
don't create a new project). Use a constant for conversion of 1 kilogram equals 2.2
pounds. Include some test results in your solution.
Can you think of a way of converting an amount in pounds to an amount in stones and
pounds (one stone equals 14 pounds so, for example, we would like to be able to
display 204 pounds as 14 stones and 8 pounds)?
SYS-1CS20 Seminar sheet 1
A.J.Bagnall
for links and resources see
http://www.sys.uea.ac.uk/~ajb/Teaching/1CS20
Download