<mosaic.cnfolio.com>

Introduction to Algorithms and Programming – ENG421

# ENG421 Practice worksheet 2 – Calculator programs

Academic year **2015/16**

## The online compiler

## Question 1

Write programs to calculate the volume of each shape in the list below:

Read this Wikipedia article to find the formulas to calculate the volume of different shapes:

**Test your program with different input values**.

## Question 2

Write programs to calculate the total parking tariff for each type of input:

Use the parking tariff provided on this website for sample calculations:

**Test your program with different input values**.

## Simple interest

Let P be an initial amount invested at a fixed annual interest rate of R. Let that interest be added just once at the end of an investment duration consisting of N years. Let V be the total value including the investment and interest earned.

*IMAGE NOT AVAILABLE*

## Question 3

Write a program to calculate simple interest and display annual investment values:

**Test your program with different input values**.

## Compound interest

Let P be an initial amount invested at a fixed annual interest rate of R. Let that interest be added at the end of each investment period, which is called compounding. Let N be the number of years during the whole investment duration. Let V be the total value including the investment and interest earned.

*IMAGE NOT AVAILABLE*

## Question 4

Write a program to calculate compound interest and display annual investment values:

**Test your program with different input values**.

- The first textbox is used to write the
**source code**for the C program. - The second textbox is used to type text that is intended to be
**input**for the program when it is running. Leave this box empty when there is no input. - The third box is used to display the
**output**from compiling and running the program. - Click the Run program button to
**compile**and run the C program.

Write programs to calculate the volume of each shape in the list below:

- cube
- cylinder
- prism
- sphere
- pyramid
- cone

Read this Wikipedia article to find the formulas to calculate the volume of different shapes:

Write programs to calculate the total parking tariff for each type of input:

- parking duration in minutes
- start time and end time for parking duration

Use the parking tariff provided on this website for sample calculations:

Let P be an initial amount invested at a fixed annual interest rate of R. Let that interest be added just once at the end of an investment duration consisting of N years. Let V be the total value including the investment and interest earned.

Write a program to calculate simple interest and display annual investment values:

- Read initial investment input value
- Read annual interest rate input value
- Read number of years input value
- Display the investment values based on simple interest at the end of
**years 1 to 5** - Display the final investment value

Let P be an initial amount invested at a fixed annual interest rate of R. Let that interest be added at the end of each investment period, which is called compounding. Let N be the number of years during the whole investment duration. Let V be the total value including the investment and interest earned.

Write a program to calculate compound interest and display annual investment values:

- Read initial investment input value
- Read annual interest rate input value
- Read number of years input value
- Display the amount of compound interest earned at the end of
**years 1 to 5** - Display the final investment value