CS2200 Intro to Systems and Networks
Homework 0
Fall 2006




Problem 1: Arrays

A. Write a function that takes in a matrix of numbers and compute the average of all the numbers. You may define one dimension of the matrix, but not both.

B. Write a program that reads integers from stdin, the first representing a rate of pay (pence per hour) and the second a number of hours worked. Print out the total pay, with hours up to 40 being paid at basic rate, from 40 to 60 at rate-and-a-half, and above 60 at double-rate. Print the pay as pounds to two decimal places.

Terminate the loop when a zero rate is encountered. At the end of the loop, print out the total pay.

The code for computing the pay from the rate and hours is to be written as a function.

The output format should be similar to the following:

Pay at 200 pence/hr for 38 hours is 76.00 pounds
Pay at 220 pence/hr for 48 hours is 114.40 pounds
Pay at 240 pence/hr for 68 hours is 206.40 pounds
Pay at 260 pence/hr for 48 hours is 135.20 pounds
Pay at 280 pence/hr for 68 hours is 240.80 pounds
Pay at 300 pence/hr for 48 hours is 156.00 pounds
Total pay is 928.80 pounds

The ``program features'' checks that explicit values such as 40 and 60 appear only once, as a #define or initialised variable value. This represents good programming practice.
(100 pence = 1 pound)

Problem 2: Data Types

A. Define a Student struct that will hold their name, GPA, major, home state, and tuition. The majors must be part of an enum (you only have to define CS, Math, Physics, and Biology). If the student is from GA, their tuition must be a short; otherwise, it must be an unsigned long.

B. Write a function that will take an char*[], int[], int[], char[][2] and int[] and return an array of Students

Problem 3: Pointers

A. Write the famous swap function :-).

B. Write a function that takes three char* (a, b, c) in as separate parameters and rotates the values stored so that value a goes to be, b, to c and c to a.

Problem 4: Memory Allocation and Linked Lists

A. Define a linked list node that stores an integer and a pointer to the next in the list. Also define a global variable that is the head of the list.

B. Implement the following functions for the data structure above.

1. Insertion to head.
2. Insertion to tail.
3. Delete all the occurrences of a number specified.
4. Check if a certain number is present in the list.

Problem 5: Bit Shifting

A. Write a function that prints out an 8-bit (unsigned char) number in binary format.

B. Write a function that takes an integer and checks whether it is divisible by 8. Do not use the mod (%) function.

End of CS 2200 Spring 2006 Homework 0