0% found this document useful (0 votes)
11 views3 pages

CPL Program 3

The document outlines a program for calculating electricity charges based on unit consumption with specified rates and conditions. It includes an algorithm, test cases, and viva questions related to the program. Additionally, it presents modification questions for calculating simple interest under different conditions.

Uploaded by

sn0385313
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

CPL Program 3

The document outlines a program for calculating electricity charges based on unit consumption with specified rates and conditions. It includes an algorithm, test cases, and viva questions related to the program. Additionally, it presents modification questions for calculating simple interest under different conditions.

Uploaded by

sn0385313
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

An electricity board charges the following rates for the use of electricity: for the first 200 units

80 paise per unit:for the


next 100 units 90 paise per unit: beyond 300 units Rs 1 per unit. All users are charged a minimum of Rs. 100 as meter
charge . If the total amount is more than Rs 400 ,then an additional surcharge of 15% of total amount is charged .Write
a program to read the name of the user ,number of units consumed and print out the charges.

Algorithm:

Step 1: Start

Step 2: Read Name, Units

Step 3: i) if units is greater than 0 and units are less than equal to 200

charges=units *0.8

ii) then if units is greater than 200 and units are less than equal to 300

charges=200*0.8+(units-200)*0.9

iii) Otherwise

charges=200*0.8+100*0.9+(units-300)*1.0

Step 4: charges=charges+100

Step 5: if charges is greater than 400

charges =charges +(charges*0.15)

Step 6: Display “Name, Units Consumed and Charges”

Step 7: Stop

Test Cases:

Sl no. Test Data Expected Output


1 Name: Sachin Charges: 828.00
Units: 670
2 Name: Rahul Charges: 494.50
Units: 380
3 Name: Sunil Charges: 305.00
Units: 250
4 Name: Ravi Charges: 244.00
Units: 180

Viva Questions:

[Link] Questions
1. What is the data type for string?
2. Write the equation for 200 units consumed.
3. Write the equation for 300 units consumed.
4. What is the syntax of if and if else condition?
5. Write the equation if the amount exceeds Rs. 400.

Modification Questions:

[Link] Questions
1. Calculate the simple interest for a deposit of amount Rs.10000/- for the following conditions:

a. If time is greater than one year and less than three years the rate of interest is 6%.
b. If time is greater than or equal to three years and less than five years the rate of interest is
7.25%.
c. If time is greater than or equal to five years or the rate of interest is 8.75%.
Flowchart:
Program:

#include <stdio.h>
#include <conio.h>
void main()
{
int units;
float charges;
char name[20];
clrscr();
printf(“Enter the name \n”);
scanf(“%s”,name);
printf(“Enter the units consumed\n”);
scanf(“%d”,&units);
if((units> 0)&&(units<=200))
{
charges=units *0.8;
} else if (units> 200)&&(units<=300)
{
charges=200*0.8+(units-200)*0.9;
} else
{
charges=200*0.8+100*0.9+(units-300)*1.0;
} charges=charges+100;
if (charges> 400)
charges =charges +(charges*0.15);
printf(“ name \t units\t charges\t\n”);
printf(“%s \t %d\t %f\t\n”,name,units,charges);
getch();
}

You might also like