Project Final Term PF
Project Final Term PF
#include <fstream>
#include <cstring>
struct Customer {
char c_name[20];
int c_id;
float price;
};
struct Bill {
int b_id;
int cid;
char name[20];
float price;
int unit;
};
int customer_id() {
int a;
ifstream file("cus.txt");
if (!file) {
a = 1;
} else {
file >> a;
a++;
file.close();
return a;
}
file.close();
ofstream outfile("cus.txt");
outfile << a;
outfile.close();
return a;
}
int bill_id() {
int y;
ifstream file("bi.txt");
if (!file) {
y = 1;
} else {
file >> y;
y++;
file.close();
return y;
}
file.close();
ofstream outfile("bi.txt");
outfile << y;
outfile.close();
return y;
}
void add_customer() {
ofstream file("cust.txt", ios::app);
Customer c;
cout << "\nEnter customer details:\nName: ";
cin.getline(c.c_name, 20);
c.c_id = customer_id();
file.write(reinterpret_cast<char*>(&c), sizeof(c));
file.close();
}
void generate_bill() {
int find, flag = 0;
ifstream ptr("cust.txt");
ofstream ptr1("bill1.txt", ios::app);
Customer c;
Bill b;
cout << "\nBill has been generated successfully.\nYour bill id is " << b.b_id;
ptr1.write(reinterpret_cast<char*>(&b), sizeof(b));
break;
}
}
if (flag == 0) {
cout << "\nError! No such customer with id no. " << find << " exists.";
}
ptr.close();
ptr1.close();
}
void display_bill() {
int flag = 0, billid, custid;
ifstream ptr1("bill1.txt");
Bill b;
cout << "\nEnter bill id whose bill you want to display: ";
cin >> billid;
if (flag == 0) {
cout << "\nError! No such customer id no. " << custid << " OR bill no. " << billid << "
exists.";
}
ptr1.close();
}
void delete_bill() {
int flag = 0, billid;
ifstream ptr("bill1.txt");
ofstream temp("temp.txt");
Bill b;
cout << "\nEnter bill id whose bill you want to delete: ";
cin >> billid;
ptr.close();
temp.close();
if (flag == 0) {
cout << "\nError! No such bill with id no. " << billid << " exists.";
}
remove("bill1.txt");
rename("temp.txt", "bill1.txt");
}
int main() {
char username[20], password[20];
if (strcmp(username, "admin") == 0) {
if (strcmp(password, "12345") == 0) {
cout << "\nWelcome _____ Login successful";
} else {
cout << "\nInvalid password";
exit(0);
}
} else {
cout << "\nUsername is invalid";
exit(0);
}
int choice = 1;
while (choice != 5) {
cout << "\n**************************************" << endl;
cout << " Electricity Bill Calculator" << endl;
cout << "**************************************" << endl;
switch (choice) {
case 1:
cin.ignore();
add_customer();
break;
case 2:
generate_bill();
break;
case 3:
display_bill();
break;
case 4:
delete_bill();
break;
case 5:
break;
default:
cout << "\nInvalid Choice...!";
cout << "\nPress any key to continue..";
cin.ignore();
break;
}
}
return 0;
}