Physics and Astronomy |
Back to top
The aim of this page is to tell students and markers what is expected of their work. General expectationsWe are looking for programs that:
Incomplete or incorrect programsIncomplete programs will be given a mark roughly in proportion to the fraction of the program that has been completed. Programs that are complete but do not work due to a bug will lose at most 20% of the mark (note that this refers to programming errors, errors that suggest that the programmer is attempting to solve the wrong problem may lose more marks).
Specific expectationsThe general expectations above always apply, the purpose of this section is to apply those general principles to the aspects of the C language we have learnt so far. Thus this list grows as the module progresses but the expectations from previous weeks still apply. Week 1 onwardsIndentation and white spaceWe said in the lecture that professional projects expect perfect indentation. This sounds petty but it isn't. Properly indented programs are much easier to understand. ExampleHere is a simple example of an if (properly indented of course!):/* * Simple if demonstration */ #include <stdio.h> int main() { int mustbepositive = -2; /* !! */ if ( mustbepositive >= 0 ) { printf("OK: %d\n", mustbepositive); return 0; } else { printf("ERROR: it's negative: %d\n", mustbepositive); return 1; } } This is indented by two spaces per indent, four is most common and eight is a little extreme. Here it is without indentation: /* * Simple if demonstration with no indentation */ #include <stdio.h> int main() { int mustbepositive = -2; /* !! */ if ( mustbepositive >= 0 ) { printf("OK: %d\n", mustbepositive); return 0; } else { printf("ERROR: it's negative: %d\n", mustbepositive); return 1; } } Indentation standardsThroughout this module we shall expect the following:
Blank lines
Variables: type and names
Comments
Week 3 onwardsFunctionsA function should:
Failure to write and/or call functions when instructed toBeing able to write and call functions is a key programming skill. For this reason some exercises and assessments specifically state that a function should be written or called:
In these cases simply putting the code that would form the body of the function inside the calling function such as main() is not acceptable. Failure to write and call a suitable function when specifically instructed to will result in an extremely poor mark. Remember, if you are not sure how to write and call a function we are happy to show you (except in the CA test!). Input/output
Indentation and white spaceFunctions should have two or three blank lines separating them from the previous one. These occur before the comment, with no blank line between the comment and its function. Week 5 onwardsArraysArrays will have their sizes set by a #defined constants and all other parameters, such as loop limits etc., shall be arranged such that changing the #define causes everything else to change in step. Week 6 onwardsStructures
|