DSU - Electricity Bill Calculator Using C
DSU - Electricity Bill Calculator Using C
Shravani ajabe :- 15
-----------------------------------------------------------
Gausiya shaikh:-09
------------------------------------------------------------
Shruti Kapure :- 13
-----------------------------------------------------------
Sharda patil :- 25
-----------------------------------------------------------
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.
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:
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.
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>
float totalBill;
} else {
return totalBill;
int main() {
int units;
scanf("%d", &units);
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.
● 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
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.