You can find some materials for the Comp. Science C2S3 course on this page.


Oleksandr Romanko, room ITB/116, ext. 27248

Tutorials

Friday, 10:30-11:20, BSB/244

C2S3 course page

Reference Materials

The C Library Reference Guide

Downloads

TextPad Editor
Borland C++ Builder
Turbo C++ version 1.01
Turbo C version 2.01

Tutorial 1

Materials
Setting up Borland C++ 5.5 Command Line Compiler and TextPad
How to produce hard copy of a C program output?
Using the Borland 5.5 Compiler and command-line tools
TextPad Tips for Borland C++ Command Line Tools and Turbo Debugger

Files
bcc55.bat - Batch file to run C programs from TextPad editor.
file-coins.c - Test C program.

Tutorial 2

We will discuss problems from the Assignment #1 as well as usage of different compilers (Turbo C and Borland C) to compile C programs.

Tutorial 3

Tutorial 3 will be devoted to solutions of the Assignment #1 and problems from the Assignment #2.
Assignment #1 Solutions

Tutorial 4

You can pick up your Assignment#1 in the room ITB/101 starting from Thursday 10:00 a.m.

Suggestions for the Assignment #2:
Problem 1
You can use the expression (int)(NUMBER+0.5) to round a real NUMBER to the nearest integer..
Problem 2

  • Your program should work for all dates between January 1, 1 and December 31, 3000.
  • Firstly, choose the base day (day for which you know the day of the week). Hint:December 31, 3000 is Wednesday, January 1, 1 is Sunday (if I claculated it correctly).
  • Secondly, calculate the number of days between the day you entered and your base day. Hint:A leap year has 366 days, non-leap year - 365.
  • Substract the number of full weeks multiplyed by 7 from the calculated number. The resulting number will be between 0 and 6 and you can easily determine the day of the week.

  • Problem 3
    You can use not only srand(), rand() combination to generate random numbers, but randomize() and random() functions as well. randomize() initializes the random number generator with a random value. random(N) returns an integer random number from 0 to N-1.

    Tutorial 5

    Suggestions for the Assignment #3:
    Problem 3
    You can use the array of strings:

  • Enter each word (string) into an array
  • Sort the array
  • Count occurrences of each word

  • Alternatively, array of structures can be used:
  • Each structure has a string and an integer counter for the number of word occurrences
  • For each new word, search the structure for the word
  • Increment the count if word is there or insert new element if the word is not there
  • Sort the results (here you need to sort the array of numbers, not strings) and output it

  • Probably, you would like to use strlwr() function to convert uppercase letters in a string to lowercase.

    Tutorial 6

    Suggestions for the Assignment #3:
    Problem 1
    A function that prints a string of characters in standard set notation should produce the output {b,c,d,a} for the string "bcda". Probably it is good idea to print characters in the ascending order {a,b,c,d}. First, you need to check whether a set is valid ("abc" is valid, but "bcca" is not). Function EMPTY should check whether a string contains at least one character (""={} is empty, but "a"={a} is not) and return 1 if it is empty and zero otherwise (or vice versa). Function EQUAL compares two strings ("abc" is equal to "bca" as in standard set notation it is the same set {a,b,c}). UNION returns the union of two strings (UNION("k#c","cfd")={k,#,c,f,d}). SUBSET checks whether one string is subset of another ("Ab"={A,b} is subset of "kAlMb"). MEMBER function should check whether a character is member of a set ('a' is member of "bca" set).

    Tutorial 7

    Suggestions for the Assignment #3:
    Problem 5
    You can use pointer to a function to pass trigonometric or polynomial function as an argument for your MAX() function: float MAX(float (*f_trig)(float), int n, int m, ...). Alternatively, you can pass a number (f=1, 2, 3, 4) to the function MAX(int f, int n, int m,...) which denotes a mathematical function you want to use. In this case mathematical function can be implemented as switch() operator (case 1: y=x^3-x; case 2: y=sin(x);...). If pointers to functions were not covered at lectures by now, you can use the second method.


    © 2002, Oleksandr Romanko