Program Based on Classes Constructer and Inheritance

#include <iostream>

using namespace std;

class Voter

{

private:

string name;

int age;

public:

/*

*This is default constructor

*this will set name to "Uknonwn"

*and age to 0

*doesn't return anything

*/

Voter ()

{

string x;

int y;

}

//getter

string getName()

{

return name;

}

int getAge()

{

return age;

}



//setter

void setName(string);

void setAge(int);



//to check voter is aligible for voting or not

void isAligible();



};




void Voter :: setName(string x)

{

name=x;

//cout << "Enter the name : " << x << endl;

}




void Voter :: setAge(int y)

{

age=y;

//cout << "Enter age : " << y << endl;

}




void Voter :: isAligible()

{

if(age < 18)

{

cout << name << " is not eligible for voting" << endl;

}

else if (age >= 18)

{

cout << name << " is eligible for voting" << endl;

}

}




int main()

{

Voter a;

//a.getName();

a.setName("Mohit");

//a.getAge();

a.setAge(21);

a.isAligible();



return 0;

}

Comments