0% found this document useful (0 votes)
15 views

Laraib Shahid Oop Assignment

Uploaded by

bsee23f33
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Laraib Shahid Oop Assignment

Uploaded by

bsee23f33
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

OBJECT ORIENTED PROGRAMMING

ASSIGNMENT NO 1
SUBMITTED BY:
LARAIB SHAHID
NUM-BSEE-2023-33
SUBMITTED TO:
MAM .NAUREEN

QUESTION NO #1:
Inferring to the concept of structures, Create a program to store and display
information about an employee and their residential addresses using nested
structures. The program should include a structure to represent an address
(house number, street, city) and another structure to represent a employee
(name, code, address). Each employee should have a nested structure
representing their address. Use the designed structure to store information for
5 employees.
CODE:

#include <iostream>

using namespace std;

struct adress

int houseno;

string city;

int street;

};

struct employee

string name;

int id;

adress ADRESS;

};

int main()

employee emp[4];
for(int i=0; i<4; i++)

cout<<"Enter the name of employee "<<endl;

cin>>emp[i] .name;

cout<<"Enter the id of employee "<<endl;

cin>>emp[i].id;

cout<<"Enter the house no;"<<endl;

cin>>emp[i].ADRESS.houseno;

cout<<"Enter the city;"<<endl;

cin>>emp[i].ADRESS.city;

cout<<"Enter the street;"<<endl;

cin>>emp[i].ADRESS.street;

cout<<""<<endl;

cout<<" _______________"<<endl;

cout<<"displaying information "<<endl;

cout<<endl;

for(int i=0; i<4; i++)

cout<<emp[i] .name<<endl;

cout<<emp[i] .id<<endl;

cout<<emp[i].ADRESS.houseno<<endl;

cout<<emp[i].ADRESS.city<<endl;
cout<<emp[i].ADRESS.street<<endl;

return 0;

}
Question 4:

Construct a code using the concept of inheritance to model faculty in a


university. Refer to the figure given below, Design a base class and derived
class with suitable data items and member functions. Provide the output of
your designed code as well.
Sol:
Code:
#include <iostream>

using namespace std;


class Faculty
{
protected:
string name;
int id;
public:

Faculty(string a,int b):name(a),id(b)


{

}
void virtual display()
{
cout<<"NAME:"<<" "<<name<<endl;
cout<<"id:"<<" "<<id<<endl;
}

};
class Professor : public Faculty
{
public:
Professor(string n, int i) : Faculty(n, i)
{
}
void display() override
{
cout << "this is : Professor" << endl;
Faculty::display();
}
};
class AssociateProfessor:public Faculty
{
public:
AssociateProfessor(string n, int i) : Faculty(n, i) {}
void display() override
{
cout << "this is associateprofessor" << endl;
Faculty::display();
}

};
class AssistantProfessor:public Faculty
{
public:
AssistantProfessor(string n, int i) : Faculty(n, i) {}
void display() override
{
cout << "this is Assistant-Professor" << endl;
Faculty::display();
}

};
class Lecturer:public Faculty
{
public:
Lecturer(string n, int i) : Faculty(n, i)
{
}
void display() override
{
cout << "this is Lecturer" << endl;
Faculty::display();
}

};
class LabEngineer:public Faculty
{
public:
LabEngineer(string n, int i) : Faculty(n, i) {}
void display() override
{
cout << "th Lab Engineer" << endl;
Faculty::display();
}

};

int main()
{
Professor professor1("Dr. sajjad", 101);
AssociateProfessor assocProf("Dr. Ahmed", 102);
AssistantProfessor assistProf("Dr.Zulaikha", 103);
Lecturer lecturer("Ms.Noureen", 104);
LabEngineer labEng("Mr. Imtiaz", 105);

professor1.display();
cout << endl;
cout<<"____________________________________"<<endl;
assocProf.display();
cout << endl;
cout<<"____________________________________"<<endl;
assistProf.display();
cout << endl;
cout<<"____________________________________"<<endl;
lecturer.display();
cout<<"____________________________________"<<endl;
cout << endl;
labEng.display();
return 0;
}
OUTPUT:’
QUESTION 3
] Construct a code using the concept of operator overloading that uses the
symbol < (less than), > (greater than), and = (equal to) to compare the value of
a data item of different objects of same class. Provide the output of your
designed code as well;

CODE”
#include <iostream>

using namespace std;


class compare
{
protected:
int value;

public:
compare(int a):value(a)
{

}
bool operator<(const compare& other) const {
return value < other.value;
}

// Overload the > operator


bool operator>(const compare& other) const {
return value > other.value;
}

// Overload the == operator


bool operator==(const compare& other) const {
return value == other.value;
}

void display() const {


cout << "Value: " << value << endl;
}
};

int main() {
compare item1(10);
compare item2(20);

item1.display();
item2.display();

if (item1 < item2)


cout << "item1 is less than item2" << endl;
else if (item1 > item2)
cout << "item1 is greater than item2" << endl;
else if (item1 == item2)
cout << "item1 is equal to item2" << endl;

return 0;
}
OUTPUT:

QUESTION 2:
Inferring to the concept of classes and objects, design books management system in library. Each
book object should have data items, title, author, ISBN numbers, and its availability status. The
member function enter book details, issue a book, and return a book should be des,,,

Code”:
#include <iostream>

using namespace std;


class bookmanagements
{
protected:
string bname;
string author;
int ISBNnumber;
bool available;
public:
bookmanagements():available(true)
{

void enterbookdetails()
{
string a;
string b;
int c;

cout<<"ENTER THE BOOOK NAME:"<<endl;


cin>>a;
cout<<"ENTER THE AUTHOR NAME:"<<endl;
cin>>b;
cout<<"ENTER THE ISBNnumber :"<<endl;
cin>>c;
cout<<"____________"<<endl;

bname=a;
author=b;
ISBNnumber=c;

}
void issue_a_book()
{
int a;
cout<<"enter ISBN no of book do you want to issue"<<endl;
cin>>a;
if(a==ISBNnumber)
{

if(available)
{

cout<<"thank you for issue that book :"<<endl;


available=false;
}
else
{

cout<<"this book is not available:"<<endl;


}

}
}
void return_a_book()
{
int a;
cout<<"enter ISBN no of book do you want to return "<<endl;
cin>>a;
if(a==ISBNnumber)
{
if(!available)
{
available=true;
//cout<<"the book you entered is available:"<<endl;
cout<<"thank you for returning that book :"<<endl;
}
else
{

cout<<"this book is already present "<<endl;

}
}
else
{

cout<<"book not find "<<endl;


}
}
void display()

{
int a;

cout<<"enter ISBN no of book do you want to display it "<<endl;


cin>>a;
if(a==ISBNnumber)
{
cout<<" THE BOOOK NAME:"<<endl;
cout<<bname<<endl;

cout<<"ENTER THE AUTHOR NAME:"<<endl;


cout<<author<<endl;;
cout<<"ENTER THE ISBNnumber :"<<endl;
cout<<ISBNnumber<<endl;
}
else
{
cout<<"this book is not available"<<endl;
}

cout<<endl;
cout<<"------------------------------------------------------------------"<<endl;

}
};
int main()
{
bookmanagements b[4];

for(int i=0; i<=3; i++)


{
b[i].enterbookdetails();
}
b[1].issue_a_book();
b[1].return_a_book();
b[1].display();

return 0;
}

You might also like