Professional Documents
Culture Documents
pay packets for its employees. The program should read the total amount to be paid, and print the
number of £20, £10 and £5 notes required, and the amount of £1, 50p, 20p, 10p, 5p, 2p and 1p coins
needed. It is union requirement that every pay pocket should contain at least 40p in coins, and at least
one £5 note. Subject to this restriction, the pay pocket should contain as few coins and notes as
possible. Note that £1=100p.
Write a program to provide the required information, and test it with a wide variety of cases, including
those with a total pay of £125.39 and £65.40.
EXERCISE 2 : Write a program that will determine how much income tax a person pays, given the
following basis for taxation :
EXERCISE 3 : Write a program that reads a pH value between 1.0 and 14.0 and prints a message
giving the colour of a certain chemical indicator for that pH value. The program should print an
intermediate colour (orange, green, purple, or pink) if the pH is in the critical range.
Colour pH range of Colour
Indicator in acid colour change in base
Methyl orange Red 3.1 – 4.4 Yellow
Bromthymol blue Yellow 6.0 – 7.6 Blue
Litmus Red 4.5 – 8.3 Blue
Phenolphthalein Colourless 8.3 – 10.0 Red
EXERCISE 4 : If the lengths of the sides of a triangle are a, b, and c, then the area of the triangle
can be computed from Heron's formula, which is
𝑎𝑟𝑒𝑎 = √𝑠 (𝑠 − 𝑎)(𝑠 − 𝑏)(𝑠 − 𝑐)
where s is one half the sum of the lengths of the sides of the triangle.
Write a program that asks for and reads the lengths of the three sides, then determines whether those
three sides can form a triangle. If they can, the program should display the area. If not, it should say
they do not form a triangle.
The sum of two sides must add up to be greater than the length of the remaining third side, i.e., a + b
> c ; b + c > a ; and a + c > b
EXERCISE 5 : Write a program that accepts a positive integer as its input and informs the user of all
the following:
Information: All years which are perfectly divisible by 4 are leap years except for century years (years
ending with 00) which is a leap year only it is perfectly divisible by 400. For example, years like 2012,
2004, 1968 are leap years but 1971, 2006 are not leap years. Similarly, 1200, 1600, 2000, 2400 are
leap years but 1700, 1800, 1900 are not.