Lab Manual for Object Oriented Programming
(LAB-03)
( Constructors and Destructors)
Lab 3: Constructors and Destructor
Introduction
Programming that you studied in the previous semester does not strongly support programming practices
like encapsulation and data hiding. In fact these features are almost nonexistent in sequential
programming. Object Oriented Programming is purely based on these practices and enforces these
practices through various techniques. In this regard access specifiers play a very important role because
they are the first line of defense in secure programming. This lab is designed to teach three very basic yet
essential concepts of OOP namely access specifiers, constructor and destructors. Access specifiers
provide a technique through which we can restrict access to data members and member functions. After
enforcing access it is important to reduce our reliance on too many member functions. Constructors offer
a very attractive and easy to implement technique through which we can take steps call procedures
whenever an object is created. The use of constructors is preferred over the use of member functions
because constructors are called automatically and hence they can invoke further functions whereas simple
member functions have to be called sequentially and explicitly one by one every time an object is created.
Similarly this lab also focuses on the use of destructors that are called whenever an object goes out of
scope. In this the lab the students will be familiarized with the use of access specifiers, constructors and
destructors.
Objective of the Experiment
After completing this lab the student should be able to:
Clearly understand the purpose and importance of access specifiers
Develop a class by correctly using/ enforcing access specifiers
Differentiate between the public and private access specifiers
Understand the importance of constructors
Understand the importance of destructors
Use a basic constructor
Use a basic destructor
Concept Map
Constructors
A constructor is a function that is automatically called when an object is created. This function can
exhibit the regular behavior of any function except that it cannot return a value. The reason why
constructors are needed is that unlike regular functions which need to deliberately called, a constructor
will be automatically called when an object is created. Every constructor has a body from where we can
call regular member function a very important question which is often asked is that how does the
compiler know that the constructor function needs to be called automatically? The answer is very simple.
A constructor is a function that has the same name as the class. Whenever an object is created the
compiler searches for a function having the same name as the class i.e. the constructor. Given below is a
sample code that shows the class constructor. Generally the constructor is defined as public. Also the
constructor can be overloaded like a regular member function. An important point regarding a
constructor is that it cannot return a value. In fact writing the keyword void is strictly prohibited.
using namespace std;
class myclass
{
private:
int datamember; //Private data member
public: myclass( ); //Class constructor
{
cout<<”Hello you have called the class constructor”;
}
};
void main( )
{ myclass obj; }
Destructors
Constructors are designed to help initialize/ create an object. Destructors on the other hand do exactly
the opposite. Destructors are called whenever an object goes out of scope. When this happens it is
necessary to perform cleanup procedures especially when you have used dynamic memory or you have
been working with pointers in your code. The destructor function can be used to free up memory that
you have allocated or dereference pointers that were referenced. The rules for a destructor are as follows:
They have the same name as the class just simply preceded by a tilde (~)
They can take no arguments
They cannot return anything, not even void
using namespace
std; class myclass
{
private:
int datamember; //Private data member
public: myclass( ); //Class constructor
{
cout<<”Hello you have called the class constructor”;
}
~myclass( ); //Class constructor
{ cout<<”Hello you have called the class destructor”; }
Compilation
After writing the code, compile your code according to the guidelines mentioned. Remove any errors
and warnings that are present in your code.
Executing the Program
A sample output after running the program is shown below. Also run the code with other possible inputs.
LAB TASK
1. Your task is to carefully understand the code provided. Analyze the code and suggest any corrections that may be
needed. There are both syntax and logical errors in the code so consider both when designing the correct solution.
Submit the correct code to the lab instructor.
class student{
int age;
int cnic;
int semester;
char name;
public:
int setall(int a, int c, int s, int sem, char n) const
{
age = a;
cnic = c;
semester = s;
name = n;
}
}
int myclass :: displayall ( ){
cout<<”The entered data is”<<student.data;
}
void main( ){
Student obj; obj::setall( ); obj.displayall( ); obj.setage();
Student anotherobj;
Student::anotherobj::setall();
}
Errors:
Private access specifier is not mentioned.
Wrong data type with name is used.
Wrong use of const.
Incorrect function declaration.
No display function is declared.
Wrong display function is initialized.
Wrong use of obj.
Correct Code:
#include <iostream>
using namespace std;
class Student {
private:
int age;
int cnic;
int semester;
string name; // Changed from char to string for proper name handling
public:
// Setter function to set values
void set(int a, int c, int sem, string n) {
age = a;
cnic = c;
semester = sem;
name = n;
}
// Display function
void display() {
cout << "The entered data is:\n";
cout << "Age: " << age << "\n";
cout << "CNIC: " << cnic << "\n";
cout << "Semester: " << semester << "\n";
cout << "Name: " << name << "\n";
}
};
int main() {
Student obj;
obj.set(25, 93, 2, "Ali");
obj.display();
Student anotherObj;
anotherObj.set(21, 91, 6, "Junaid");
anotherObj.display();
return 0;
}
Output:
2. Create a class “Vehicle” having:
“LisencePlate_No”, “Model_No”, “Type”, and “Color” as private data members.
Parameterized constructor assigning default values to the data members
No-Argument constructor assigning default values to the data members
Default constructor assigning default values to the data members
Public member functions: Register Vehicle, Update Vehicle, Delete Vehicle, and Search Vehicle
NOTE: The values required should be obtained from the user in “void main ()” function and each data
member should have a setter and a getter through which you are required to perform the member function
Code:
#include <iostream>
using namespace std;
class Vehicle {
private:
string licensePlate_No;
string model_No;
string type;
string color;
public:
Vehicle(string lp = "Unknown", string mn = "Unknown", string t = "Unknown", string c = "Unknown") {
licensePlate_No = lp;
model_No = mn;
type = t;
color = c;
}
Vehicle() {
licensePlate_No = "Unknown";
model_No = "Unknown";
type = "Unknown";
color = "Unknown";
}
void setLicensePlate_No(string lp) {
licensePlate_No = lp;
}
void setModel_No(string mn) {
model_No = mn;
}
void setType(string t) {
type = t;
}
void setColor(string c) {
color = c;
}
string getLicensePlate_No() {
return licensePlate_No;
}
string getModel_No() {
return model_No;
}
string getType() {
return type;
}
string getColor() {
return color;
}
void registerVehicle() {
cout << "Registering Vehicle...\n";
cout << "Enter License Plate Number: ";
cin >> licensePlate_No;
cout << "Enter Model Number: ";
cin >> model_No;
cout << "Enter Vehicle Type: ";
cin >> type;
cout << "Enter Vehicle Color: ";
cin >> color;
}
void updateVehicle() {
cout << "Updating Vehicle...\n";
cout << "Enter new License Plate Number: ";
cin >> licensePlate_No;
cout << "Enter new Model Number: ";
cin >> model_No;
cout << "Enter new Vehicle Type: ";
cin >> type;
cout << "Enter new Vehicle Color: ";
cin >> color;
}
void deleteVehicle() {
licensePlate_No = "Deleted";
model_No = "Deleted";
type = "Deleted";
color = "Deleted";
cout << "Vehicle deleted successfully.\n";
}
void searchVehicle(string lp) {
if (licensePlate_No == lp) {
cout << "Vehicle Found:\n";
cout << "License Plate Number: " << licensePlate_No << endl;
cout << "Model Number: " << model_No << endl;
cout << "Type: " << type << endl;
cout << "Color: " << color << endl;
} else {
cout << "Vehicle with License Plate " << lp << " not found.\n";
}
}
};
int main(){
Vehicle vehicle1;
vehicle1.registerVehicle();
cout << "\nVehicle details after registration:\n";
cout << "License Plate: " << vehicle1.getLicensePlate_No() << endl;
cout << "Model No: " << vehicle1.getModel_No() << endl;
cout << "Type: " << vehicle1.getType() << endl;
cout << "Color: " << vehicle1.getColor() << endl;
vehicle1.updateVehicle();
cout << "\nVehicle details after update:\n";
cout << "License Plate: " << vehicle1.getLicensePlate_No() << endl;
cout << "Model No: " << vehicle1.getModel_No() << endl;
cout << "Type: " << vehicle1.getType() << endl;
cout << "Color: " << vehicle1.getColor() << endl;
string searchLicensePlate;
cout << "\nEnter License Plate Number to search: ";
cin >> searchLicensePlate;
vehicle1.searchVehicle(searchLicensePlate);
vehicle1.deleteVehicle();
cout << "\nVehicle details after deletion:\n";
cout << "License Plate: " << vehicle1.getLicensePlate_No() << endl;
cout << "Model No: " << vehicle1.getModel_No() << endl;
cout << "Type: " << vehicle1.getType() << endl;
cout << "Color: " << vehicle1.getColor() << endl;
return 0;
}
3. Create a default constructor and print your name in it. Also create an overloaded constructor that
returns speed and takes one integer parameter and returns it.
- How can you create a default constructor in C++?
- A default constructor in C++ is a constructor that takes no parameters. It is called automatically when an object of
the class is created without providing any arguments.
- Code:
class MyClass {
public:
MyClass() {
// Default constructor
cout << "This is the default constructor!" << endl;
}
};
- In the default constructor, how would you print your name?
- Code:
class MyClass {
public:
MyClass() {
cout << "My name is Capt Ali." << endl;
}
};
- How do you define an overloaded constructor?
- An overloaded constructor is a constructor that has the same name as the class but takes a different number or
types of parameters. It allows multiple ways to initialize an object of a class.
- Code:
-
class MyClass {
public:
int Speed;
MyClass(int spd) {
// Overloaded constructor
speed = spd;
}
};
- For the overloaded constructor, what type should it return, and how many parameters does it take?
- An overloaded constructor in C++ does not return any type (not even void). Constructors are used for
initialization, so they simply initialize the object and don't return anything. The number of parameters it takes
depends on the specific use case.
- Could you provide an example of how to implement an overloaded constructor that takes an integer
parameter and returns it?
CODE:
#include <iostream>
using namespace std;
class Vehicle {
private:
int speed;
public:
Vehicle() {
cout << "My name is Capt Ali" << endl;
}
int Vehicle(int s) {
speed = s;
return speed;
}
};
int main() {
Vehicle vehicle1;
Vehicle vehicle2;
int speed = vehicle2.Vehicle(100);
cout << "The speed of the vehicle is: " << speed << " km/h" << endl;
return 0;
}
4. Create a destructor and integrate it into the above code to show the end of the code
- What is the syntax for creating a destructor in C++?
A destructor in C++ is a special member function that is called automatically when an object goes out of scope or
is explicitly deleted. It is used to clean up resources or perform any necessary finalization tasks.
Code:
~ClassName() {
// Destructor code
}
- How is the name of the destructor related to the class?
The name of the destructor is always the same as the class name, with a tilde ( ~) before it. The destructor is tied to
the class and is used to clean up when an object of that class is destroyed.
class Vehicle {
public:
~Vehicle() {
// Destructor code
}
};
- Can a destructor take arguments?
- No, destructors cannot take any arguments. They have no return type and cannot be overloaded.
- What does the role of a destructor typically involve?
The role of a destructor is to release resources (such as memory, file handles, or other system resources)
when the object is destroyed. It is usually used to:
Free dynamically allocated memory.
Release any other resources acquired during the lifetime of the object.
- How can you integrate the destructor into the provided code to demonstrate the end of the program
execution?
- Code:
#include <iostream>
using namespace std;
class Vehicle {
private:
int speed;
public:
Vehicle() {
cout << "My name is capt Ali." << endl;
}
int Vehicle(int s) {
speed = s;
return speed;
}
~Vehicle() {
cout << "Destructor called. Vehicle object is being destroyed." << endl;
}
void displaySpeed() {
cout << "The speed of the vehicle is: " << speed << " km/h" << endl;
}
};
int main() {
Vehicle vehicle1;
vehicle1.displaySpeed();
Vehicle vehicle2;
int speed = vehicle2.Vehicle(100);
vehicle2.displaySpeed();
cout << "End of program execution." << endl;
return 0;
}
Lab Manual for Object Oriented Programming
(LAB-04)
(Constructor Overloading and Copy Constructors)
Lab 4: Constructor Overloading and Copy Constructors
Introduction
Programming that you studied in the previous semester does not strongly support programming practices
like encapsulation and data hiding. In fact these features are almost nonexistent in sequential
programming. Object Oriented Programming is purely based on these practices and enforces these
practices through various techniques. In this regard access specifiers play a very important role because
they are the first line of defense in secure programming. This lab is designed to teach three very basic yet
essential concepts of OOP namely access specifiers, constructor and destructors. Access specifiers
provide a technique through which we can restrict access to data members and member functions. After
enforcing access it is important to reduce our reliance on too many member functions. Constructors offer
a very attractive and easy to implement technique through which we can take steps call procedures
whenever an object is created. The use of constructors is preferred over the use of member functions
because constructors are called automatically and hence they can invoke further functions whereas simple
member functions have to be called sequentially and explicitly one by one every time an object is created.
Similarly this lab also focuses on the use of destructors that are called whenever an object goes out of
scope. In this the lab the students will be familiarized with the use of access specifiers, constructors and
destructors.
Objective of the Experiment
After completing this lab the student should be able to:
Clearly understand the purpose and importance of access specifiers
Develop a class by correctly using/ enforcing access specifiers
Differentiate between the public and private access specifiers
Understand the importance of constructors
Understand the importance of destructors
Use a basic constructor
Use a basic destructor
Concept Map
Access Specifiers – Public and Private Access
Access specifier also known as access modifier provides a technique for enforcing access control to class
members (data members and member functions). The use of access specifiers enforces encapsulation and
data hiding. C++ provides three access specifiers i.e. public, private and protected. In this lab we will
only cover the public and the private access specifier. The protected specifier is left for future
discussions.
The public access specifier is the one that provides unrestricted access to the class members. While
the private access specifier provides a very strict/ restricted access to class members. All the class
members that are written under the public access can be accessed both inside and outside the class
without any restriction. On the other hand all the class members written as private are accessible inside
the class but are not accessible outside the class. The best and most common way of accessing private
data members is through the use of a public functions.
When we are discussing access specifiers it must be pointed out that by default classes are private
whereas structures are public. Hence if you do not write private then your listed class members are
considered private in a class.
The correct convention for the use of access specifiers is that data members are kept private whereas
functions are kept public. Hence you are providing a public interface for accessing restricted items in a
class.
using namespace
std; class myclass
{
private:
int datamember; //Private data member public:
int memberfun(int); // public member function
};
int myclass :: memberfun (int x) // This function is still public because its prototype is
public
{
datamember=x;
}
void main( )
{
myclass obj;
myclass::datamember=10; //Syntax Error: private member obj.memberfun(10);
}
Constructors
A constructor is a function that is automatically called when an object is created. This function can
exhibit the regular behavior of any function except that it cannot return a value. The reason why
constructors are needed is that unlike regular functions which need to deliberately called, a constructor
will be automatically called when an object is created. Every constructor has a body from where we can
call regular member function a very important question which is often asked is that how does the
compiler know that the constructor function needs to be called automatically? The answer is very simple.
A constructor is a function that has the same name as the class. Whenever an object is created the
compiler searches for a function having the same name as the class i.e. the constructor. Given below is a
sample code that shows the class constructor. Generally the constructor is defined as public. Also the
constructor can be overloaded like a regular member function. An important point regarding a
constructor is that it cannot return a value. In fact writing the keyword void is strictly prohibited.
using namespace std;
class myclass
{
private:
int datamember; //Private data member
public: myclass( ); //Class constructor
{
cout<<”Hello you have called the class constructor”;
}
};
void main( )
{ myclass obj; }
Destructors
Constructors are designed to help initialize/ create an object. Destructors on the other hand do exactly
the opposite. Destructors are called whenever an object goes out of scope. When this happens it is
necessary to perform cleanup procedures especially when you have used dynamic memory or you have
been working with pointers in your code. The destructor function can be used to free up memory that
you have allocated or dereference pointers that were referenced. The rules for a destructor are as follows:
They have the same name as the class just simply preceded by a tilde (~)
They can take no arguments
They cannot return anything, not even void
using namespace
std; class myclass
{
private:
int datamember; //Private data member
public: myclass( ); //Class constructor
{
cout<<”Hello you have called the class constructor”;
}
~myclass( ); //Class constructor
{ cout<<”Hello you have called the class destructor”; }
Copy Constructors
Copy constructors provide a function through which you can create a new object from an existing already created
object. This feature is commonly used in simple programming and hence its need can arise at any time when working
with objects. C++ provides a default copy constructor that will assist in the copying of simple objects. For example
objects that do not use pointers or arrays. Although the default copy constructor will copy any type of object but it is
strongly recommended that the copy constructor be used only for objects that have non pointer data members. The
default copy constructor performs a member by member copy i.e. the copy constructor creates an exact copy where
data members are copied one by one to the new object. Always remember that in copy constructors the original object
is maintained in its original state and the copy changes are only exhibited in the newly created object. In this lab we
will just restrict ourselves to the use of the default copy constructor.
The default copy constructor can be explicitly called as follows:
class obj2(obj1); // Function calling notation
class obj2 = obj1; //Assignment statement notation
Both statements create an object of the class. Of course any of the above statements can be used for copying an object
into another object.
Caution: The copy constructor is always called at the time of creating a new object. If at any time after the creation of
objects you copy contents of one object to the other then the copy constructor is not called. We will discuss more on
this in future lectures.
LAB TASK
TASK 1:
Write a program that creates a class called student. The data members of the class are name and age.
Create a nullary constructor and initialize the class object.
Create a parameterized constructor that can set the values being passed from the main function.
Create a display function called showall( ) which will be used to show values that have been set.
Use the default copy constructor to show that copying of simple objects can be accomplished
through the use of the default copy constructor.
Code:
#include <iostream>
#include <string>
using namespace std;
class Student {
private:
string name;
int age;
public:
Student() {
name = "Unknown";
age = 0;
}
Student(string n, int a) {
name = n;
age = a;
}
void showAll() {
cout << "Name: " << name << endl;
cout << "Age: " << age << endl;
}
Student(const Student &other) {
name = other.name;
age = other.age;
}
};
int main() {
Student student1;
cout << "Student 1 (Using nullary constructor):\n";
student1.showAll();
Student student2("Alice", 20);
cout << "\nStudent 2 (Using parameterized constructor):\n";
student2.showAll();
Student student3 = student2;
cout << "\nStudent 3 (Using default copy constructor):\n";
student3.showAll();
return 0;
}
TASK 2
Write a C++ program for a new ice cream vendor called PopSalon. The management of PopSalon has
decided that they are going to sell their popcorn in 11 different flavors namely: chocolate, English toffee,
salted caramel, caramel, jalapeno, cheese, spiced cheese, plain sated, buttered, salt and pepper, and garlic.
Carefully design the program by observing the following rules.
PopSalon is charging Rs. 100 for small pack, Rs. 250 for medium sized pack, Rs. 500 for large
sized pack and Rs. 750 large size tin pack. Hence you will need a function to determine the size
of the pack and based on that the price. If a user enters option number other than the ones
displayed, your program should display an invalid input message and ask the user to re-enter the
option number
Code:
#include <iostream>
#include <string>
using namespace std;
class PopSalon {
private:
string flavors[11] = {"Chocolate", "English Toffee", "Salted Caramel", "Caramel",
"Jalapeno", "Cheese", "Spiced Cheese", "Plain Salted",
"Buttered", "Salt and Pepper", "Garlic"};
string selectedFlavor;
int packSize;
int price;
public:
void showFlavors() {
cout << "Select a flavor from the following list:\n";
for (int i = 0; i < 11; i++) {
cout << i + 1 << ". " << flavors[i] << endl;
}
}
void selectFlavor(int option) {
if (option >= 1 && option <= 11) {
selectedFlavor = flavors[option - 1];
} else {
cout << "Invalid input! Please select a valid flavor.\n";
}
}
void determinePrice(int size) {
if (size == 1) {
price = 100;
} else if (size == 2) {
price = 250;
} else if (size == 3) {
price = 500;
} else if (size == 4) {
price = 750;
} else {
cout << "Invalid size! Please enter a valid size.\n";
}
}
void displayOrder() {
cout << "\nYour Order Details:\n";
cout << "Flavor: " << selectedFlavor << endl;
cout << "Price: Rs. " << price << endl;
}
};
int main() {
PopSalon vendor;
int flavorChoice, packChoice;
while (true) {
vendor.showFlavors();
cout << "\nEnter the number for your choice of flavor: ";
cin >> flavorChoice;
vendor.selectFlavor(flavorChoice);
if (flavorChoice >= 1 && flavorChoice <= 11) {
break;
}
}
while (true) {
cout << "\nSelect the pack size:\n";
cout << "1. Small (Rs. 100)\n";
cout << "2. Medium (Rs. 250)\n";
cout << "3. Large (Rs. 500)\n";
cout << "4. Large Tin (Rs. 750)\n";
cout << "Enter the number for your desired pack size: ";
cin >> packChoice;
if (packChoice >= 1 && packChoice <= 4) {
vendor.determinePrice(packChoice);
break;
} else {
cout << "Invalid input! Please select a valid pack size.\n";
}
}
vendor.displayOrder();
return 0;
}
Task 3:
Write a program that uses accepts a given Machine Readable Code and using a class stores the following 11 parts of a passport separately after
extraction as private data members:
1. Full Name
2. Passport Number
3. Nationality
4. Gender
5. Date of Birth
6. Country of Issuance (Passport Issuance)
7. Date of Issuance (Passport Issuance)
8. Date of Expiry
9. Citizenship Number
10. Passport Type
Create setters and getters for all the member variables and a public method named display to display the all the data members.
Create three constructors as follows:
1. A nullary constructor that initializes the Citizenship Number as “*****-*******-*”.
2. A parameterized constructor that accepts First Name and Second Name and concatenates them into the data member “Full Name” in
its body.
3. A parameterized constructor that will set Gender, Nationality, and Passport Number as sent in parameters.
Create three objects of the class such as:
First object is initialized with default constructor. The values are then set by calling the setters
Second object is initialized with the constructor that accepts three arguments.
Third object is initialized with the constructor that accepts four arguments.
Then display these data members.
Imp:at last
Modify the class Create a copy constructor to copy a citizenship number. Then in main function call the copy constructor
and observe the outputs.
Code:
#include <iostream>
#include <string>
using namespace std;
class Passport {
private:
string fullName;
string passportNumber;
string nationality;
string gender;
string dateOfBirth;
string countryOfIssuance;
string dateOfIssuance;
string dateOfExpiry;
string citizenshipNumber;
string passportType;
public:
Passport() {
citizenshipNumber = "*****-*******-*";
}
Passport(string firstName, string lastName) {
fullName = firstName + " " + lastName;
}
Passport(string g, string n, string p) {
gender = g;
nationality = n;
passportNumber = p;
}
void setFullName(string name) {
fullName = name;
}
string getFullName() {
return fullName;
}
void setPassportNumber(string pNumber) {
passportNumber = pNumber;
}
string getPassportNumber() {
return passportNumber;
}
void setNationality(string nat) {
nationality = nat;
}
string getNationality() {
return nationality;
}
void setGender(string g) {
gender = g;
}
string getGender() {
return gender;
}
void setDateOfBirth(string dob) {
dateOfBirth = dob;
}
string getDateOfBirth() {
return dateOfBirth;
}
void setCountryOfIssuance(string country) {
countryOfIssuance = country;
}
string getCountryOfIssuance() {
return countryOfIssuance;
}
void setDateOfIssuance(string issuance) {
dateOfIssuance = issuance;
}
string getDateOfIssuance() {
return dateOfIssuance;
}
void setDateOfExpiry(string expiry) {
dateOfExpiry = expiry;
}
string getDateOfExpiry() {
return dateOfExpiry;
}
void setCitizenshipNumber(string cNumber) {
citizenshipNumber = cNumber;
}
string getCitizenshipNumber() {
return citizenshipNumber;
}
void setPassportType(string pType) {
passportType = pType;
}
string getPassportType() {
return passportType;
}
void display() {
cout << "Full Name: " << fullName << endl;
cout << "Passport Number: " << passportNumber << endl;
cout << "Nationality: " << nationality << endl;
cout << "Gender: " << gender << endl;
cout << "Date of Birth: " << dateOfBirth << endl;
cout << "Country of Issuance: " << countryOfIssuance << endl;
cout << "Date of Issuance: " << dateOfIssuance << endl;
cout << "Date of Expiry: " << dateOfExpiry << endl;
cout << "Citizenship Number: " << citizenshipNumber << endl;
cout << "Passport Type: " << passportType << endl;
}
Passport(const Passport &other) {
citizenshipNumber = other.citizenshipNumber;
}
};
int main() {
Passport passport1;
passport1.setFullName("Capt”,”Ali");
passport1.setPassportNumber("A1234567");
passport1.setNationality("Pakistan");
passport1.setGender("Male");
passport1.setDateOfBirth("01-01-1990");
passport1.setCountryOfIssuance("PAK");
passport1.setDateOfIssuance("01-01-2020");
passport1.setDateOfExpiry("01-01-2030");
passport1.setCitizenshipNumber("12345-6789-123");
passport1.setPassportType("Ordinary");
cout << "Passport 1 (Initialized with default constructor):\n";
passport1.display();
Passport passport2("Kanza", "Abideen");
passport2.setPassportNumber("B7654321");
passport2.setNationality("American");
passport2.setGender("Female");
passport2.setDateOfBirth("02-02-1985");
passport2.setCountryOfIssuance("USA");
passport2.setDateOfIssuance("02-02-2018");
passport2.setDateOfExpiry("02-02-2028");
passport2.setCitizenshipNumber("23456-7890-234");
passport2.setPassportType("Diplomatic");
cout << "\nPassport 2 (Initialized with parameterized constructor for Full Name):\n";
passport2.display();
Passport passport3("Female", "Indian", "C9876543");
passport3.setFullName("Alia Bhatt");
passport3.setDateOfBirth("15-03-1995");
passport3.setCountryOfIssuance("India");
passport3.setDateOfIssuance("15-03-2021");
passport3.setDateOfExpiry("15-03-2031");
passport3.setCitizenshipNumber("34567-8901-345");
passport3.setPassportType("Ordinary");
cout << "\nPassport 3 (Initialized with parameterized constructor for Gender, Nationality, and Passport Number):\n";
passport3.display();
Passport passport4 = passport3;
cout << "\nPassport 4 (Using copy constructor to copy Citizenship Number):\n";
passport4.display();
return 0;
}