#include <iostream>
#include <string>
using namespace std;

class InvalidData : public std::exception {
public:
  explicit InvalidData(const std::string& message) : std::exception(message.c_str()) {}
};

class User {
public:
  virtual void validateData() {
    if (age < 18 || age > 55) {
      throw InvalidData("Invalid age. Must be between 18 and 55.");
    }
    if (income < 50000 || income > 100000) {
      throw InvalidData("Invalid income. Must be between Rs. 50,000 and Rs. 1,00000.");
    }
    if (city != "Pune" && city != "Mumbai" && city != "Bangalore" && city != "Chennai") {
      throw InvalidData("Invalid city. Must be Pune, Mumbai, Bangalore, or Chennai.");
    }
    if (!hasFourWheeler) {
      throw InvalidData("Must have a 4-wheeler vehicle.");
    }
  }
protected:
  int age;
  double income;
  string city;
  bool hasFourWheeler;
};

int main() {
  // Create user object
  User user;
  // Read user data
  cout << "Enter age: ";
  cin >> user.age;
  cout << "Enter income: ";
  cin >> user.income;
  cout << "Enter city: ";
  cin >> user.city;
  cout << "Enter 1 if you have a 4-wheeler vehicle, 0 otherwise: ";
  cin >> user.hasFourWheeler;
  // Assign values to user's protected members
  try {
    user.validateData(); // Call virtual function for validation
    // User is eligible, proceed with further steps
    cout << "User is eligible.\n";
  } catch (const InvalidData& e) {
    cerr << "Error: " << e.what() << std::endl;
  }
  return 0;
}

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: