Programs Frank Chapter 2
Programs Frank Chapter 2
2. Write a program to calculate the final bill of a customer in a store. The discount structure is as
follows:
Purchase in Discount
Rupees
<=1000 Nil
1001 to <=5000 5%
>5000 10%
Print the total purchase, amount of discount and final bill.
3. Write a program to calculate and print commission of a salesman according to the following criteria:
Sales in Commission
Rupees
0-1000 0%
1001-3000 5%
3001-5000 10%
>5000 15%
In addition, if the total commission paid to the salesman exceeds Rupees 1000, he is paid an
additional bonus of 200.
Input the sales, calculate and print the commission, sales and total commission with bonus.
4. Write a program to calculate the telephone bill of a customer. The billing method is as follows:
a. First 100 minutes at 1.00/call
b. Next 100 minutes at 1.50/call
c. Excess minutes at 2.50/call
5. A worker is paid at the hourly rate (R) for the first 40 hours of work in a week. Thereafter, he is paid
at 1.25 times the hourly rate (R) for the next 16 hours and at 1.5 times the hourly rate (R) for further
hours of work in the week. Taking the number of hours (H) and the rate/hour (R) as inputs, write a
program to calculate weekly wage (W). Print the weekly wage for the employee.
6. Design a class named ‘Investment’, to calculate the amount collected by an investor for different
interest rates based on the formula A=P(1+R/`00)N where A = amount due, P=amount invested, R =
rate of interest and N=number of years.
The bank offers the following rates:
N R%
1 year 8
2 years 8.5
3 years 9
Month Season
2,3,4,5 Summer
6,7,8,9 Monsoon
10,11,12,1 Winter
Write a program that accepts a number for the month and gives the output for the appropriate
season for that month.
8. Write a menu-driven program to find the area of an equilateral triangle, a right-angled triangle, a
scalene triangle respectively.
Hint: Area of an equilateral triangle = √
3 a2
4
bh
Area of a right-angled triangle =
2
a+b+ c
Area of a scalene triangle = √ s ( s−a )( s−b ) ( s−c ) where s =
2
9. Write a program using switch/case to find the volume of a cube, a sphere and a cuboid. For an
incorrect choice, an appropriate message should be displayed.
Hint: Volume of a cube = s×s×s
4
Volume of a sphere = × π ×r ×r × r
3
Volume of a cuboid = l ×b × h
11. Accept three consecutive numbers, a, b, c and check whether they are Pythagorean Triplets or not.
Pythagorean triplets are a2+b2=c2
12. A store sells several items and a discount is given according to the number of items bought.
Quantity Discount
bought
<15 5% of gross
>=15 to <25 10% of gross
>=25 to <40 15% of gross
>=40 20% of gross
Write a program to do the following:
Input : Item number, Quantity bought and Rate
Calculate : Gross amount = Quantity bought * Rate
Output : Net payable = Gross amount – Discount
Item number, Gross amount, Discount, Net payable
13. Input two numbers. Find the greater of the two numbers and then swap the numbers. Do not use a
third variable for swapping.
14. Using the ternary operator, write a program to input a number and check whether the given number
is odd or even.
15. Writer a program to input three integers. Using ternary operator, print the largest of the three
numbers.
16. Write a program to print all prime numbers from 100 to 500.
20. Write a program to accept a number and check whether it is a special number. A special number is
one where the sum of the factorial of the digits is equal to the number input, for example, 145 is a
special number as 5! + 4! +1! = 145
Program Based On Series:
21. S=1+1+2+1+2+3+….n terms
x x x x
23. S= + + + … terms
2! 3! 4! n!
27. S=(1×2)+(2×3)+….(19×20)
28. S=1+(1×2)+2+(1×2×3)+3+….9+(1×2×3×…..10)
1 1 1 1
29. s= + + + +… n terms
2 4 8 16
1 1 1 1
30. s= − + − + … n terms
2 3 4 5