You are on page 1of 17

ASSIGNEMENT:

OOP
SUBMITTED TO:
MAM BUSHRA KASHIF
SUBMITTED BY:
SUBHAN AYUB
ROLL:
36577
SEMESTER:
4th
GOVERNMENT COMMUNITY COLLOEGE

PROGRAM NO 01:
#include<iostream>
#include<string.h>
using namespace std;
class student
{
private:
string name, id, email;
public:
student()
{
name = " ";
id = " ";
email = " ";
}
void display(string n, string i, string e)
{
name = n;
id = i;
email = e;
cout << name << endl;
cout << id << endl;
cout << email << endl;
}
student(string n, string i, string e)
{
name = n;
id = i;
email = e;
}
void display2()
{
cout << name << endl;
cout << id << endl;
cout << email << endl;
}
student(const student& s3)
{
name = s3.name;
id = s3.id;
email = s3.email;
cout << name << endl;
cout << id << endl;
cout << email << endl;
}
~student()
{
cout << " Destructor is called here " << endl;
}
};
int main()
{
student s1;
string name, id, email;
cout << " Enter Details for empty constructor: " << endl;
cout << " Enter your name : ";
cin >> name;
cout << " Enter your id : ";
cin >> id;
cout << " Enter Your Email : ";
cin >> email;
cout << "................Employee1............................." << endl;
s1.display(name, id, email);
cout << ".........................Employee2..................." << endl;
student s2("Jawad ","Bc007004005 ","jawad@gmail.com ");
s2.display2();
cout << endl;
cout << "......................Employee3........................." << endl;
cout << " Copy Constructor is being called now " << endl;
student s4("Salman", "mc00500420", "salman@gmail.com");
student s3 = s4;
cout << " Thank You! " << endl;
}
OUTPUT

PROGRAM NO 02:
#include <iostream>
#include <iomanip>
using namespace std;

class shape
{
protected:
double x, y;
public:
virtual void get_data() = 0;
virtual void display_area() = 0;
};

class triangle : public shape


{
public:
void get_data()
{
cout << "Data Entry for Triangle" << endl;
cout <<"Enter base : ";
cin >> x;
cout <<"Enter height : ";
cin>> y;
}

void display_area()
{
double a;
a = 0.5 * x * y;
cout <<"Area of Triangle is : "<<a;
cout << endl;
}
};

class rectangle : public shape


{
public:

void get_data()
{
cout <<"Data Entry for Rectangle : ";
cin >> x;
cout <<"Enter length of two sides :";
cin >>y;
}

void display_area()
{
cout <<"Area of rectangle";
double aor;
aor = x * y;
cout <<"Area of Rectangle is : "<<aor;
cout << endl;
cout << endl;
}
};

void main()
{
triangle t;
rectangle r;
shape* list[2];
list[0] = &t;
list[1] = &r;

int choice;
while (1)
{
cout << " DIFFERENT SHAPES " << endl;
cout <<"Enter 01 FOR Area of Triangle "<<endl;
cout <<"Enter 02 FOR Area of Rectangle"<<endl;
cout <<"Enter 03 FOR EXIT"<<endl;
cout << endl;
cout << "Enter your choice : ";
cin >> choice;
switch (choice)
{
case 1: list[0]->get_data();
list[0]->display_area();
break;
case 2: list[1]->get_data();
list[1]->display_area();
break;
case 3:
exit(0);
default:
cout << "Invalid choice" << endl;
}
}
system("pause");
}
OUTPUT
PROGRAM NO 03:
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
class persondata {
public:
string fn;
string ln;
string age;
void setfn(string N)
{
fn = N;
}
string getfn()
{
return fn;
}
void setln(string L)
{
ln = L;
}

void setage(string A)
{
age = A;
}
string getage()
{
return age;
}

};
class custdata :public persondata {
public:
int cusnum;
bool maillist;
void setter() {
cout << "Enter Cusnum : ";
cin >> cusnum;
}
};
int main()
{
persondata h;
custdata g;
g.setter();
h.setfn("Arslan");
h.setage("20 Year");
cout << "Name 0F a person : " << h.getfn();
cout << endl;
cout << "Age Of a person : " << h.getage();
cout << endl;

cout << endl;


g.setter();
h.setfn("Moeez");
h.setage("21 Year");
cout << "Name 0F a person : " << h.getfn();
cout << endl;
cout << "Age Of a person : " << h.getage();
cout << endl;

cout << endl;


g.setter();
h.setfn("Talha");
h.setage("22 Year");
cout << "Name 0F a person : " << h.getfn();
cout << endl;
cout << "Age Of a person : " << h.getage();
cout << endl;

cout << endl;


g.setter();
h.setfn("Ahsan Baryar");
h.setage("23 Year");
cout << "Name 0F a person : " << h.getfn();
cout << endl;
cout << "Age Of a person : " << h.getage();
cout << endl;

system("pause");
}
OUTPUT

PROGRAM NO 04:
#include<iostream>
using namespace std;
class math
{
private:
int n;
public:
math()
{
n = 0;
}
math(int number)
{
n = number;
}
math operator +(int no)
{
math x;
x.n = n;
x = x.n + no;
return x;
}
math operator -(int no)
{
math x;
x.n = n;
x = x.n - no;
return x;
}
math operator *(int no)
{

math x;
x.n = n;
x = x.n * no;
return x;
}
math operator +(math &no)
{
math x;
x.n = x.n + no.n;
return x;
}
math operator -(math& no)
{
math x;
x.n = x.n - no.n;
return x;
}
math operator *(math& no)
{
math x;
x.n = x.n * no.n;
return x;
}
void display()
{
cout << n << endl;
}
};
int main()
{
math obj;
cout << " adding integer 10 in the object using statement: obj= obj + 10 : ";
obj = obj + 10;
obj.display();
cout << " adding integer 10 in the object using statement: obj= 10 + obj : ";
obj = obj + 10;
obj.display();
cout << " Multiplying object with integer 20 using statement: obj= obj * 20 : ";
obj = obj * 20;
obj.display();
cout << " Multiplying object with integer 20 using statement: obj= 20*obj : ";
obj = obj * 20;
obj.display();
cout << " Subtracting 20 from object using statement: obj= obj - 20 : ";
obj = obj - 20;
obj.display();
return 0;
}
OUTPUT

PROGRAM NO 05:
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
class employ
{
private:
string name;
int courses;
int cr;
int thesis;
int Req;
public:
employ()
{
name = " ";
courses = 0;
cr = 0;
thesis = 0;
Req = 0;
}
void employ1()
{
cout << "Enter Discipline Name : ";
cin >> name;
cout << "Enter Number 0F Course : ";
cin >> courses;
cout << "Enter Credit Hour Per Course : ";
cin >> cr;
cout << "Enter Thesis Credit : ";
cin >> thesis;
Req = courses * cr + thesis;
}
void display()
{
cout << "Discipline Name Is : " <<name<<endl;
cout << "Number 0F Course Is : " <<courses << endl;
cout << "Credit Hour Per Course Is : " << cr << endl;
cout << "Thesis Credit are : " << thesis << endl;
cout << "Number OF Requird Credit Hours For Degree Is : " << Req <<
endl;
cout << endl;
cout << endl;
}
};
int main()

{
employ s;
employ s2;
employ s3;
s.employ1();
cout << endl;
s2.employ1();
cout << endl;
s3.employ1();
cout << endl;
s.display();
s2.display();
s3.display();
system("pause");
}
OUTPUT

You might also like