Programming Fundamentals
Information
- This page contains additional revision exercises for week 06.
- These exercises are not compulsory, nor do they provide any marks in the course.
- You cannot submit any of these exercises, however autotests may be available for some them (Command included at bottom of each exercise if applicable).
Exercise — individual:
String Manipulation (Revision Session Exercise)
Copy the file(s) for this exercise to your CSE account using the following command:
1511 fetch-revision 06
Implement the different functions listed in the string_manipulation.c
file.
No autotests are provided for this question.
Examples
dcc struct_tutorial.c -o struct_tutorial ./struct_tutorial Hello, World! Goodbye Goodbye is before World.
Exercise — individual:
Simple Frogger (Revision Session Exercise)
Copy the file(s) for this exercise to your CSE account using the following command:
1511 fetch-revision 06
Complete the program simple_frogger.c
, which is a simple version of the classic Frogger arcade game.
The game should start by printing a 9 x 9 map, to be built as follows:
- The Top Row alternates between house
|^|
and grass-
. - Next 3 rows are water
~
, where logs-_-
and alligatorsA
can be added later. - Next row is grass
-
. - Next 3 rows is road
=
, where carsC
can be added later. - Bottom row is grass
-
.
The game then prompts the user to:
- Enter a column to place Frogger
!F!
on. - Enter the row, column, and length of 3 logs in the water. These will be used to get Frogger across the river as it cannot jump onto the water.
- Enter the type, row, and column of 3 enemies which can be
- Alligators (in the water)
- Cars (on the road)
Once these elements have been added to the map, Frogger can start moving through the map using:
u
to move upd
to move downl
to move leftr
to move right
Frogger wins if it makes it to a house tile |^|
.
Frogger loses if it goes into the water ~
, or on an alligator A
or car C
.
No autotests are provided for this question.
Examples
dcc simple_frogger.c -o simple_frogger ./simple_frogger Welcome to the simple game of Frogger! |^| - |^| - |^| - |^| - |^| ~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - - - - - - - - =========================== =========================== =========================== - - - - - - - - - Please enter frogger's starting column: 4 |^| - |^| - |^| - |^| - |^| ~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - - - - - - - - =========================== =========================== =========================== - - - - !F! - - - - Enter 3 logs: 1 2 4 2 5 3 3 4 2 Enter 3 enemies. Type + row + col: 1 5 3 1 7 4 2 2 4 |^| - |^| - |^| - |^| - |^| ~~~~~~-_--_--_--_-~~~~~~~~~ ~~~~~~~~~~~~ A -_--_--_-~~~ ~~~~~~~~~~~~-_--_-~~~~~~~~~ - - - - - - - - - ========= C =============== =========================== ============ C ============ - - - - !F! - - - - Enter movement: u Game over! dcc simple_frogger.c -o simple_frogger ./simple_frogger Welcome to the simple game of Frogger! |^| - |^| - |^| - |^| - |^| ~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - - - - - - - - =========================== =========================== =========================== - - - - - - - - - Please enter frogger's starting column: 5 |^| - |^| - |^| - |^| - |^| ~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - - - - - - - - =========================== =========================== =========================== - - - - - !F! - - - Enter 3 logs: 1 2 4 2 5 3 3 4 2 Enter 3 enemies. Type + row + col: 1 5 3 1 7 6 2 2 4 |^| - |^| - |^| - |^| - |^| ~~~~~~-_--_--_--_-~~~~~~~~~ ~~~~~~~~~~~~ A -_--_--_-~~~ ~~~~~~~~~~~~-_--_-~~~~~~~~~ - - - - - - - - - ========= C =============== =========================== ================== C ====== - - - - - !F! - - - Enter movement: u |^| - |^| - |^| - |^| - |^| ~~~~~~-_--_--_--_-~~~~~~~~~ ~~~~~~~~~~~~ A -_--_--_-~~~ ~~~~~~~~~~~~-_--_-~~~~~~~~~ - - - - - - - - - ========= C =============== =========================== ===============!F! C ====== - - - - - - - - - Enter movement: u |^| - |^| - |^| - |^| - |^| ~~~~~~-_--_--_--_-~~~~~~~~~ ~~~~~~~~~~~~ A -_--_--_-~~~ ~~~~~~~~~~~~-_--_-~~~~~~~~~ - - - - - - - - - ========= C =============== ===============!F!========= ================== C ====== - - - - - - - - - Enter movement: u |^| - |^| - |^| - |^| - |^| ~~~~~~-_--_--_--_-~~~~~~~~~ ~~~~~~~~~~~~ A -_--_--_-~~~ ~~~~~~~~~~~~-_--_-~~~~~~~~~ - - - - - - - - - ========= C ===!F!========= =========================== ================== C ====== - - - - - - - - - Enter movement: u |^| - |^| - |^| - |^| - |^| ~~~~~~-_--_--_--_-~~~~~~~~~ ~~~~~~~~~~~~ A -_--_--_-~~~ ~~~~~~~~~~~~-_--_-~~~~~~~~~ - - - - - !F! - - - ========= C =============== =========================== ================== C ====== - - - - - - - - - Enter movement: u |^| - |^| - |^| - |^| - |^| ~~~~~~-_--_--_--_-~~~~~~~~~ ~~~~~~~~~~~~ A -_--_--_-~~~ ~~~~~~~~~~~~-_-!F!~~~~~~~~~ - - - - - - - - - ========= C =============== =========================== ================== C ====== - - - - - - - - - Enter movement: u |^| - |^| - |^| - |^| - |^| ~~~~~~-_--_--_--_-~~~~~~~~~ ~~~~~~~~~~~~ A !F!-_--_-~~~ ~~~~~~~~~~~~-_--_-~~~~~~~~~ - - - - - - - - - ========= C =============== =========================== ================== C ====== - - - - - - - - - Enter movement: u |^| - |^| - |^| - |^| - |^| ~~~~~~-_--_--_-!F!~~~~~~~~~ ~~~~~~~~~~~~ A -_--_--_-~~~ ~~~~~~~~~~~~-_--_-~~~~~~~~~ - - - - - - - - - ========= C =============== =========================== ================== C ====== - - - - - - - - - Enter movement: l |^| - |^| - |^| - |^| - |^| ~~~~~~-_--_-!F!-_-~~~~~~~~~ ~~~~~~~~~~~~ A -_--_--_-~~~ ~~~~~~~~~~~~-_--_-~~~~~~~~~ - - - - - - - - - ========= C =============== =========================== ================== C ====== - - - - - - - - - Enter movement: u Game won!
Assumptions/Restrictions/Clarifications
- Error checking is not needed. You can assume only valid inputs will be given.
- Apart from Frogger, the map elements will not move during the game.
Exercise — individual:
CS Calculator Style (Revision Session Exercise)
Copy the file(s) for this exercise to your CSE account using the following command:
1511 fetch-revision 06
Although this cs_calculator.style.c
program runs properly, the style is horrendous! Please help us fix up the style.
No autotests are provided for this question.