#include using namespace std; class Consumer { protected: int id; string name; int prevReading, currReading; public: void getData() { cout << "Enter consumer id: "; cin >> id; cout << "Enter name: "; cin >> name; cout << "Enter previous reading: "; cin >> prevReading; cout << "Enter current reading: "; cin >> currReading; while (currReading < prevReading) { cout << "Current reading cannot be less than previous. Enter again: "; cin >> currReading; } } int units() { return currReading - prevReading; } int getId() { return id; } virtual float bill() = 0; virtual string type() = 0; void showBill() { cout << "\n-------- ELECTRICITY BILL --------" << endl; cout << "Consumer ID : " << id << endl; cout << "Name : " << name << endl; cout << "Type : " << type() << endl; cout << "Units consumed: " << units() << endl; cout << "Bill amount : Rs. " << bill() << endl; cout << "----------------------------------" << endl; } virtual ~Consumer() {} }; class Domestic : public Consumer { public: float bill() { int u = units(); float amt; if (u <= 100) amt = u * 3.5; else if (u <= 300) amt = 100 * 3.5 + (u - 100) * 5.0; else amt = 100 * 3.5 + 200 * 5.0 + (u - 300) * 7.5; return amt + 50; } string type() { return "Domestic"; } }; class Commercial : public Consumer { public: float bill() { int u = units(); float amt; if (u <= 200) amt = u * 7.0; else amt = 200 * 7.0 + (u - 200) * 9.5; return amt + 150; } string type() { return "Commercial"; } }; class Industrial : public Consumer { public: float bill() { return units() * 8.5 + 500; } string type() { return "Industrial"; } }; int main() { Consumer *list[50]; int n = 0, ch, t, id; do { cout << "\n===== Electricity Billing System =====" << endl; cout << "1. Add consumer" << endl; cout << "2. Show all bills" << endl; cout << "3. Search by consumer id" << endl; cout << "4. Exit" << endl; cout << "Enter choice: "; cin >> ch; switch (ch) { case 1: if (n >= 50) { cout << "Limit reached" << endl; break; } cout << "1. Domestic 2. Commercial 3. Industrial" << endl; cout << "Enter type: "; cin >> t; if (t == 1) list[n] = new Domestic; else if (t == 2) list[n] = new Commercial; else if (t == 3) list[n] = new Industrial; else { cout << "Invalid type" << endl; break; } list[n]->getData(); n++; cout << "Consumer added" << endl; break; case 2: if (n == 0) cout << "No records" << endl; for (int i = 0; i < n; i++) list[i]->showBill(); break; case 3: { cout << "Enter consumer id: "; cin >> id; bool found = false; for (int i = 0; i < n; i++) { if (list[i]->getId() == id) { list[i]->showBill(); found = true; } } if (!found) cout << "Consumer not found" << endl; break; } case 4: cout << "Exiting..." << endl; break; default: cout << "Invalid choice" << endl; } } while (ch != 4); for (int i = 0; i < n; i++) delete list[i]; return 0; }