-
Notifications
You must be signed in to change notification settings - Fork 0
/
14.cpp
86 lines (65 loc) · 1.77 KB
/
14.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
@Author: Amritanshu Sikdar
Session: 2018-'19
Repository: https://github.com/amritanshusikdar/CS30PracticalQuestion
*/
// Program to calculate electricity bill and print in given format
#include<conio.h>
#include<fstream.h>
#include<stdio.h>
#include<iomanip.h>
struct elecBill
{
char name[20];
int currReading;
int prevReading;
};
void line();
void main()
{
clrscr();
int i, consumed;
float amount;
elecBill bill;
fstream file("CSEB.txt", ios::in | ios::out);
cout << "Enter customer details: \n";
for(i=0; i<5; i++)
{
cout << "Name: ";
gets(bill.name);
cout << "Current reading: ";
cin >> bill.currReading;
cout << "Previous Reading: ";
cin >> bill.prevReading;
cout << endl;
file.write((char*) &bill, sizeof(bill));
}
// Printing the Bill
line();
cout << "Consumer's_Name\tCurrent_Reading\tPrevious_Reading Consumed_Unit Bill_Amount" << endl;
line();
file.seekg(0, ios::beg);
while(file.read((char*) &bill, sizeof(bill)))
{
consumed = bill.currReading - bill.prevReading;
if(consumed <= 100)
amount = consumed * 2.0;
else if(consumed > 100 && consumed <= 200)
amount = consumed * 3.25;
else if(consumed > 200 && consumed <= 300)
amount = consumed * 4.75;
else if(consumed > 300)
amount = consumed * 5.25;
cout << setw(10) << bill.name << '\t' << setw(10) << bill.currReading << '\t' << setw(10) << bill.prevReading
<< '\t' << setw(10) << consumed << '\t' << setw(10) << amount << endl;
}
line();
file.close();
getch();
}
void line()
{
for(int i=0; i<79; i++)
cout << '-';
cout << endl;
}