NADRA is an organization used to store info of Pakistani citizens, you are a computer programmer and your
Manager given you as task to store the cnic, name, father name, city of birth and date of birth. Write a class
personal info that has five attributes given above. It has a member function to input and a member function to
display the elements. Create another class Passport that inherits personal info class. It has additional attributes
of passport number, date of issue and date of expiry. It also has member functions to input and display its
data members.
#include <iostream>
#include <string>
using namespace std;
class personaInfo // Base class
{
private:
int cnic;
string name;
string fatherName;
string cityOfBirth;
string dateOfBirth;
public:
// For setting(Taking input) attributes
void setAttributes()
{
cout << "Enter cnic: ";
cin >> cnic;
cout << "Enter name: ";
cin >> name;
cout << "Enter father name: ";
cin >> fatherName;
cout << "Enter city of birth: ";
cin >> cityOfBirth;
cout << "Enter date of birth: ";
cin >> dateOfBirth;
}
// For printing (outputting) the attributes
void getAttributes()
{
cout << "cnic: " << cnic << endl;
cout << "Name: " << name << endl;
cout << "Father name: " << fatherName << endl;
cout << "City of birth: " << cityOfBirth << endl;
cout << "Date of birth: " << dateOfBirth << endl;
}
};
// Derived class
class Passport : public personaInfo
{
private:
int passportNumber;
string dateOfIssue;
string dateOfExpiry;
public:
void SetAttributes() // For getting passportNumber, dateOfIssue, dateOfexpiry variables from user
{
cout << "Enter passport number: ";
cin >> passportNumber;
cout << "Enter date of issue: ";
cin >> dateOfIssue;
cout << "Enter date of expiry: ";
cin >> dateOfExpiry;
}
void GetAttributes()
{
cout << "Passport Number: " << passportNumber << endl;
cout << "Date of issue: " << dateOfIssue << endl;
cout << "Date of expiry: " << dateOfExpiry << endl;
}
};
int main()
{
Passport ob1;
ob1.setAttributes(); // Method for getting inputs of attributes from user for ob1 object
ob1.getAttributes(); // Method for pritning the attributes of ob1 object
}
Comments
Leave a comment