You are on page 1of 2

DeKUT ~ Mechanical & Mechatronics Departments.

SMA 2276 Computer Programming II ~ Assignment I


Requirement:
a) The work should be done in groups not exceeding four members each
b) No handwritten work will be accepted
c) Deadline: 26th October, 2018

Questions

1) Write a C++ program that prompts the user to enter two positive integer numbers and tests whether the
larger integer is exactly divisible by the smaller one. In the process the program should check that the
input values are both varied (greater than zero) & then establish which one of them is large.

2) Write a C++ program that creates a 'guessing game' and which, generates a random number from 1 and
10. The computer then asks if the next number generated will be higher or lower. If the user guesses
correctly, a new number is generated, and the user gets to guess again. If he guesses incorrectly, the game
ends. A score is maintained - i.e. 1 point for each correct guess that is made.

3) Write a complete C++ program to calculate the area of a triangle, rectangle or circle. The program
requires the user to enter the name of the figure, and using a decision making statement(s) to decide:
• If the figure is a triangle then ask for base and height values to input.
• If the figure is a rectangle the ask for length and breath values to input
• If the figure is a circle then ask for the radius values to input
The program should display the output on the screen and should enable the user to re-enter choice for at
most three times incase a wrong selection is entered

4) Using nested loops, write a C++ program that produces the following output.

&&&&&&
* &* * * *
* * &* * *
* * * &* *
* * * * & *
&&&&&&

5) Write a C++ program that will read 3 values for the capital (float) rate of interest (float) and the number
of years (integer). Define a function to read values from the keyboard.
Your program should compute the values of the capital with the compound interest added over the given
period of years. Each year’s interest is counted as: -
INTEREST=CAPITAL+=INTEREST RATE;
The interest is then added to the capital by:
CAPITAL +=INTEREST;
So as to give the value for the capital for the next year. Print out the values for the interest and capital
for the year up to the end of the period. Your program should allow the user to repeat the calculation as
long as the user wishes. The output should take the format below: -
The Original Sum is 420.25 at 12.25% for 5 years.
1 |Page
Year Interest Accumulated Capital Sum
……………………………………………………………………………………...
1 56.28 506.53
2 63.32 569.85
3 71.23 641.08
4 83.13 721.21
5 90.15 811.37

Do you wish to continue? (Y/N)

6) Write a C++ program that incorporates three functions subtraction, addition and operation. The
subtraction and addition accepts two integer parameters and are used to return the added and subtracted
values respectively. The operation function accepts two integer parameters and a pointer to a function
and which is used to call the pointed function that returns the computed value accordingly, and which is
then returned to the main function to be displayed. The main function declares two pointers sum and
minus to the functions addition and subtraction respectively and then calls the operation function twice,
each with respective arguments.

7) Write a C++ program that uses an array to generate and display the table shown below;

1
2 2
3 3 6
4 4 8 12
5 5 10 15 20

8) A company distributes 10 different items around Nairobi through its 5 salesmen in Nairobi. Using
dynamic arrays, write a C++ program to input a salesman name and the corresponding sales made by
each of the salesman for each of the item. The program should then output each of the salesman’s name,
sales, total sales as well as grand total using the format shown below.
Name Item1 Item2 Item3 Item3 Item4 Item5 TotalSales

Brian 20 50 25 10 0 15 120
Joan 45 55 10 25 5 30 170
….
….
….
GrandTotal xx

2 |Page

You might also like