Comp102 Practical 1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

UNIVERSITY OF KWAZULU-NATAL

COMP102: Compute Programming


Practical 1: Gentle Introduction

Wednesday, 31 July 2024

Question 1: Fast but not Furious


Write a program that prompts a user to enter the current velocity of a vehicle, the
current acceleration, and the amount of time it accelerates for. Your program should
then calculate the final velocity of the vehicle and display it on the console.
Output
Enter initial velocity: 10
Enter acceleration: 2
Enter time period: 5
The final velocity is 20 m/s

Question 2: Simple Interest


The final amount to be paid on a loan when simple interest is used is calculated
using the following formula:

𝐴 = 𝑃 (1 + 𝑟𝑡)
where:
• 𝐴 is the final amount,
• 𝑃 is the initial principal amount,
• 𝑟 is the annual interest rate,
• 𝑡 is time in years.
Write a program that prompts the user to enter the initial amount, interest rate and
time. The program must then calculate the final amount and display it to the user.

Question 3: Reverse Integer


Write a program that prompts a user to enter a three-digit integer. Your program
should then reverse that integer and display it on the console as shown below.
Output
Enter a three-digit integer: 135
Reversed integer: 531

1
Question 4: Currency Breakdown
Write program that prompts a user for an amount in Rands, and then breaks it down
into the corresponding Rand denominations with counts.
For example, if the amount R1 274,01, the program should output:

Output
Two hundreds: 6
One hundreds: 0
Fifties: 1
Twenties: 1
Tens: 0
Coins: 4
Cents: 1

Note that the coins are only broken down into cents and other coins, e.g. R1, R2, R5
are grouped into a coins bucket and all cent coins, e.g. 2c, 5c; are grouped into a
cents bucket.
-

You might also like