Exercise 1

Write a program that computes and prints all the prime numbers below 100. Reminder: prime numbers are integers greater than one with no factors other than
themselves and one.

Exercise 2

Write a program that accepts seat reservations and cancellations for a single performance in a theatre, accepting requests from the keyboard and printing information to the screen. The theatre has 50 seats, numbered from 0 to 49. The program should operate as follows:-

The program should loop, each loop performing the following steps:

  1. Prompt the user to type either 'a' or 'c' to add or cancel a reservation.
  2. Read keyboard input. If neither 'a' nor 'c' is entered, prompt again.
  3. If 'a' is entered, request the number of seats required. If enough seats are still available, identify the seat(s) to be reserved. Always use the lowest numbered seats available. Print the numbers of the seats allocated along with a reservation number, so that the reservation can be identified later for the purposes of cancellation. If there are not enough seats, print an error message.
  4. If 'c' is entered, request the reservation number and locate the seats reserved under that reservation number. Mark the seats as available again. If the reservation is not found, print an error message.

Optional extra: when a reservation added, first check whether the seats can be reserved as a single contiguous block.

Exercise 3

Write a program to multiply a vector by a matrix. As an example, try to compute

   (2 3 4) ( 8)
   (5 6 7) ( 9)

for which the correct answer is

    ( 83)

Use integer or floating point arithmetic as you prefer.

NOTE: write the program so that it is easy to change the size of the matrix & vector, i.e. use for loops, and #define or const declarations to specify the dimensions.

Exercise 4

Implement a doubly-linked list module using the Structures in the notes (see week 2 supplementary). Change the type of DataT to a string type able to hold strings up to 20 characters long. Rename IntLLT to StrLLT.

Implement the constructor and destructor functions

  StrLLT Cons(void);


  void Dest ( StrLLT list );

Add an additional function

  void Add ( StrLLT list, char *s );

that adds a link to the start of the list with string s as its data. Hint: use malloc() to create the new link.

Then write a function

  void PrintList ( StrLLT list );

to print all the strings contained in the list.

Write a small main() function to test your functions, such as

   int main ( int argc, char *argv[] )
      StrLLT list;

      /* construct empty list of strings */
      list = Cons();

      /* add some strings to the list */
      Add ( list, "Fluff" );
      Add ( list, "badger" );
      Add ( list, "boa constrictor" );

      /* print contents of list */
      PrintList ( list );

      /* destroy list */
      Dest ( list );

      /* we've finished */
      return 0;

which should print out

boa constrictor