Programming and Algorithms Coursework 1
Release 1.0
Programming and Algorithms Teaching Team
Nov 02, 2023
CONTENTS
0.1 Changelog .............................................. 1
-
1 Coursework Specification 2 1.1 Introduction ............................................. 2 1.1.1 Keywords.......................................... 2 1.1.2 Definitions ......................................... 2
-
1.2 Submission.............................................. 3
-
1.3 Plagiarism .............................................. 3
-
1.4 Marking ............................................... 4
-
1.5 Question:calculator-‘Arithmeticcalculator’............................ 5 1.5.1 ProblemDescription .................................... 5 1.5.2 Input............................................. 5 1.5.3 Output............................................ 5 1.5.4 SampleInput/Output .................................... 5 1.5.5 SampleFilesandCommand-lineUsages.......................... 6
-
-
2 Source Code Submission Manual 7 2.1 TechnicalNotes ........................................... 7 2.2 Possibleresults............................................ 7 2.3 JudgingProcess ........................................... 8
2.3.1 Submittingsolutions .................................... 8 2.3.2 Compilation......................................... 8 2.3.3 Testing ........................................... 8 2.3.4 Restrictions......................................... 8
2.4 Codeexamples............................................ 9
i
Programming and Algorithms Coursework 1, Release 1.0
0.1 Changelog
Warning: Thecontentofthisfilemaychangeinfuture,pleasealwaysrefertothelatestversiononMoodle. 2023-10-28 1.0
Release candidate.
0.1. Changelog 1
1.1 Introduction
This is the first marked coursework for Programming and Algorithms (COMP1038). It is worth 30% of the module mark. It requires you to write a program to solve the given problem(s). The deadline for this coursework is 23:55 on Wednesday 22nd of November 2023.
Read the entire document before beginning the coursework.
If you have any questions about this coursework, please ask in the Q&A forum on Moodle, after a lecture, in a lab, or during the advertised oce hours. Do not post your program or parts of your program to Moodle as you are not allowed to share your coursework programs with other students. If any questions require this coursework to be clarified then this document will be updated and everyone will be notified via Moodle.
1.1.1 Keywords
The keywords MUST, MUST NOT, REQUIRED, SHALL, SHALL NOT, SHOULD, SHOULD NOT, REC- OMMENDED, MAY, and OPTIONAL in this guide are to be interpreted as follow:
MUSThis word, or the terms REQUIRED, SHOULD or SHALL, mean that the instruction is an absolute re- quirement of this guide.
MUST NOT
This phrase, or the phrases SHOULD NOT or SHALL NOT, mean that the instruction is an absolute
prohibition of this guide.
MAY This word, or the phrases RECOMMENDED or OPTIONAL, mean that the instruction is truly optional. 1.1.2 Definitions
standard input
This term, or the term stdin, mean that the stream from which input to the program is taken. Typically this is the keyboard, but it can be specified that input is to come from a serial port or a disk file, for example.
standard output
This term, or the term stdout, mean that the stream to which output from the program is sent. Typically this is a display, but it can be redirected to a serial port or a file.
standard error
This term, or the term stderr, mean that the stream to which error output from the program is sent. Typically this is a display, but it can be redirected to a serial port or a file.
<empty line>
This term, or the terms \n, \r\n, <LF> or <CR><LF>, mean the character \n after the last non-whitespace character in the previous content.
CHAPTER ONE
COURSEWORK SPECIFICATION
2
For example, the following representations are all equivalent:
Programming and Algorithms Coursework 1, Release 1.0
<empty line> \n
first first\nsecond\nthird\nlast\n
second
third
last
<empty line>
1.2 Submission
You must submit a single C source code file containing all your code for this exercise. This file must be called calculator.c and must not require any other files outside of the standard C headers which are always available. The first line of the file should be a comment which contains your student ID number, username, and full name, of the form:
// 6512345 zy12345 Joe Blogs
The file must compile without warnings or errors using the command
gcc -std=c99 -lm -Wall calculator.c -o calculator
This command will be run on our Linux server CSLinux. If it does not compile, for any reason, then you will lose all the marks for testing (common reasons in the past have been submitting a file with the wrong filename, or developing your solution on your personal computer without having tested it on our Linux server). If the file compiles but has warnings then you will lose some marks for not correcting the warnings.
The completed source code file should be uploaded to the Coursework 1 Submission link on the COMP1038 Moodle page. You may submit as many times as you wish and the last submission will be used for marking. However, if you submit after the deadline, your last submission time will be considered for the late submission penalty. After the deadline has passed, if you have already submitted your exercise then you will not be able to submit again. If you have not already submitted then you will be allowed to submit once.
Late submissions: COMP1038 late submission policy is dierent from the standard university policy. Late sub- missions will lose 2 percentage points per hour, rounded up to the next whole hour. This is to better represent the large benefit a small amount of extra time can give at the end of a programming exercise. No late submissions will be accepted more than 50 hours after the exercise deadline. If you have extenuating circumstances you should file them before the deadline.
1.3 Plagiarism
You should complete this coursework on your own. Anyone suspected of plagiarism will be investigated and punished in accordance with the university policy on plagiarism (see your student handbook and the University Quality Manual). This may include a mark of zero for this coursework.
You should write the source code required for this assignment yourself. If you use code from other sources (books, web pages, etc), you should use comments to acknowledge this (and marks will be heavily adjusted down accord- ingly). The only exception to this is the dynamic data-structures (linked lists and others) developed during the lectures and tutorials; you may use these, with or without modification, without penalty as long as you add a com- ment in your program saying you have taken them from the lectures or tutorials and saying how you have modified it (or not modified it). If you do not acknowledge their source in a comment then it will be regarded as potential plagiarism.
1.2. Submission 3
Programming and Algorithms Coursework 1, Release 1.0
You must not copy or share source code with other students. You must not work together on your solution. You can informally talk about higher-level ideas but not to a level of detail that would allow you all to create the same source code.
Remember, it is quite easy for experienced lecturers to spot plagiarism in source code. We also have automated tools that can help us identify shared code, even with modifications designed to hide copying. If you are having problems you should ask questions rather then plagiarize. If you are not able to complete the exercise then you should still submit your incomplete program as that will still get you some of the marks for the parts you have done (but make sure your incomplete solution compiles and partially runs!).
1.4 Marking
The marking scheme will be as follows:
• Tests (26 marks): Your program should correctly implement the task requirements. A number of tests will be run against your program with dierent input data designed to test if this is the case for each individual requirement. The tests themselves are secret but general examples of the tests might be:
– Does the program work with the example I/O in the question?
– Does the program work with typical valid input?
– Does the program correctly deal with invalid input?
– Does the program output match the required format?
– Does your code run correctly without any run-time error?
As noted in the submission section, if your program does not compile then you will lose all testing marks. As well as if you submit a dierent type of file apart from a single C source code file containing all your code for this exercise and the file name is dierent from calculator.c then you will also lose all testing marks. We usually use an automatic marking system to test/mark your coursework submissions. So you should strictly follow the output format specified in this task description while implementing your program. Otherwise, your program will fail to test and you will lose marks. If your code compiles with warnings, each warning message causes 10% mark deduction.
-
Appropriate use of language features (2 marks): Your program should use the appropriate C language features in your solution. You can use any language features or techniques that you have seen in the course, or you have learned on your own, as long as they are appropriate to your solution. Examples of this might be:
-
– Have you broken your program down into separate functions?
-
– Are all your function arguments being used?
-
– If your functions return values, are they being used?
-
– Are you using loops to avoid repeating many lines of code?
-
– Are your if/switch statements making a dierence, or is the conditions always true or false making the statement pointless?
-
-
Source code formatting (2 marks): Your program should be correctly formatted and easy to understand by a competent C programmer. This includes, but is not limited to, indentation, bracketing, variable/function naming, and use of comments.
1.4. Marking 4
Programming and Algorithms Coursework 1, Release 1.0
1.5 Question: calculator - ‘Arithmetic calculator’ 1.5.1 Problem Description
Your task is to implement an arithmetic calculator program in C programming language.
The program takes one mathematical expression in a line, then output the result to the expression, otherwise output
Invalid input and finish.
Your program should be able to handle arithmetic operators +, -, *, /, % (modulo), and (, ).
1.5.2 Input
The input is one mathematical expression in a line of no more than 100 characters. A valid numerical value satisfies the following conditions:
• Its length must be no more than 12 digits including the decimal point.
• Itisinoneoftheforms123,-12.3,12.3000,123.and.123,butNOTintheforms1e23,00123,+12.3
and 00.123.
A valid arithmetic expression contains arithmetic operators, numerical values, and white-spaces. It may contain extra spaces in between an operator and a value and you should simply ignore them. Your program should output Invalid input if the input contains more than 100 chars. You MUST NOT assume the expression is always legal and SHOULD validate the expression yourself.
Some examples of valid arithmetic expression are:
(1 + 2)* 3.14 -10.567854446/ 15.34 0.5* ((1.5 -1)+ 2)
1.5.3 Output
Output the result to the input expression.
The answer should have an absolute or relative error of at most 106, if the expression is invalid or cannot be
calculated, output case-sensitive string Invalid input. 1.5.4 Sample Input/Output
Input output
1+a Invalid input
Input output
(1+2+3)) Invalid input
1.5. Question: calculator - ‘Arithmetic calculator’ 5
Programming and Algorithms Coursework 1, Release 1.0
Input output
3.14%2 -1 Invalid input
Input output
3.141592685746* 2 Invalid input
Input output
1+2 * 3 7.000000
1.5.5 Sample Files and Command-line Usages
To compile the C code:
gcc -std=c99 -lm -Wall calculator.c -o calculator To test the program with the sample files:
./calculator < 1.in
Then check the output is exactly the same as the content in the corresponding .out files.
To detect memory leak:
valgrind --leak-check=full ./calculator < 1.in
Note:
• < is used for redirect the input from your keyboard to a given file.
• 1.in is a file containing the input mathematical expression in the same folder with the program, and it may be replaced by other file names in testing and marking. You can replace it with other .in files such as 2.in as long as it exists.
1.5. Question: calculator - ‘Arithmetic calculator’ 6