Students are required to submit their coursework online using their individual coursework pages on theMosaic website.
Coursework submissions MUST satisfy the following requirements:
There will be at least one saved version per question answered.
The answer to all questions must be written as one single program.
Answers must not be copied from any printed sources, electronic sources or other people.
Answer all questions. This assessment has a total of 20 marks. Each question will be marked according to the following criteria:
Marks
Criteria
5
Source code uses an effective design to answer the question, compiles without errors and includes informative comments.
4
Source code answers the question, compiles without errors and includes informative comments.
3
Source code answers the question and compiles without errors.
2
Source code is relevant to the question, but does not compile.
1
Source code is incorrect or not relevant to the question.
COURSEWORK QUESTIONS
QUESTION 1
[5 Marks]
Write a C program that uses a stack or a queue to store individual input characters. The data structure size must be 10. The program must:
Accept 10 input characters
Store them into the data structure
Stop accepting input and end the program
QUESTION 2
[5 Marks]
In the same program as question 1, add source code to identify sequences of 3 consecutive input characters that are the same. The program must display the number of sequences that were found. If the input does not contain any matching sequences, then display zero sequences.
For example, if the input characters are:
RRRedTag9?
Then, the program must display the following output message:
Found 1 sequence
QUESTION 3
[5 Marks]
In the same program as question 1, add source code to calculate and display the sum of points for the 10 input characters stored in the data structure using the following rules:
Any number is worth 4 points, e.g. character 9 is worth 4 points and character 0 is worth 4 points
Any uppercase letter is worth 3 points, e.g. character W is worth 3 points
Any lowercase letter is worth 2 points, e.g. character b is worth 2 points
Any other character is worth 1 point, e.g. character ? is worth 1 point
For example, if the input characters are:
RRRedTag9?
Then, the program must display the following output message:
Total points is 25
QUESTION 4
[5 Marks]
In the same program as question 1, add source code to identify and display 3 characters stored in the data structure which have the highest points value. If there are more than 3 characters with the highest points value, then the program may select any of them. The order of the characters when displayed is not important.
For example, if the input characters are:
RRRedTag9?
Then, the program output could be similar to the following. Your program may display the output characters in a different order.
struct stack { int currentStackSize; char currentStackItems[ MAX_STACK_SIZE ]; };
struct stack letters; /* Stack currently in use by program */
void push(char); /* Adds a character to the top of the stack */ char pop(); /* Remove a character from the top of the stack */ char top(); /* Look at the character currently at the top of the stack */ int size(); /* Count the characters currently in the stack */
int main(void) { char token, sequencesPattern, topToken1, topToken2, topToken3; int counter, tokenPoints, totalPoints, sequencesCounter, sequencesFound; int topToken1Points, topToken2Points, topToken3Points;