
Assignment
Deadline: 30-12-11 section 04
31-12-11 section 8
Write a program containing all of the following functions. Design a user
friendly menu and proper messages for your program. [20 marks]
Question 1
Write a logical (i.e. Boolean) valued function which takes a single integer parameter, and returns
"True" if and only if the integer is a prime number between 1 and 1000 (note that 1 is not usually
counted as a prime number). Test your function by calling it from an appropriate "driver"
program with different inputs.
Hints: (i) if a number is not prime, it has at least one prime factor less than or equal to its
square root, (ii) (32 x 32) = 1024 and 1024 > 1000.
Question 2
Write a function "print_pyramid(...)" which takes a single integer argument "height" and
displays a "pyramid" of this height made up of of "*" characters on the screen. Test the function
with a simple "driver" program, which should be able to reproduce the following example
output:
This program prints a 'pyramid' shape of
a specified height on the screen.
how high would you like the pyramid?: 37
Pick another height (must be between 1 and 30): 6
Question 3
5) Write a program containing a function which prints a table listing the number of occurrences
of the lower-case characters 'a' to 'z' in a char array of length 50
CHARACTER OCCURRENCES
a 38
b 5
c 35
d 7
e 58
f 8
g 8