Week 07 Weekly Test Questions
Test Conditions
These questions must be completed under self-administered exam-like conditions. You must time the test yourself and ensure you comply with the conditions below.
- You may complete this test in CSE labs or elsewhere using your own machine.
- You may complete this test at any time before Wednesday 01 January 00:00.
- The maximum time allowed for this test is 1 hour + 5 minutes reading time.
- You may first use 5 minutes to read the questions (no typing).
- You must then complete the test within 1 hour and submit your answers with give.
- You must complete the questions alone: you can not get help in any way from any person.
- You can not access your previous answers to lab or tut questions.
- You can not access web pages or use the internet in any way.
- You can not access books, notes or other written or online materials.
- You can not access your own files, programs, code ...
- You can not access COMP1521 course materials, except for language documentation linked below.
You may access this language documentation while attempting this test:
You may also access manual entries (the man
command).
Any violation of the test conditions will results in a mark of zero for the entire weekly test component.
Set up for the test by creating a new directory called
test07
, changing to this directory, and fetching the
provided code by running these commands:
mkdir test07 cd test07 1521 fetch test07
Or, if you're not working on CSE, you can download the provided code as a zip file or a tar file.
You should not write any code. Test in Progress — working time You have just over minutes left in the test. Test Complete! Your time for this test has finished. You may submit your work. You may choose to keep working, but you should not submit further work. You should reflect on how you went in this hour, and discuss with your tutor if you have concerns.
weekly test question:
MIPS - Which char?
line_char.s
, a MIPS assembler program that reads a line of input then reads an
integer, n, then prints a '?'.
1521 spim -f line_char.s Loaded: /home/cs1521/share/spim/exceptions.s Enter a line of input: Hello Enter a position: 1 Character is: ?Add code to
line_char.s
to make it equivalent to this C
program which reads a line and prints the character in position
n:
// read a line from stdin and and then an integer n
// Print the character in the nth-position
#include <stdio.h>
// line of input stored here
char line[256];
int main(void) {
printf("Enter a line of input: ");
fgets(line, 256, stdin);
printf("Enter a position: ");
int n;
scanf("%d", &n);
printf("Character is: ");
printf("%c", line[n]);
printf("%c", '\n');
return 0;
}
For example:
1521 spim -f line_char.s Loaded: /home/cs1521/share/spim/exceptions.s Enter a line of input: abcdefghijklmnopqrstuvwxyz Enter a position: 0 Character is: a 1521 spim -f line_char.s Loaded: /home/cs1521/share/spim/exceptions.s Enter a line of input: abcdefghijklmnopqrstuvwxyz Enter a position: 13 Character is: n 1521 spim -f line_char.s Loaded: /home/cs1521/share/spim/exceptions.s Enter a line of input: Hello Andrew! Enter a position: 12 Character is: ! 1521 spim -f line_char.s Loaded: /home/cs1521/share/spim/exceptions.s Enter a line of input: i MIPS you Enter a position: 3 Character is: I
When you think your program is working you can
autotest
to run some simple automated tests:
1521 autotest line_charWhen you are finished working on this exercise you must submit your work by running give:
give cs1521 test07_line_char line_char.s
weekly test question:
MIPS -How Long?
line_length.s
, a MIPS assembler program that reads a line of input and then
prints 42.
1521 spim -f line_length.s Loaded: /home/cs1521/share/spim/exceptions.s Enter a line of input: Hello Line length: 42Add code to
line_length.s
to make it equivalent to this C program which reads a line and
prints its length:
// read a line and print its length
#include <stdio.h>
// line of input stored here
char line[256];
int main(void) {
printf("Enter a line of input: ");
fgets(line, 256, stdin);
int i = 0;
while (line[i] != 0) {
i++;
}
printf("Line length: ");
printf("%d", i);
printf("%c", '\n');
return 0;
}
For example:
1521 spim -f line_length.s Loaded: /home/cs1521/share/spim/exceptions.s Enter a line of input: Hello Line length: 6 1521 spim -f line_length.s Loaded: /home/cs1521/share/spim/exceptions.s Enter a line of input: i MIPS you Line length: 11 1521 spim -f line_length.s Loaded: /home/cs1521/share/spim/exceptions.s Enter a line of input: good bye Line length: 9
When you think your program is working you can
autotest
to run some simple automated tests:
1521 autotest line_lengthWhen you are finished working on this exercise you must submit your work by running give:
give cs1521 test07_line_length line_length.s
weekly test question:
MIPS - Palindromic?
palindrome.s
, a MIPS assembler program that reads a line of input and then
prints 2 lines.
1521 spim -f palindrome.s Loaded: /home/cs1521/share/spim/exceptions.s Enter a line of input: Hello not palindrome palindromeAdd code to
palindrome.s
to make it equivalent to this C program which reads a line and
prints whether it is a palindrome or not.
// read a line and print whether it is a palindrom
#include <stdio.h>
// line of input stored here
char line[256];
int main(void) {
printf("Enter a line of input: ");
fgets(line, 256, stdin);
int i = 0;
while (line[i] != 0) {
i++;
}
int j = 0;
int k = i - 2;
while (j < k) {
if (line[j] != line[k]) {
printf("not palindrome\n");
return 0;
}
j++;
k--;
}
printf("palindrome\n");
return 0;
}
For example:
1521 spim -f palindrome.s Loaded: /home/cs1521/share/spim/exceptions.s Enter a line of input: kayak palindrome 1521 spim -f palindrome.s Loaded: /home/cs1521/share/spim/exceptions.s Enter a line of input: canoe not palindrome 1521 spim -f palindrome.s Loaded: /home/cs1521/share/spim/exceptions.s Enter a line of input: madamimadam palindrome 1521 spim -f palindrome.s Loaded: /home/cs1521/share/spim/exceptions.s Enter a line of input: abcdecba not palindrome
When you think your program is working you can
autotest
to run some simple automated tests:
1521 autotest palindromeWhen you are finished working on this exercise you must submit your work by running give:
give cs1521 test07_palindrome palindrome.s
Submission
You can run give multiple times. Only your last submission will be marked.
Don't submit any exercises you haven't attempted.
If you are working at home, you may find it more convenient to upload your work via give's web interface.
Remember you have until Wednesday 01 January 00:00 to complete this test.
Automarking will be run by the lecturer several days after the
submission deadline for the test, using test cases that you haven't
seen: different to the test cases
autotest
runs for you.
(Hint: do your own testing as well as running
autotest
)
Test Marks
After automarking is run by the lecturer you can view it here the resulting mark will also be available via via give's web interface or by running this command on a CSE machine:
1521 classrun -sturec
The test exercises for each week are worth in total 1 marks.
The best 6 of your 8 test marks for weeks 3-10 will be summed to give you a mark out of 9.