Week 08 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 Week 9 Thursday 17:00.
- Weekly tests are designed to act like a past paper - to give you an idea of how well you are progressing in the course, and what you need to work on. Many of the questions in weekly tests are from past COMP1511 final exams.
- You must treat the first hour as a real exam - no access to external help from other people or the internet.
- Once the first hour has finished, you should take note of how far you got, which parts you didn't understand, and ask questions to clarify your understanding with course staff or on the course forum.
- Failure to follow the above instructions will result in a lower quality learning experience and ultimately a lower mark in the final exam.
- Once the first hour has finished, you may use the internet, get help from other people, and still submit your solutions afterwards.
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.
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 reflect on how you went in this hour, and discuss with your tutor if you have concerns.
weekly test question:
Print out command line arguments in lower case
Write a C program, string_to_lower_args.c
, which reads command line arguments
then prints them out. When it prints out, it will convert all upper case letters to lower
case.
Note: If there are any characters that are not Upper Case letters, they do not need to be converted.
Note: The apostrophe ' character causes problems when trying to print it out. There will be no tests using an ' in this activity.
The output from your program should look exactly like this:
dcc string_to_lower_args.c -o string_to_lower_args ./string_to_lower_args Hello World! hello world! ./string_to_lower_args Its Over 9000! its over 9000! ./string_to_lower_args KAMEHAMEHA kamehameha
Need a Hint?
There's a way to decide if characters are upper case if they're between 'A' and 'Z'. They can then be treated as numbers to convert to lower case.
Otherwise, there is a C library called ctype.h that might have some useful functions!
When you think your program is working you can autotest
to run some simple automated tests:
1511 autotest string_to_lower_argsWhen you are finished working on this exercise you must submit your work by running give:
give cs1511 test08_string_to_lower_args string_to_lower_args.c
weekly test question:
Create a struct
Download struct_create.c here, or copy it to your CSE account using the following command:
cp -n /web/cs1511/20T1/activities/struct_create/struct_create.c .
Your task is to add code to this function in struct_create.c:
// create an instance of the struct and return a pointer to it
struct numbers *struct_create(int a, int b) {
// PUT YOUR CODE HERE (you must change the next line!)
}
struct numbers { int first; int second; };
struct_create should take two integers as input and return a pointer to a struct numbers variable that it has created. Its first input should be stored in the first field and its second input should be stored in the second field.
For example if the integers are:
int a = 1; int b = 2;
and the function is called like this:
struct numbers* n = struct_create(a, b);n will now be pointing at a struct that has n->first == 1 and n->second == 2.
Assumptions/Restrictions/Clarifications.
struct numbers cannot be edited. It must be used as it is.
struct_create should call malloc() to allocate memory.
struct_create should not print anything. It should not call printf.
Your submitted file may contain a main function. It will not be tested or marked.
When you think your program is working you can autotest
to run some simple automated tests:
1511 autotest struct_createWhen you are finished working on this exercise you must submit your work by running give:
give cs1511 test08_struct_create struct_create.c
weekly test question:
Use structs and pointers to represent Pokemon evolution
Download evolve_pokemon.c here, or copy it to your CSE account using the following command:
cp -n /web/cs1511/20T1/activities/evolve_pokemon/evolve_pokemon.c .
Your task is to add code to these functions in evolve_pokemon.c:
// Create a pokemon
struct pokemon *create_pokemon(char name[MAX_NAME_SIZE]) {
// PUT YOUR CODE HERE (you must change the next line!)
return NULL;
}
// Link a pokemon to another that it evolves into
void evolve_pokemon(struct pokemon *base, struct pokemon *evolution) {
// PUT YOUR CODE HERE
}
// Print out the evolution of a pokemon
void print_evolution(struct pokemon *p) {
// PUT YOUR CODE HERE
}
struct pokemon { char name[MAX_NAME_SIZE]; struct pokemon *evolution; };
create_pokemon should allocate memory for a pokemon struct, set its name to the input string and return a pointer to it. The evolution pointer should be set to NULL.
evolve_pokemon should take two pointers to pokemon. It should set the second as the evolution of the first.
print_evolution should take a pointer to a pokemon. It should print out the name of the pokemon, then the name of what it evolves to and the name of what that pokemon evolves to until it reaches a pokemon that doesn't evolve into anything else. It should print each name on its own line.
For example if we create two pokemon using the strings "Pikachu" and "Raichu"
struct pokemon *pikachu = create_pokemon("Pikachu"); struct pokemon *raichu = create_pokemon("Raichu");
Then we set pikachu's evolution to be raichu and print the evolution
evolve_pokemon(pikachu, raichu); print_evolution(pikachu);
The output of this will be:
Pikachu Raichu
Assumptions/Restrictions/Clarifications.
struct pokemon cannot be edited. It must be used as it is.
create_pokemon should call malloc() to allocate memory.
evolve_pokemon should not print anything. It should not call printf.
print_evolution should continue printing names on separate lines until it reaches a NULL evolution then it will stop.
Your submitted file may contain a main function. It will not be tested or marked.
When you think your program is working you can autotest
to run some simple automated tests:
1511 autotest evolve_pokemonWhen you are finished working on this exercise you must submit your work by running give:
give cs1511 test08_evolve_pokemon evolve_pokemon.c
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 Week 9 Thursday 17: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:
1511 classrun -sturec
The test exercises for each week are worth in total 1 marks.
The best 7 of your 8 test marks for weeks 3-10 will be summed to give you a mark out of 7.