COM1100 Final Exam Program
The Final Examination for COM1100 will cover the following topics.
For a few topics I supply questions which should be perfectly clear
once the relevant material is understood. On the exam, you will be
expected to write short programs that answer similar questions.
Reading:
Chapters 2 (all), 4 (4.1--4.9), 5 (5.1--5.4, 5.6), 6 (6.1--6.3, 6.8),
7 (7.1--7.3), 10 (10.1--10.4)
Also, be sure to look through the "Points to Remember" sections of these
chapters.
Topics:
- Basic arithmetic (+, -, *, /, %). Integer division, remainder.
- Given the duration of a period of time in minutes, express it
in weeks, days, hours and minutes.
- Basic algorithmic constructs: If, For, While.
- Print the first 500 prime numbers.
- Compute the greatest common divisor of two positive integers.
- Input a positive integer N and draw a chessboard of
N x N squares.
- Functions: passing parameters by value and by reference,
returning a value from a function. Local and global variables.
- Suppose a function foo performs a mathematical
computation. How is printing the result different
from returning it?
- What happens to the local variables when a function completes
execution? How can several functions share a variable?
- A computation may produce several answers (e.g. a quadratic
equation most often has two different solutions), but a function
can return only one value. How can a function communicate
several values back to its caller?
- Write the function that returns the nearest perfect square
to a given positive integer. (Example: 9 for 10, 64 for 60.)
- Write a function that swaps the values of its arguments
(which it takes by reference).
- If each task in these questions had to be implemented
as a function, what arguments would it take and what values
would these functions return?
- Arrays.
- Find the sum and the average of an array of numbers.
- Find the largest and the smallest number in an array of
numbers.
- Count the number of times a given character occurs in an array
of characters.
- Sort an array of numbers (any method).
- Given an array of integers (positive or negative), count how
many different numbers occur in it (Hint:
first solve this problem for a sorted array).
- Passing arrays as arguments to functions.
- Do the above array tasks as functions.
- Write a function that compares two arrays (of the same
given length) and decides if they are equal entry-wise.
- Characters. Strings. Old style zero-terminated character arrays
and the new
C++ string class library.
- Write a function that counts the number of vowels in a string.
- Write a function that takes a string and returns the inverted
string (the original string read backwards).
- Write a function that removes all spaces from a given string
and returns the resulting squashed string (without spaces).
- Write a function that takes a string and converts all character
in it to lowercase. Make this function change its actual argument.
- Check if a string is a palindrome (i.e. reads the same way
from left to right and from right to left).
- Binary numbers, negative numbers, signed an unsigned.
- Write 97 as a binary number. Write '1011010' as a decimal
number.
- Assuming that an integer is stored in 4 bytes of memory,
write the "two's complement" representation of -11.
- What is the integer value of '10110101' if understood
as a signed char? As an unsigned char?
- Files.
- Write a program that prompts for the name of a file,
attempts to open it and, if successful, prints the number
of lines, words and characters in it. (This program is called
wc under UNIX.)
- Write a program that counts how many times a given word
occurs in a given file.
- Write a "censor" program that inputs a list of "bad" words and
a filename, and writes another file that contains the original
text with those words removed. (Assume that there is a firm limit
on the number of different "bad" words your censor can cover).
Sergey Bratus
Last modified: Tue Dec 8 00:38:19 EST 1998