You are on page 1of 9

OBJECT ORIENTED PROGRAMMING

POST LAB ASSIGNMENT#01

SUBMITTED TO: MA’AM SAMMAR NASEEM

SUBMITTED BY: UMER FAROOQ

REG#: FA20-BEE-210

SEC: BEE-3D
Q#01
Program:
#include <iostream>
using namespace std;
struct Book
{
int Id,Price,Pages;
};
int main()
{
Book B1,B2;
cout<<"Enter the details of Book 1:\n";
cout<<"Enter the ID of Book: ";
cin>>B1.Id;
cout<<"Enter the price Book: ";
cin>>B1.Price;
cout<<"Enter the Pages of Book: ";
cin>>B1.Pages;
cout<<"Enter the details of Book 2:\n";
cout<<"Enter the Id of Book : ";
cin>>B2.Id;
cout<<"Enter the price of Book : ";
cin>>B2.Price;
cout<<"Enter the Pages of Book: ";
cin>>B2.Pages;
if(B1.Price>B2.Price)
{
cout<<"Book 1 is costly:\n";
cout<<"\nDetails of Book 1 are=";
cout<<"\nBook id is:"<<B1.Id<<"\nBook Price is:"<<B1.Price<<"\nBook's Pages
are:"<<B1.Pages<<endl;
}
else
{
cout<<"Book 2 is costly:\n";
cout<<"\nDetails of Book 2 are=";
cout<<"\nBook Id is:"<<B2.Id<<"\nBook Price is:"<<B2.Price<<"\nBook's Pages
are:"<<B2.Pages<<endl;
}
return 0;
}
Result:

Q#02
(a)
Program:
#include<iostream>
using namespace std;
void swap(int,int);
int main()
{
int X , Y ;
cout<<"Enter first number=";
cin>>X;
cout<<"Enter second number=";
cin>>Y;
cout<<"After Swapping =\n";
swap(X , Y);
return 0;
}
void swap(int x,int y)
{
int temp;
temp = x;
x = y;
y = temp;
cout<<" "<<x<<" \n "<<y;
}

RESULT:
Q#02
(b)
Program:
#include<iostream>
using namespace std;
void swap_num(int *a,int *b)
{
int temp ;
temp = *a;
*a = *b;
*b = temp;
}
int main()
{
int A,B;
cout<<"Enter the value of first num="<<endl;
cin>>A;
cout<<"Enter the value of second num="<<endl;
cin>>B;
cout<<"\nBefore swapping of numbers="<<endl;
cout<< A <<"\n"<<B;
swap_num(&A , &B);
cout<<"\nAfter swapping of numbers="<<endl;
cout<< A <<"\n"<<B;
return 0;
}
RESULT:

Q#03
Program:
#include <iostream>
struct Employee
{
int code;
std::string name;
int day,month,year;
};
void display(Employee Emp)
{
std::cout<<"Enter Employee's Code:"<<Emp.code<<std::endl;
std::cout<<"Enter Employee's Name:"<<Emp.name<<std::endl;
std::cout<<"Enter Date of joining (dd-mm-
yyyy):"<<Emp.day<<"/"<<Emp.month<<"/"<<Emp.year<<std::endl;
}
int main()
{
int dd,mm,yyyy;
Employee emp[3];
for(int i=0;i<3;i++)
{
std::cout<<"Enter Employee's Name:";
getline(std::cin,emp[i].name);
if(emp[i].name.empty())
{
getline(std::cin,emp[i].name);
}
std::cout<<"Enter Employee's Code:";
std::cin>>emp[i].code;
std::cout<<"Enter Date of joining(dd-mm-yyyy):";
std::cin>>emp[i].day;
std::cin>>emp[i].month;
std::cin>>emp[i].year;
}
std::cout<<"Enter current date(dd-mm-yyyy):";
std::cin>>dd>>mm>>yyyy;
for(int i=0;i<3;i++)
{
if(yyyy-emp[i].year>=3)
{
std::cout<<"This Employee has completed his tenure "<<std::endl;
display(emp[i]);
}
}
return 0;
}

Result:

You might also like