EEE125程序设计辅导、讲解C/C++编程、programming程序语言讲解
- 首页 >> Java编程 EEE125 - C programming program writing assignment 20/21 1 (© University of Sheffield '98-'20)
EEE125 Programming in ‘C’ Course: program writing assignment
At the first lecture, you were introduced to the make-up of this course and explained that the course would be
assessed by means of a Multiple Choice Question Blackboard test (worth 33.3% of the available marks) and
this C assignment task (also worth 33.3%). In semester 2, you will have a final test which covers both
Matlab and more advanced C programming writing exercises (this covers the remaining 33.4% of the marks).
For this assessed assignment you are asked to write a program in ‘C’ to carry out the particular task
detailed here.
1 Administrative details
Your program must be handed in via Blackboard. The hand-in date for this exercise is 4.59pm on Tuesday
15th December. You can hand your work in anytime between the beginning of week 10 and the deadline
date. You are very strongly urged to not leave your submission to the latest possible moment to avoid
computer related submission errors.
• Late submission will result in a deduction of 5% of the total mark awarded for each working day after the
submission date, this is Faculty policy. (Working days – Monday to Friday - include working days within
standard vacation times). The only exceptions to this will usually be where illness or other serious extenuating
circumstances have meant missing the hand-in date (medical evidence will often be needed to sustain this
exception). In such circumstances you MUST submit an Extenuating Circumstances form (not a selfcertification
form), available from www.sheffield.ac.uk/ssid/forms/circs, (before completing such a form
make sure you read the explanatory notes here first: http://www.sheffield.ac.uk/ssid/forms/circsnotes) hand
the form in to the department Student Support Office (Suite 27, level 1, 3 Solly Street building) or email
directly to Matthew Hobbs.
• If you believe you have good reason to ask for an extension to this hand-in date, you may discuss the
circumstances with Matthew Hobbs and, at his discretion, a later hand-in date may be negotiated. (But please
do the discussing well in advance of the original hand-in date expiring). Please note: being disorganised or
lazy and so failing to meet the hand-in date by simply leaving tackling the exercise until it's too late is not
a “good reason” and will not normally result in an extension of the hand-in date!
________________________________________________________________________________________
2 What your program should do
Elsewhere in your studies you may have heard of the “Least Squares” method often used to generate a “best fit” straight
line through a set of data plotted on a graph (where a straight line relationship is expected to exist). The "Least Squares"
method is very useful when working with data derived from experiments and indeed it may well be a technique of use to
you elsewhere in course work.
The aim of this assessed exercise is: for you to write a program in 'C' that uses the least squares technique to allow a user
to input a set of data value and to compute and output as results the gradient (m) and offset (c) of the “best fit” straight
line through that entered set of data. You do not need to understand the underlying mathematics (though it would help)
instead all you need to do is correctly implement the formulae given in this assignment sheet.
2.1 The "Least Squares" formulae needed
Consider you have a set of data comprising pairs of measurements of two related variables: ‘x’ & ‘y’. You believe
the relationship between these variables can be expressed as a straight line, using the standard straight line
equation (where y is the dependent variable and x is the independent variable, m is the gradient of the line - that
is the rate of change of y with respect to x - and c is the intercept (or ‘offset’) of the line with the y axis – that is
the value of y when x is zero). Here is the standard straight line equation:
y = m. x + c
EEE125 - C programming program writing assignment 20/21 2 (© University of Sheffield '98-'20)
Look at the example graph shown below. Pairs of x, y data have been plotted (the little ‘+’ marks) and a best fit
straight line drawn through them (the dotted line). The gradient of the “best fit” straight line is ‘m’ and the
intercept (offset) of that line with the y axis from the origin of the graph is ‘c’.
From theory we can obtain the equations needed to
draw a best fit straight line through such a set of data
using “Least Squares” as our technique.
Consider we have a set of data samples where values of
‘y’ have been measured for a range of different values
of ‘x’. Consider we have taken ‘N’ samples (i.e. pairs
of x and y data of the form: [x1 y1] [x2 y2] [x3 y3] … [xN
yN]). Then using this notation we can write the
following equations:
The least squares equation for the gradient of the ‘best fit’ line ‘m’ is:
The least squares equation for the offset of the ‘best fit’ line ‘c’ is:
When interpreting these formulae you might like to be reminded that:
Although these formulae may initially look daunting, note that they contain some common terms,
appears in the formulas above. By identifying such common terms you can perhaps
save effort by calculating them only once and use the results when those terms appear in later equations or writing
one function to do this and use it each time it’s needed.
EEE125 - C programming program writing assignment 20/21 3 (© University of Sheffield '98-'20)
2.2 How the program should appear to the user – the Requirements.
Reminder, the aim of this assessed exercise is for you to write a program that will allow the user to enter a set
of data (in the form of x, y pairs) and then uses the least squares technique to calculate and display the gradient
(m) and offset (c) of the “best fit” straight line through that set of data.
a) The program should begin by briefly announcing its purpose to the user.
b) Next it should ask the user how many pairs of data values (sets of x and y) they intend to input, only
permitting the user to choose numbers of pairs in the range from 4 to 20 pairs (that is the user should be
permitted to enter no fewer than 4 pairs and no more than 20 pairs).
c) Make sure your program displays clear instructions to the user at each stage so that the user knows exactly
what the program wants them to do.
d) The program should then ask the user to input the specified number of data value pairs, storing them in suitable
variable(s). Your program should be able to accept values for x and y entered as real numbers. Your program
should accept only positive numbers that are in the range between l000000.0 and 0.000005.
e) Next the program should neatly display all the data pairs entered in a tidy way on the screen.
f) The program should use the least squares formulae described section 2.1 above to process the set of data
entered and so calculate the values for ‘m’ and ‘c’ for the ‘best fit’ straight line through that set of data.
g) The program should then neatly display the values of ‘m’ and ‘c’ that it has calculated.
h) The program should then ask the user if they would like to repeat the program, interpret their reply, and, if
their answer is yes then the program should repeat again all steps from step b) onwards.
Please note:
• When designing you program: be careful to ensure that it makes efficient use of variable space by choosing
suitable types for your variables that do not waste memory unnecessarily. Don’t just assume this program
will be compiled to run on a PC with the Dev-C compiler, make sure you use the smallest ‘C’ type variables
necessary according to the minimum sizes given for the standard C types in the lectures. Also make
appropriate use of the various flow-control statements 'C' has to offer to build loops where they would be
helpful.
• You should divide your program up into separate functions. Programs that consist of everything inside the
single function main only will earn far fewer marks than programs that are divided into more than one
function.
2.3 A sample data set to use for testing
Here is some sample data upon which you might like to test your program:
First a simple set (you could try plotting it as a graph and estimating m and c by hand):
The results are: Gradient of best fit straight line m = 1.025 approx. with and a y intercept at c = 1.911 approx.
EEE125 - C programming program writing assignment 20/21 4 (© University of Sheffield '98-'20)
Now a more complex set:
The results are: Gradient of best fit straight line m = 0.0634 and a y intercept c at -2.907.
2.4 Some helpful hints
• Your program must be written in ‘C’ and not ‘C++’. (‘C’ is taught in EEE125, not C++, so sticking to
techniques you have been taught will mean you will be OK). Make sure you save your file with a ‘.c’
filename extension NOT ‘.cpp’. When using Dev-C, make sure when saving your file that the “Save
File” dialogue has the “Save as type” drop-down menu set for “C source files (*.c)”.
• By the time this sheet is handed out you will have already covered, in lectures and lab sheets, all the
material necessary to allow you to write a suitable program. However, future lectures and background
reading of your own may be of additional help.
• Make your program code as easy to "read" (by a human) as possible. For example partition it (in other words
break it up) by making your own functions. (Programs that consist of everything inside the single function
main only will earn fewer marks than programs that are divided into more than one function). (See example
solution to Lab 6 question 4 file TUT6Q4-4.c in the EEE125 MOLE course, in the ‘Lab Classes’ section, in
the ‘Lab Class Downloads’ folder and finally in the ‘Lab Sheet 6 – Downloads’ showing use of functions).
Use well-chosen identifiers for function names and variable names so that the purpose of a particular
function or variable is hinted by its name. This example solution will be made available during week 8 of
the semester.
• Make sure the program is well commented (i.e. using /* */ marks) so that the purpose of each part is clear.
These comments should be concise. Note: there is no need to use comments to explain how a particular ‘C’
construct works, you can assume the reader understands the ‘C’ language itself (e.g. you don’t need to explain
how a ‘for’ loop works as such). However you should add comments to explain what your program aims to
achieve with particular ‘C’ constructs where it isn't immediately obvious (e.g. explain what useful task a
particular ‘for’ loop is performing for you in your particular program). This is an important skill needed by
programmers to ensure their program code is ‘readable’ and ‘understandable’ by others who may have cause
to examine it or modify it later. You have been given clear guidance in the lectures about how to lay out a
program and how to add comments – check your lecture slides to see what was said.
• Don't forget: planning your program thoroughly on paper first is by far the most effective way of quickly
writing a good program. Don't rush to coding at the PC too soon. Start by breaking the task down into
manageable portions, then plan the sequence of events for each portion with flow-charts and pseudo code etc.
Flow-charts in particular will help you identify the appropriate flow control statements ('while', 'do..while',
'for', 'if' etc.) to choose.
• Test the output from your program by using various sets of data. You can generate your own test data quite
easily. Use a calculator or a spreadsheet to help verify your results. Don't forget to check your program's
behaviour with illegal data (i.e. data outside the range allowed for input), does it behave appropriately?
EEE125 - C programming program writing assignment 20/21 5 (© University of Sheffield '98-'20)
• Don't forget, “divide and conquer” is a wise approach. Break the task down into manageable portions and
tackle them one at a time, don't try and code up the whole program in one go only to find it doesn't work. The
task of finding a fault (or more likely many faults) in a large program is like "looking for a needle in a haystack"
- make sure you have only a small "haystack" to search! Start off with a small program which only does the
first few steps of the task, get that working first. Next add a bit more to your program and get that working
too. Continue in this way until the program can carry out the complete task
• Above all, be sure to hand something in by the hand-in date. If you examine the marking scheme carefully
(see later) you will see that only a small proportion of the marks are available for accuracy of results, etc.
There are many more marks available for other aspects of the work. If you only manage to produce a
program that asks for, stores and re-displays the input sample data values but does not even attempt to do
anything else then you can at least be given some marks for that much (which is better than no marks if you
hand in nothing!)
• If you need help:
a) Please talk to your demonstrators during a timetabled online Tuesday afternoon computer lab. session, or
a timetabled face-to-face Wednesday morning computer lab. session.
b) Be sure to make full use of the 'C' books in the library and the web links provided in our Blackboard
course as well as other available online resources.
3 What should you hand in?
3.1 The program itself:
• You should hand your ‘C’ program file itself in via Blackboard (see instructions in section 3.2 below)
and it should be in the form of a source file of ‘C’ code (that is the ASCII text file created in the usual way by
using the Dev-C++ Editor when writing a program and saved with the filename and the file name extension
for C Source Files: “leastsq.c”). You MUST name the file “leastsq.c " Please use this name only, it
helps with processing your work quickly. It must not be called “leastsq.cpp"! (*.cpp implies a C++
file and you must not write in C++!). Use of an incorrect filename will result in lost marks.
• You MUST write your Registration number into a comment string as the first line of your program like
this:
/* My Reg Number: 180113134 */
#include
…and so on. You are NOT required to include your name.
• If, for any reason, you choose to write and test your program using a `C' compiler other than the Bloodshed
Dev-C environment provided for you on the University's Computer network (as used in the lab.
sessions), then you are strongly recommended to test the final version of your source code within the DevC
compiler environment on the University's Computer network and check that it compiles and runs correctly
before handing it in. It is this same Dev-C compiler environment that will used to compile and test your
program in order to assess it! If you have used a different compiler, and your program does not compile
on the Dev-C compiler environment, you will lose marks.
EEE125 - C programming program writing assignment 20/21 6 (© University of Sheffield '98-'20)
3.2 Submitting your file:
To submit your program via Blackboard, follow these instructions (follow them carefully as you only get one
chance to submit!):
a) You only have one chance to submit your file, once submitted you cannot change it, so be sure you are
finished and have chosen the correct file to submit and attach it correctly.
b) Once you have finished your C source file and you are happy that it is ready to submit, open a web
browser and either login in to Blackboard via MUSE.
c) On the “EEE125 Programming” course home page look for the ‘Assessment and Feedback’ section in
the left-hand menu.
d) In the ‘Assessment and Feedback’ section of this left-hand menu you should see a heading called
‘Assessment’. Click on this.
e) You should now see an item titled “C Programming Course, Assessed Exercise No. 1”, make sure you
click on this title.
f) Scroll down to section “Assignment Submission”. DO NOT use the Create Submission button. Look
below and you will see a line beginning “Attach file” and a button marked “Browse My Computer”.
Click on this. A file browser window should now open.
g) In the file browser window navigate to your folder and select your ‘C’ source file leastsq.c in the
conventional way. (Make absolutely sure you are selecting the C source file - the one you typed – not
any of the other associated files the compiler generates when you compile and run your program). To do
this, look at the icon displayed beside the file name, make sure you pick the file with the icon showing a
small blue ‘.c’ in the corner. Double click on your leastsq.c file to attach it. It should now appear in
a list of “Attached files”.
h) Once you are sure you have attached your leastsq.c file then scroll to the bottom of the page and you
should see the Submit button on the right hand side, click this button to submit your work. Note: You
must NOT write anything in the Add Comments box (anything this placed here will not be read).
EEE125 - C programming program writing assignment 20/21 7 (© University of Sheffield '98-'20)
3.3 Marking Scheme
Here is the marking scheme that will be used to mark your work. Initially, as you can see, you will be marked
out of 100, “full marks” would be 100%.
Does the program try to meet the specification laid out in this
sheet? Is it designed to do all the things asked for?
Have variables been created using appropriate types and do they
make efficient use of storage space?
Have the many useful ‘C’ language features discussed in
lectures and tutorials been exploited? Are the ‘C’ constructs
used appropriately?
Is the program's purpose easily understood from the way it's
structured e.g. does it have an appropriate hierarchical form
(exploiting functions?). Is it well (concisely and clearly)
commented? Have sensible, self explanatory, identifiers been
chosen for function names and variable names?
Have user functions other than main been written at all? Are
they used sensibly? Is the choice of return types and parameters
sensible?
Does the program compile without errors or serious warnings?
Does it run without crashing etc?
Are the results it produces correct? 20
User interface Does the "user interface" clearly inform the user what she or he
must do at each stage? Are the outputs presented clearly and in
an appropriate fashion?
The basic principle underlying assessed work is that the work submitted for assessment must be entirely
your own. No one objects to you discussing the principles of C programming in general with others, but:
plagiarism and collusion are not allowed. You must not discuss the details of how to do this exercise with any
one other than Matthew Hobbs or one of the lab. demonstrators (GTAs). In the context of this exercise, unfair
means would include:
1 You MUST NOT allow anyone else to write or dictate to you your program, in whole or in part.
2 You MUST NOT look at someone else’s program for this exercise or copy from someone else’s work or
exchange emails or internet chat messages (MSM, Weibo, Whatsapp, Facebook, Google Meet,
Blackboard or similar) with someone else which include code from either your program or their program
for this exercise. Note: this includes with the lab. Demonstrators or students in other years.
3 Likewise you MUST NOT write program code for, or share program code with, another student on this
course or from previous years of study or anyone else.
4 You MUST NOT team up with others to write one program (in whole or in part) together, then all hand in
programs containing that same code (in whole or in part).
5 You MUST NOT copy portions of code from any sources (that are not of your own creation) such as a
website or a book or from someone else’s computer, website (even from a website where the language is not
English) or memory device. (However: you are granted exceptional permission to copy from any of the
EEE125 - C programming program writing assignment 20/21 8 (© University of Sheffield '98-'20)
examples of code that have been given to you during this course as lecture or tutorial examples – if you
do this, then attribute the source of those portions of code by clearly referencing it using a comment like
this /* taken from EEE125 examples */ immediately before and immediately after the code
concerned.)
Remember: the basic principle underlying assessed work such as this is that the work submitted for
assessment must be entirely your own. We wish to only give marks for programs written by you alone!
If you are in any doubt about what might constitute unfair means in the context of this exercise then please
discuss any areas of uncertainty with Matthew Hobbs. If you experience any problems with this assignment
then seek help from Matthew Hobbs or the demonstrators present during lab. sessions.
Please note: We will be using a sophisticated program specially designed to detect plagiarism in a set of ‘C’
programs to help detect evidence of such unfair means in the assessed work that you hand in, so, please don't
take the risk of copying work, submit only work done by you entirely on you own. Where we suspect unfair
means to have been used, the department reserves the right to give zero marks to all individuals concerned
and/or refer you to the University Discipline Committee and/or place a note in your student record file
(We have caught people breaking these recommendations before and done all these things, so do please note the
warning!).
Good Luck!
EEE125 Programming in ‘C’ Course: program writing assignment
At the first lecture, you were introduced to the make-up of this course and explained that the course would be
assessed by means of a Multiple Choice Question Blackboard test (worth 33.3% of the available marks) and
this C assignment task (also worth 33.3%). In semester 2, you will have a final test which covers both
Matlab and more advanced C programming writing exercises (this covers the remaining 33.4% of the marks).
For this assessed assignment you are asked to write a program in ‘C’ to carry out the particular task
detailed here.
1 Administrative details
Your program must be handed in via Blackboard. The hand-in date for this exercise is 4.59pm on Tuesday
15th December. You can hand your work in anytime between the beginning of week 10 and the deadline
date. You are very strongly urged to not leave your submission to the latest possible moment to avoid
computer related submission errors.
• Late submission will result in a deduction of 5% of the total mark awarded for each working day after the
submission date, this is Faculty policy. (Working days – Monday to Friday - include working days within
standard vacation times). The only exceptions to this will usually be where illness or other serious extenuating
circumstances have meant missing the hand-in date (medical evidence will often be needed to sustain this
exception). In such circumstances you MUST submit an Extenuating Circumstances form (not a selfcertification
form), available from www.sheffield.ac.uk/ssid/forms/circs, (before completing such a form
make sure you read the explanatory notes here first: http://www.sheffield.ac.uk/ssid/forms/circsnotes) hand
the form in to the department Student Support Office (Suite 27, level 1, 3 Solly Street building) or email
directly to Matthew Hobbs.
• If you believe you have good reason to ask for an extension to this hand-in date, you may discuss the
circumstances with Matthew Hobbs and, at his discretion, a later hand-in date may be negotiated. (But please
do the discussing well in advance of the original hand-in date expiring). Please note: being disorganised or
lazy and so failing to meet the hand-in date by simply leaving tackling the exercise until it's too late is not
a “good reason” and will not normally result in an extension of the hand-in date!
________________________________________________________________________________________
2 What your program should do
Elsewhere in your studies you may have heard of the “Least Squares” method often used to generate a “best fit” straight
line through a set of data plotted on a graph (where a straight line relationship is expected to exist). The "Least Squares"
method is very useful when working with data derived from experiments and indeed it may well be a technique of use to
you elsewhere in course work.
The aim of this assessed exercise is: for you to write a program in 'C' that uses the least squares technique to allow a user
to input a set of data value and to compute and output as results the gradient (m) and offset (c) of the “best fit” straight
line through that entered set of data. You do not need to understand the underlying mathematics (though it would help)
instead all you need to do is correctly implement the formulae given in this assignment sheet.
2.1 The "Least Squares" formulae needed
Consider you have a set of data comprising pairs of measurements of two related variables: ‘x’ & ‘y’. You believe
the relationship between these variables can be expressed as a straight line, using the standard straight line
equation (where y is the dependent variable and x is the independent variable, m is the gradient of the line - that
is the rate of change of y with respect to x - and c is the intercept (or ‘offset’) of the line with the y axis – that is
the value of y when x is zero). Here is the standard straight line equation:
y = m. x + c
EEE125 - C programming program writing assignment 20/21 2 (© University of Sheffield '98-'20)
Look at the example graph shown below. Pairs of x, y data have been plotted (the little ‘+’ marks) and a best fit
straight line drawn through them (the dotted line). The gradient of the “best fit” straight line is ‘m’ and the
intercept (offset) of that line with the y axis from the origin of the graph is ‘c’.
From theory we can obtain the equations needed to
draw a best fit straight line through such a set of data
using “Least Squares” as our technique.
Consider we have a set of data samples where values of
‘y’ have been measured for a range of different values
of ‘x’. Consider we have taken ‘N’ samples (i.e. pairs
of x and y data of the form: [x1 y1] [x2 y2] [x3 y3] … [xN
yN]). Then using this notation we can write the
following equations:
The least squares equation for the gradient of the ‘best fit’ line ‘m’ is:
The least squares equation for the offset of the ‘best fit’ line ‘c’ is:
When interpreting these formulae you might like to be reminded that:
Although these formulae may initially look daunting, note that they contain some common terms,
appears in the formulas above. By identifying such common terms you can perhaps
save effort by calculating them only once and use the results when those terms appear in later equations or writing
one function to do this and use it each time it’s needed.
EEE125 - C programming program writing assignment 20/21 3 (© University of Sheffield '98-'20)
2.2 How the program should appear to the user – the Requirements.
Reminder, the aim of this assessed exercise is for you to write a program that will allow the user to enter a set
of data (in the form of x, y pairs) and then uses the least squares technique to calculate and display the gradient
(m) and offset (c) of the “best fit” straight line through that set of data.
a) The program should begin by briefly announcing its purpose to the user.
b) Next it should ask the user how many pairs of data values (sets of x and y) they intend to input, only
permitting the user to choose numbers of pairs in the range from 4 to 20 pairs (that is the user should be
permitted to enter no fewer than 4 pairs and no more than 20 pairs).
c) Make sure your program displays clear instructions to the user at each stage so that the user knows exactly
what the program wants them to do.
d) The program should then ask the user to input the specified number of data value pairs, storing them in suitable
variable(s). Your program should be able to accept values for x and y entered as real numbers. Your program
should accept only positive numbers that are in the range between l000000.0 and 0.000005.
e) Next the program should neatly display all the data pairs entered in a tidy way on the screen.
f) The program should use the least squares formulae described section 2.1 above to process the set of data
entered and so calculate the values for ‘m’ and ‘c’ for the ‘best fit’ straight line through that set of data.
g) The program should then neatly display the values of ‘m’ and ‘c’ that it has calculated.
h) The program should then ask the user if they would like to repeat the program, interpret their reply, and, if
their answer is yes then the program should repeat again all steps from step b) onwards.
Please note:
• When designing you program: be careful to ensure that it makes efficient use of variable space by choosing
suitable types for your variables that do not waste memory unnecessarily. Don’t just assume this program
will be compiled to run on a PC with the Dev-C compiler, make sure you use the smallest ‘C’ type variables
necessary according to the minimum sizes given for the standard C types in the lectures. Also make
appropriate use of the various flow-control statements 'C' has to offer to build loops where they would be
helpful.
• You should divide your program up into separate functions. Programs that consist of everything inside the
single function main only will earn far fewer marks than programs that are divided into more than one
function.
2.3 A sample data set to use for testing
Here is some sample data upon which you might like to test your program:
First a simple set (you could try plotting it as a graph and estimating m and c by hand):
The results are: Gradient of best fit straight line m = 1.025 approx. with and a y intercept at c = 1.911 approx.
EEE125 - C programming program writing assignment 20/21 4 (© University of Sheffield '98-'20)
Now a more complex set:
The results are: Gradient of best fit straight line m = 0.0634 and a y intercept c at -2.907.
2.4 Some helpful hints
• Your program must be written in ‘C’ and not ‘C++’. (‘C’ is taught in EEE125, not C++, so sticking to
techniques you have been taught will mean you will be OK). Make sure you save your file with a ‘.c’
filename extension NOT ‘.cpp’. When using Dev-C, make sure when saving your file that the “Save
File” dialogue has the “Save as type” drop-down menu set for “C source files (*.c)”.
• By the time this sheet is handed out you will have already covered, in lectures and lab sheets, all the
material necessary to allow you to write a suitable program. However, future lectures and background
reading of your own may be of additional help.
• Make your program code as easy to "read" (by a human) as possible. For example partition it (in other words
break it up) by making your own functions. (Programs that consist of everything inside the single function
main only will earn fewer marks than programs that are divided into more than one function). (See example
solution to Lab 6 question 4 file TUT6Q4-4.c in the EEE125 MOLE course, in the ‘Lab Classes’ section, in
the ‘Lab Class Downloads’ folder and finally in the ‘Lab Sheet 6 – Downloads’ showing use of functions).
Use well-chosen identifiers for function names and variable names so that the purpose of a particular
function or variable is hinted by its name. This example solution will be made available during week 8 of
the semester.
• Make sure the program is well commented (i.e. using /* */ marks) so that the purpose of each part is clear.
These comments should be concise. Note: there is no need to use comments to explain how a particular ‘C’
construct works, you can assume the reader understands the ‘C’ language itself (e.g. you don’t need to explain
how a ‘for’ loop works as such). However you should add comments to explain what your program aims to
achieve with particular ‘C’ constructs where it isn't immediately obvious (e.g. explain what useful task a
particular ‘for’ loop is performing for you in your particular program). This is an important skill needed by
programmers to ensure their program code is ‘readable’ and ‘understandable’ by others who may have cause
to examine it or modify it later. You have been given clear guidance in the lectures about how to lay out a
program and how to add comments – check your lecture slides to see what was said.
• Don't forget: planning your program thoroughly on paper first is by far the most effective way of quickly
writing a good program. Don't rush to coding at the PC too soon. Start by breaking the task down into
manageable portions, then plan the sequence of events for each portion with flow-charts and pseudo code etc.
Flow-charts in particular will help you identify the appropriate flow control statements ('while', 'do..while',
'for', 'if' etc.) to choose.
• Test the output from your program by using various sets of data. You can generate your own test data quite
easily. Use a calculator or a spreadsheet to help verify your results. Don't forget to check your program's
behaviour with illegal data (i.e. data outside the range allowed for input), does it behave appropriately?
EEE125 - C programming program writing assignment 20/21 5 (© University of Sheffield '98-'20)
• Don't forget, “divide and conquer” is a wise approach. Break the task down into manageable portions and
tackle them one at a time, don't try and code up the whole program in one go only to find it doesn't work. The
task of finding a fault (or more likely many faults) in a large program is like "looking for a needle in a haystack"
- make sure you have only a small "haystack" to search! Start off with a small program which only does the
first few steps of the task, get that working first. Next add a bit more to your program and get that working
too. Continue in this way until the program can carry out the complete task
• Above all, be sure to hand something in by the hand-in date. If you examine the marking scheme carefully
(see later) you will see that only a small proportion of the marks are available for accuracy of results, etc.
There are many more marks available for other aspects of the work. If you only manage to produce a
program that asks for, stores and re-displays the input sample data values but does not even attempt to do
anything else then you can at least be given some marks for that much (which is better than no marks if you
hand in nothing!)
• If you need help:
a) Please talk to your demonstrators during a timetabled online Tuesday afternoon computer lab. session, or
a timetabled face-to-face Wednesday morning computer lab. session.
b) Be sure to make full use of the 'C' books in the library and the web links provided in our Blackboard
course as well as other available online resources.
3 What should you hand in?
3.1 The program itself:
• You should hand your ‘C’ program file itself in via Blackboard (see instructions in section 3.2 below)
and it should be in the form of a source file of ‘C’ code (that is the ASCII text file created in the usual way by
using the Dev-C++ Editor when writing a program and saved with the filename and the file name extension
for C Source Files: “leastsq.c”). You MUST name the file “leastsq.c " Please use this name only, it
helps with processing your work quickly. It must not be called “leastsq.cpp"! (*.cpp implies a C++
file and you must not write in C++!). Use of an incorrect filename will result in lost marks.
• You MUST write your Registration number into a comment string as the first line of your program like
this:
/* My Reg Number: 180113134 */
#include
…and so on. You are NOT required to include your name.
• If, for any reason, you choose to write and test your program using a `C' compiler other than the Bloodshed
Dev-C environment provided for you on the University's Computer network (as used in the lab.
sessions), then you are strongly recommended to test the final version of your source code within the DevC
compiler environment on the University's Computer network and check that it compiles and runs correctly
before handing it in. It is this same Dev-C compiler environment that will used to compile and test your
program in order to assess it! If you have used a different compiler, and your program does not compile
on the Dev-C compiler environment, you will lose marks.
EEE125 - C programming program writing assignment 20/21 6 (© University of Sheffield '98-'20)
3.2 Submitting your file:
To submit your program via Blackboard, follow these instructions (follow them carefully as you only get one
chance to submit!):
a) You only have one chance to submit your file, once submitted you cannot change it, so be sure you are
finished and have chosen the correct file to submit and attach it correctly.
b) Once you have finished your C source file and you are happy that it is ready to submit, open a web
browser and either login in to Blackboard via MUSE.
c) On the “EEE125 Programming” course home page look for the ‘Assessment and Feedback’ section in
the left-hand menu.
d) In the ‘Assessment and Feedback’ section of this left-hand menu you should see a heading called
‘Assessment’. Click on this.
e) You should now see an item titled “C Programming Course, Assessed Exercise No. 1”, make sure you
click on this title.
f) Scroll down to section “Assignment Submission”. DO NOT use the Create Submission button. Look
below and you will see a line beginning “Attach file” and a button marked “Browse My Computer”.
Click on this. A file browser window should now open.
g) In the file browser window navigate to your folder and select your ‘C’ source file leastsq.c in the
conventional way. (Make absolutely sure you are selecting the C source file - the one you typed – not
any of the other associated files the compiler generates when you compile and run your program). To do
this, look at the icon displayed beside the file name, make sure you pick the file with the icon showing a
small blue ‘.c’ in the corner. Double click on your leastsq.c file to attach it. It should now appear in
a list of “Attached files”.
h) Once you are sure you have attached your leastsq.c file then scroll to the bottom of the page and you
should see the Submit button on the right hand side, click this button to submit your work. Note: You
must NOT write anything in the Add Comments box (anything this placed here will not be read).
EEE125 - C programming program writing assignment 20/21 7 (© University of Sheffield '98-'20)
3.3 Marking Scheme
Here is the marking scheme that will be used to mark your work. Initially, as you can see, you will be marked
out of 100, “full marks” would be 100%.
Does the program try to meet the specification laid out in this
sheet? Is it designed to do all the things asked for?
Have variables been created using appropriate types and do they
make efficient use of storage space?
Have the many useful ‘C’ language features discussed in
lectures and tutorials been exploited? Are the ‘C’ constructs
used appropriately?
Is the program's purpose easily understood from the way it's
structured e.g. does it have an appropriate hierarchical form
(exploiting functions?). Is it well (concisely and clearly)
commented? Have sensible, self explanatory, identifiers been
chosen for function names and variable names?
Have user functions other than main been written at all? Are
they used sensibly? Is the choice of return types and parameters
sensible?
Does the program compile without errors or serious warnings?
Does it run without crashing etc?
Are the results it produces correct? 20
User interface Does the "user interface" clearly inform the user what she or he
must do at each stage? Are the outputs presented clearly and in
an appropriate fashion?
The basic principle underlying assessed work is that the work submitted for assessment must be entirely
your own. No one objects to you discussing the principles of C programming in general with others, but:
plagiarism and collusion are not allowed. You must not discuss the details of how to do this exercise with any
one other than Matthew Hobbs or one of the lab. demonstrators (GTAs). In the context of this exercise, unfair
means would include:
1 You MUST NOT allow anyone else to write or dictate to you your program, in whole or in part.
2 You MUST NOT look at someone else’s program for this exercise or copy from someone else’s work or
exchange emails or internet chat messages (MSM, Weibo, Whatsapp, Facebook, Google Meet,
Blackboard or similar) with someone else which include code from either your program or their program
for this exercise. Note: this includes with the lab. Demonstrators or students in other years.
3 Likewise you MUST NOT write program code for, or share program code with, another student on this
course or from previous years of study or anyone else.
4 You MUST NOT team up with others to write one program (in whole or in part) together, then all hand in
programs containing that same code (in whole or in part).
5 You MUST NOT copy portions of code from any sources (that are not of your own creation) such as a
website or a book or from someone else’s computer, website (even from a website where the language is not
English) or memory device. (However: you are granted exceptional permission to copy from any of the
EEE125 - C programming program writing assignment 20/21 8 (© University of Sheffield '98-'20)
examples of code that have been given to you during this course as lecture or tutorial examples – if you
do this, then attribute the source of those portions of code by clearly referencing it using a comment like
this /* taken from EEE125 examples */ immediately before and immediately after the code
concerned.)
Remember: the basic principle underlying assessed work such as this is that the work submitted for
assessment must be entirely your own. We wish to only give marks for programs written by you alone!
If you are in any doubt about what might constitute unfair means in the context of this exercise then please
discuss any areas of uncertainty with Matthew Hobbs. If you experience any problems with this assignment
then seek help from Matthew Hobbs or the demonstrators present during lab. sessions.
Please note: We will be using a sophisticated program specially designed to detect plagiarism in a set of ‘C’
programs to help detect evidence of such unfair means in the assessed work that you hand in, so, please don't
take the risk of copying work, submit only work done by you entirely on you own. Where we suspect unfair
means to have been used, the department reserves the right to give zero marks to all individuals concerned
and/or refer you to the University Discipline Committee and/or place a note in your student record file
(We have caught people breaking these recommendations before and done all these things, so do please note the
warning!).
Good Luck!