Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PROGRAM: You have to write a C++ Program in which you will have to write a class

ID: 3622755 • Letter: P

Question

PROGRAM:

You have to write a C++ Program in which you will have to write a class ‘Pakistani Citizens’ which has five data members “name, age, CNIC No, province, and domicile” and two data functions getter and setter for each data member e.g setAge() getAge() etc.

Write a second class ‘VotersList’ which inherited the ‘PakistaniCitizens’ class and has “implemented in term of” relationship to pakistaniCitizens.

The ‘VotersList’ class restrict the functionality of setAge() function by override the setAge() function of ‘PakistaniCitizens’ class and check the condition :

If age is greater than 18 then print “Eligible for vote cast”.

If object of VotersList class is initialized with the age less than 18, then it prints a message

“Age is less than 18” and sets the value of age to default.

Explanation / Answer

#include<iostream.h>
class PakistaniCitizens
{
protected:
int age;
private:
char name[30];

int CNICNo;
char provinance[30];
char domicile[30];
public:
void setAge(int tage)
{
     age=tage;
}
int getAge()
{
    return age;
}
};
class VotersList:public PakistaniCitizens
{
public:
void setAge(int tage)
{
    if(tage<18)
    {
      cout<<"Age is less than 18";
      PakistaniCitizens::age=18;
    }
    else
    {
      PakistaniCitizens::age=tage;
    }
}
};
int main()
{
VotersList lst;
lst.setAge(12);
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote