CCS CSE 2112 Exercise 6
1. Write a program that asks the user for two integers and a character, ‘A’, ‘S’, or ‘M’.
Callone of three functions that adds, subtracts, or multiplies the user’s integers, based
on the character input.
2. Write a program that includes two functions. The first function should ask a
salespersonfor the daily sales and then return this figure to the main program. The
second function should calculate the salesperson’s commission based on the
following rates:
Ksh Rate
0- 999 3%
1000-2,999 3.5%
3000 and above 4.5 %
The value of the calculated commission should be returned to the main program,
whichthen displays it.
3. Write a program that calculates the cost of building a desk. The main( ) function
callsfour other functions. Pass all variables as reference variables for any
variables they receive:
a. A function to accept as input from the keyboard the number of drawers in the
desk. This function returns the number of drawers to the main program.
b. A function to accept as input the type of wood: ‘m’ for mahogany, ‘o’ for
oak, or ‘p’ for pine.
c. A function that receives the drawer number and wood type, and calculates the
cost of the desk based on the following:
Pine desks are
$100.Oak
desks are
$140.
All other woods are $180.
A $30 surcharge is added for each drawer.
This function returns the cost to the main( ) function.
d. A function to display the final price.
4. Write a program that uses an array to store the square of numbers, and displays the
content of the array.
5. Using an array, write a program that generates the first Fibonacci terms and prints
them.
A Fibonacci series is defined as follows;
fib[0]=0
fib[1]=1
fib[i]=fib[i-1]+fib[i-2] for i>=2
6. Write a program which prompts a user for the number of students, and saves it in an
int variable. Prompt the user for the marks of each student and saves in an array. The
program must check the mark is between 0 and 100. Finally, the program displays the
average, minimum, maximum mark and the grade.
7. Write a program that prompts and inputs positive numbers; store them in an array and
calls a function display to output the array elements on the screen.
8. A certain class has 10 students. Each student takes three units, Programming,
Financial Accounting, PC maintenance. Their lecturer has requested you to develop a
simple program for storing the marks scored by each student for the three units. The
program should be able to display a detailed report on the class performance including
minimum and maximum mark of each student, the average per unit, per student and
the average overall performance for the class.
Required:
Write a program that will fulfill the above requirement. Make any other necessary
modification to make it more users friendly.
9. Write a program that uses an array to compute and display a multiplication table like
the one shown below;
* 1 2 3 4
1 1 2 3 4
2 2 4 6 8
3 3 6 9 12
4 4 8 12 16
10. Writes a program that displays the pattern shown below;
* * * *
1 * * *
2 2 * *
3 3 3 *
4 4 4 3
11. Write a program that accepts 10 values from the user at the keyboard and stores
them in an array. Pass the array and its size to a function that determines and displays
the smallestand largest of the 10 values.