Oop Lab 9
Oop Lab 9
Muhammad Junaid
01-135211-053
Zarmeen Fatima
01-135211-086
Eman Shoukat
01-135202-025
Bilal Ahmad
01-135202-022
Lab Journal – Lab 9
Exercise 1
Code :
#include<iostream>
#include<conio.h>
#include<string>
using namespace std;
class faculty
{
protected:
string name;
int id;
public:
faculty();
faculty(string n, int i);
virtual void display();
virtual double salary() = 0;
};
}
visiting_faculty::visiting_faculty()
{
hour_rate = 0;
hour_taught = 0;
}
visiting_faculty::visiting_faculty(int r, int t, string n, int i) :faculty(n, i)
{
hour_rate = r;
hour_taught = t;
}
double visiting_faculty::salary()
{
int total = hour_rate*hour_taught;
return total;
}
void visiting_faculty::display()
{
faculty::display();
cout << "hourly rate :" << hour_rate << endl;
cout << "No of hour taught :" << hour_taught << endl;
}
int main()
{
faculty *ptr1, *ptr2;
permanent_faculty p(5, 55000, "Junaid ", 2018);
visiting_faculty v(4000, 3, "Rafay", 2019);
ptr1 = &p;
ptr2 = &v;
ptr1->display();
cout << "salary of permanent faculty :" << ptr1->salary() << endl;
cout << endl << endl;
ptr2->display();
cout << "salary of visiting faculty :" << ptr2->salary() << endl;
_getch();
return 0;
}
Output:
Exercise 2
Code :
#include<conio.h>
#include<iostream>
#include<string>
using namespace std;
class faculty
{
protected:
string name;
int ID;
public:
faculty()
{
name = " ";
ID = 0;
}
faculty(string n, int id)
{
name = n;
ID = id;
}
virtual void salary() = 0 {}
};
{
name = n;
ID = id;
YearOService = yos;
basicpay = bp;
}
void salary()
{
double salary;
double medicalallow;
double houserent;
visitingfaculty()
{
name = " ";
ID = 0;
phrate = 0;
nht = 0;
}
visitingfaculty(string n, int id, int rate, int NHT)
{
name = " ";
ID = 0;
phrate = rate;
nht = NHT;
}
void salary()
{
double salary;
};
int main()
{
int k = 0;
faculty* fptr1;
faculty* fptr2;
permanentfaculty pf(" Hassaan ", 561, 7, 75000);
visitingfaculty vf(" Hadid ", 725, 6500, 2);
fptr1 = &pf;
fptr2 = &vf;
fptr1->salary();
fptr2->salary();
faculty* arr[50];
char choice;
int l;
string n;
int i;
double h;
double r;
int yos;
double pay;
cout << "Enter Type of Faculy ";
cin >> choice;
do
{
cout << "Enter your name ";
cin >> n;
cout << "Enter your ID ";
cin >> i;
cout << "Enter Years of service ";
cin >> yos;
cout << "Enter Basic Pay ";
if (choice == 'p')
{
arr[k] = new permanentfaculty(n, i, yos, pay);
}
else
{
arr[k] = new visitingfaculty(n, i, rate, hourstaught);
}
k++;
Output :
Exercise 3
Create a class date with data members day, month and year. Class
should have constructors, setDate and display function.
Create a class time with data members hour, minute and second. Class
should have constructors, setTime and display function.
Create a class Flight having information on departure and arrival dates
and times, origin and destination. Date and time should be declared
using composition. The class should have constructors, a function to
input the values of data members and another function to display the
data members.
Derive classes Domestic flight and International flight from the class
Flight. The class Domestic Flight should have a data member to store
the allowed baggage limit while the class International Flight should
have a data member to store whether the Flight is direct or not. Provide
their constructors and override the input and display methods in the
derived classes.
In the main program, declare an array of 5 pointers to Flight, create
objects of Domestic and International Flights and call the input and
display methods.
Code:
Flight.h:
#pragma once
#include<iostream>
#include<conio.h>
#include<string>
class flight
string departure;
string arrival;
string origin;
string destination;
public:
};
int baggage_limit;
public:
void input();
void display();
};
string direct;
public:
void input();
void display();
};
Flight.cpp:
#include "flight.h"
void flight::input()
getline(cin, departure);
getline(cin, arrival);
getline(cin, origin);
getline(cin, destination);
void flight::display()
cout << "departure date and time :" << departure << endl;
cout << "arrival time and date :" << arrival << endl;
void domestic_flight::input()
flight::input();
void domestic_flight::display()
flight::display();
cout << "Allowed baggage limit is :" << baggage_limit << endl;
void international_flight::input()
cin.ignore();
flight::input();
getline(cin, direct);
void international_flight::display()
flight::display();
cout << "flight status direct?? :" << direct << endl;
Source.cpp:
#include "flight.h"
int main()
flight *ptr[2];
domestic_flight df;
international_flight interf;
ptr[0] = &df;
ptr[1] = &interf;
ptr[i]->input();
ptr[i]->display();
_getch();
return 0;
Program the aforementioned exercises and get them checked by your instructor.
+++++++++++++++++++++++++