Revision Programs

Set 8

Electricity Bill: Slab Calculation

1.1. Sequence Construct

  1. Input name of customer, consumer number, previous reading and present reading. Find number of units used, electricity charge and print a bill. The charge is Rs. 2.50 per unit.

2. Conditional Construct: Selection Statement

2.1. if

  1. Input previous reading and present reading. Find the units used, electricity charge and print a bill. If the units is above 40 then the charge is Rs. 2.50 per unit. (For others no charge). Use simple if.

2.2. if else

  1. Input previous reading and present reading. Find the electricity charge and print the bill.
    For the first 40 units the charge is Rs. 2.50 per unit. For remaining units Rs. 4.00 per unit.

2.3. if else if else

  1. Input previous reading and present reading. Find electricity charge and print a bill.
    For the first 40 units the charge is Rs. 2.50 per unit.
    Next 40 units Rs. 4.00 per unit.
    For remaining units Rs. 6.00 per unit.

2.4. Nested if else if else

  1. Input number of units and category. Find electricity charge. The calculation is given below:
    Number of units Domestic (D) (Rs. per unit) Business (B) (Rs. per unit)
    For first 40 units 2.50 3.50
    Next 40 units 4.00 5.00
    Remaining units 6.00 7.00

2.5. if After if else

  1. Input previous reading and present reading. Find electricity charge and print a bill.
    For the first 40 units charge is Rs. 2.50 per unit.
    For remaining units Rs. 4.00 per unit.
    For Electricity Board employees no charge.

2.6. switch case

  1. W a m d p: Input category as choice and units. Find electricity charge. Calculation is given below:
    Number of units Domestic (D) (Rs. per unit) Business (B) (Rs. per unit)
    For first 40 units 2.50 3.50
    Next 40 units 4.00 5.00
    Remaining units 6.00 7.00

3. Iterative Construct (Loop):

3.1. for

  1. Input n subscribers’ names and number of units. Find electricity charge and print a bill for each subscriber. Also find total collection.
    For first 40 units charge is Rs. 2.50 per unit.
    Remaining units Rs. 4.00 per unit.

3.2. do while

  1. Input names of some subscribers and their number of units. Find electricity charge and print a bill for each subscriber. Also find total collection.
    For the first 40 units the charge is Rs. 2.50 per unit.
    Remaining units Rs. 4.00 per unit.
    The program continues as long as user wishes.

4.1. S D Array:

  1. Input n subscribers’ consumer numbers, names and number of units into three arrays. Find electricity charge of each subscriber and store them into another array. Input a search number; print the details of the subscriber. Nnumbers are not sorted.
    For first 40 units charge is Rs. 2.50 per unit.
    Remaining units Rs. 4.00 per unit.

4.2. D D Array

  1. Initialize integers to a 4 x 4 matrix. Display the left and right diagonals simultaneously and find average of them together.

5.1. Methods

Overloaded Methods

  1. W a p using overloaded methods void charge() to find followings:
    1) Find electricity charge for Domestic use
    First 40 units: 2.50 per unit. Next 40 units: 4.00 per unit: Remaining: 6.00 per unit
    2) Find electricity charge for Business use
    First 40 units: 4.50 per unit. Next 40 units: 6.00 per unit: Remaining: 8.00 per unit

6.1. Constructor

  1. Define a class ElectricityBill. Data members / Instance variables: name, unit, charge.
    Member methods: 1) input() - to input name and units.
    2) compute() – to find elecricity charge:
    First 40 units: 4.50 per unit. Next 40 units: 6.00 per unit: Remaining: 8.00 per unit
    3) print() – to print the bill. Write main() also.