Professional Documents
Culture Documents
22F-3133
Question 1:
#include <iostream>
#include <string>
class PersonData {
private:
string FirstName;
string LastName;
string Address;
public:
// Accessor functions
string getFirstName() const {
return FirstName;
}
// Mutator functions
void setFirstName(string firstName) {
FirstName = firstName;
}
public:
// Accessor functions
int getCustomerNumber() const {
return CustomerNumber;
}
cout << "Do you want to be on the mailing list? (1 for Yes, 0 for No): ";
cin >> mailingList;
setMailingList(mailingList);
}
}
};
int main() {
CustomerData customer;
return 0;
}
Question 2:
#include <iostream>
#include <string>
class Person {
public:
string name;
int age;
string gender;
Person() {
name = "Mohsin";
age = 22;
gender = "Male";
}
};
Employed() {
name = "Mohsin";
NIC = "35404-0000000000-0";
}
void Employ() {
cout << "Hi, I am Employ from Employed Class" << endl;
}
};
void display() {
cout << "Name: " << name << endl;
cout << "NIC: " << NIC << endl;
}
};
int main() {
BusinessMan businessman;
businessman.Employ();
businessman.display();
Unemployed unemployed;
// Print members of Unemployed
cout << "Name: " << unemployed.name << endl;
cout << "Age: " << unemployed.age << endl;
cout << "Gender: " << unemployed.gender << endl;
return 0;
Question 3:
#include<iostream>
using namespace std;
class vehicle
{
float speed;
float distance;
public:
vehicle()
{
}
void setspeed(float s)
{
speed = s;
}
float getspeed()
{
return speed;
}
void setdistance(float d)
{
distance = d;
}
float getdistance()
{
return distance;
}
float computeduration()
{
float dur = speed / distance;
return dur;
}
};
class wheelvehicle : public vehicle {
int wheels;
public:
wheelvehicle() :vehicle()
{
}
void setwheels(int w)
{
wheels = w;
}
int getwheels()
{
return wheels;
}
};
}
void setwing(int w)
{
wings = w;
}
int getwings()
{
return wings;
}
};
return 0;
}
Question 4:
#include <iostream>
#include <string>
using namespace std;
class Student {
private:
string stdID;
string stdName;
string dept;
public:
Student() : stdID(""), stdName(""), dept("") {}
Student(const string& id, const string& name, const string& department) : stdID(id), stdName(name),
dept(department) {}
void inputData() {
cout << "Enter Student ID: ";
cin >> this->stdID;
cout << "Enter Student Name: ";
cin.ignore(numeric_limits<streamsize>::max(), '\n');
getline(cin, this->stdName);
cout << "Enter Department: ";
getline(cin, this->dept);
}
void displayData() const {
cout << "Student ID: " << this->stdID << endl;
cout << "Student Name: " << this->stdName << endl;
cout << "Department: " << this->dept << endl;
}
~Student() {
cout << "Destroying Student object: " << stdID << endl;
}
};
int main() {
Student obj1;
Student obj2("12345", "Ali Hassan");
Student obj3("23456", "Sheraz Depp", "Computer Science");
Student obj4("Fahad Abbas", "Computer Science");
return 0;
}