[go: up one dir, main page]

0% found this document useful (0 votes)
13 views9 pages

DSU - Electricity Bill Calculator Using C

Uploaded by

noahsus589
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)
13 views9 pages

DSU - Electricity Bill Calculator Using C

Uploaded by

noahsus589
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
You are on page 1/ 9

Electricity Bill Calculator using C

Shravani ajabe :- 15
-----------------------------------------------------------
Gausiya shaikh:-09
------------------------------------------------------------
Shruti Kapure :- 13
-----------------------------------------------------------
Sharda patil :- 25
-----------------------------------------------------------

prof. mrs. Archana Sahu


Annexure-II
Report on Developing an Electricity Bill Calculator using C

1.0 Brief Description:-

Structures:
Used to bundle related data under a single name (e.g.,
ElectricityBill structure).
Fields include customer details, meter readings, and calculated
consumption.
Enhances readability and maintainability.
Arrays of Structures:
Efficiently store multiple customers' data.
Provides a scalable way to manage electricity bills for a larger
database.
Linked Lists:
Allow dynamic and flexible management of electricity bill
records.
Support efficient insertion and removal of customer data.
Control Structures:
for and while loops help process inputs, calculate bills, and
generate outputs.
Work seamlessly with the data structures to automate billing
logic.
Conclusion:
Using structures, arrays, and linked lists in C for an Electricity Bill
Calculator ensures efficient data management and scalability
while maintaining code clarity.
4o
Step by step descriptive logic to compute electricity bill.

1. Inputunitconsumedbycustomerinsomevariablesayunit.

2. Ifunitsconsumedlessorequalto50units.Thenamt=unit*0.50.

3. Ifaunitconsumedmorethan50unitsbutlessthan100units.Thenaddthefirst50
units amount i.e. 25 to the final amount and compute the rest 50 units amount.
Which is given by amt = 25 + (unit-50) * 0.75. I have used units-50, since I already
calculated the first 50 units which is 25.

4. Similarlychecktherestoftheconditionsandcalculatethetotalamount.

5. Aftercalculatingthetotalamount.Calculatethesurchargeamounti.e.sur_charge=
total_amt * 0.20. Add surcharge amount to net amount. Which is given by net_amt =
total_amt + sur_charge.

Developing an Electricity Bill Calculator using C involves implementing a suitable data


structure to efficiently manage and manipulate the relevant information. One fundamental
data structure that can be employed for this purpose is a struct. A struct allows you to create
a user-defined data type that can encapsulate different types of variables under a single
name. In the context of an electricity bill calculator, you can define a struct to represent the
details of each customer, such as their name, address, consumption details, and the
calculated bill.

struct Customer {

char name[50];

char address[100];

int

unitsConsumed;

};float billAmount;

In the above example, a struct named Customer is defined with fields like name, address,
unitsConsumed, and billAmount. The name and address fields are character arrays to store
the customer's personal information, while unitsConsumed represents the electricity units
consumed, and billAmount holds the calculated bill for the customer.
To efficiently manage multiple customer records, an array of structs can be used. For
instance, you can declare an array of Customer structs to store information for multiple
customers:

struct Customer customers[MAX_CUSTOMERS];

Here, MAX_CUSTOMERS represents the maximum number of customers your program can
handle, and the array of customers holds individual customer records.

Next, you can implement functions to input customer details, calculate the electricity bill,
and display the results. Functions can be designed to operate on the Customer struct or the
array of Customer structs, allowing for modularity and ease of maintenance.

void inputCustomerDetails(struct Customer *customer) {

// Code to input customer details

float calculateBill(struct Customer *customer) {

// Code to calculate electricity bill

void displayBill(struct Customer *customer) {

// Code to display the bill details

These functions can then be called in the main program to interactively manage customer
data and calculate bills.

In summary, using a struct and an array of structs in C provides an organized and modular
approach to developing an electricity bill calculator. The struct encapsulates customer
details, and the array allows for the efficient management of multiple customer records.
Functions can be designed to handle various aspects of the program, promoting code
reusability and readability.
Code -
#include <stdio.h>

// Function to calculate the electricity bill

float calculateBill(int units) {

float totalBill;

if (units <= 50) {

totalBill = units * 0.50;

} else if (units <= 150) {

totalBill = 25 + ((units - 50) * 0.75);

} else if (units <= 250) {

totalBill = 100 + ((units - 150) * 1.20);

} else {

totalBill = 220 + ((units - 250) * 1.50);

return totalBill;

int main() {

int units;

printf("Enter the total units consumed: ");

scanf("%d", &units);

float bill = calculateBill(units);

printf("Electricity Bill: %.2f\n", bill);

return 0;

}
In the above code, the calculateBill function calculates the total electricity bill based on the
number of units consumed. The main function prompts the user to enter the total units
consumed and then calls the calculateBill function to calculate and display the electricity bill.

The billing rates used in this example are as follows:

● Forthefirst50units,therateis41.38rsperunit.

● Forthenext100units(51-150),therateis62.08rsperunit.

● Forthenext100units(151-250),therateis99.32rsperunit.

● Forunitsabove250,therateis124.15rsperunit.

Feel free to modify the rates or add additional functionality as per your requirements.
Output -
https://msbtestore.com/
Conclusion

In conclusion, the development of an Electricity Bill Calculator using the C programming


language has been successfully accomplished. The objective of this project was to create a
user-friendly tool that allows individuals to calculate their monthly electricity bills based on
their consumption. The development process followed a systematic approach,
encompassing requirements analysis, design, implementation, testing, and documentation.

Throughout the project, we have identified and analyzed the functional and non-functional
requirements of the calculator. By leveraging programming concepts, such as variables, data
input/output, calculations, and conditional statements, we were able to design and
implement an efficient solution.

The calculator provides a user-friendly interface, prompting users to enter the meter
readings for the previous and current months. By calculating the units consumed, applying
appropriate tariff rates, and factoring in additional charges or discounts, the calculator
accurately determines the total cost of the electricity bill. The final bill is displayed to the
user, ensuring transparency and ease of understanding.

In conclusion, the development of the Electricity Bill Calculator using C has been a fruitful
endeavor, offering a reliable and user-friendly solution to calculate electricity bills accurately.

You might also like