CITS2002 Systems Programming  
 

Unit home

Project 1

help2002

Lecture & Workshop
recordings on LMS

Schedule

FAQ

Unit outline

C textbooks

OS textbooks

Information resources


Extra reading

Past projects

Recent feedback


Working effectively

Look after yourself!

Labsheet 1 - for the week commencing 29th July 2024

This and the following weekly labsheets provide both 'basic' and optional 'advanced' tasks.
The optional advanced tasks, which we'll term chili questions, are prefixed by one or more chilis: 🌶 The more chilis, the more difficult the task.

  • If you're able to complete all of the basic tasks each week, then you're considered to be keeping up with the unit.
  • More advanced programmers should be able to complete a number, if not all, of the advanced tasks.

Preparation

Before commencing this labsheet, please read the following introductory pages:

Next, kick out the cobwebs

A number of students in previous years have indicated that they had difficulties 'getting started' with the first couple of CITS2002 Labsheets. When questioned, they indicated that they hadn't written even a simple program 'for a while' - for some this was since first semester, for some since first year.

So these introductory tasks are just designed to refresh your programming knowledge, and confidence; to get you to the point where you'll again have these skills at your fingertips (some students are even a bit rusty on how to build and run a program).

The tasks are language agnostic, so attempt them using any operating system, any programming language, and any editor you choose (at this stage, they may appear a bit difficult in C). There'll be no sample solutions, but it should be obvious to you if your solution is correct.


Refresher tasks

  1. [integer arithmetic, basic loop] When Australia first adopted decimal currency in 1966, coins had the denominations of 1c, 2c, 5c, 10c, 20c, and a round 50c. If a person purchased something valued at $1 or less, and paid with a $1 note (yes!), write a program to list the coins, and their demoninations, that they should receive as change.

  2. [calling external function] Using your chosen programming language, write a short program to print out today's date and time (example output: Thu Jul 25 08:19:34 2024). The actual format is unimportant.

  3. 🌶 [floating-point numbers] In Lecture-2 we stated that floating-point values are rarely, if ever, used in operating system kernels - primarily because they cannot be represented exactly on contemporary computers and, so, we must use them with great caution, or not at all. In your chosen programming language, write an small program displaying sufficient decimal-points to 'expose' the problem of inaccuracy.

  4. [integer arithmetic, 1D array] Revise (or learn) how to generate a non-negative random integer in your chosen programming language. Saturday Lotto involves drawing 6 unique numbers, between 1 and 45. Write a simple program to choose and display your 6 lucky numbers.

  5. 🌶 [2D array, nested loop] Fill a 2D array of, say, 10x20 integers with non-negative random integers. Without using your language's builtin/standard sort() method/function, print out the second largest value in the array.

If you're interested in more, short, programming challenges, there are many websites providing examples and their solutions in many programming languages:


Labsheet 1 tasks

The following tasks provide a gentle introduction to compiling simple C programs. These tasks can be completed:

  • using Linux (installed natively, booted from a Linux disk partition),
  • using Apple's macOS v14 (Sonoma), or v13 (Ventura) - many improved features and security fixes are provided in these newer versions. or
  • using Windows Subsystem for Linux version-2 (WSL-2) on Microsoft's Windows11 (preferably), or Windows10,

Unless you already know what you're doing (and already have your favourite Linux distribution) or own an Apple Mac, you're encouraged to use the Ubuntu Desktop Linux distribution (installed natively, or run 'inside' WSL-2 on Windows).

Using rotate.c :

rot13
  1. Modify the program to perform rot-3, rotation by 3 characters (or the traditional Caesar-cipher).

  2. Extend the program to print out each character of the ciphered text one per line instead of all the characters on one line.

  3. Extend the program to print out on each line not only the ciphered character, but also the original character too.

  4. Extend the program to print out on each line not only the original and ciphered characters, but also the "position" of the character in the text.

  5. Extend the program to handle both upper-case and lower-case letters.

  6. The program rotate.c requires 4 C-preprocessor #include directives to read the declarations of some standard C functions from C header files. Remove (and eventually replace) each #include line, in turn, to determine which required functions are declared in each file.

  1. 🌶 Extend the program so that it can accept multiple arguments, performing the ciphering process on each argument to the program.

  2. 🌶 Extend the program so that it reads the rotation amount (the amount to rotate each character by) as the first argument to the program. You will need to use the atoi function to convert the text argument into a number.

  3. 🌶 🌶 Extend the program so that all arguments to the program can be either text or numbers. If an argument is text, the text is ciphered using the current rotation amount (initialised to 13). If an argument is a number, the rotation amount changes to this value and all subsequent cipherings (up to the next number argument) use this new rotation amount.

  4. 🌶 🌶 Extend the previous version of the program so that textual arguments can represent files. If a text argument can be opened as a file (see man fopen), perform the ciphering on the contents of the file. Otherwise, treat the arguments as before: if an argument is text, the text is ciphered using the current rotation amount (initialised to 13), or if an argument is a number, the rotation amount changes to this value and all subsequent cipherings (up to the next number argument) use this new rotation amount.

The University of Western Australia

Computer Science and Software Engineering

CRICOS Code: 00126G
Presented by [email protected]