Laraib Shahid Oop Assignment
Laraib Shahid Oop Assignment
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>
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++)
cin>>emp[i] .name;
cin>>emp[i].id;
cin>>emp[i].ADRESS.houseno;
cin>>emp[i].ADRESS.city;
cin>>emp[i].ADRESS.street;
cout<<""<<endl;
cout<<" _______________"<<endl;
cout<<endl;
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:
}
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>
public:
compare(int a):value(a)
{
}
bool operator<(const compare& other) const {
return value < other.value;
}
int main() {
compare item1(10);
compare item2(20);
item1.display();
item2.display();
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>
void enterbookdetails()
{
string a;
string b;
int c;
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)
{
}
}
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
{
}
}
else
{
{
int a;
cout<<endl;
cout<<"------------------------------------------------------------------"<<endl;
}
};
int main()
{
bookmanagements b[4];
return 0;
}