Assignment OOP (2022-AG-8721)
Assignment OOP (2022-AG-8721)
Course: CS-409
University OF Agriculture
Faisalabad Sub-Campus Burewala
Program
EX#15.1:
#include<iostream>
using namespace std;
class Employee{
protected:
int eid,scale;
public:
Employee()
{
eid=-1;
scale=0;
}
void input()
{
cout<<"Enter employee id:"<<endl;
cin>>eid;
cout<<"Enter Scale"<<endl;
cin>>scale;
}
void show()
{
cout<<"Empolyee Id:"<<eid<<endl;
cout<<"Sacle:"<<scale<<endl;
}
};
class manager:public Employee
{
private:
int mid;
char dept[30];
public:
manager()
{
Employee();
mid=0;
}
void input()
{
Employee::input();
cout<<"Enter Manager Id:"<<endl;
cin>>mid;
cout<<"Enter department:"<<endl;
gets(dept);
}
void show()
{
Employee::show();
cout<<"Manager Id:"<<mid<<endl;
cout<<"Department:"<<dept<<endl;
}
};
int main()
{
manager m;
m.input();
m.show();
return 0;
Output:
Enter employee id:
1
Enter Scale:
19
Enter Manager Id:
23
Enter department:
Computer
Empolyee Id:1
Sacle:19
Manager Id:23
Department:Computer
EX#5.2:
#include<iostream>
using namespace std;
class localphone
{
protected:
long ph;
public:
void input()
{
cout<<"Enter Phone no:";
cin>>ph;
}
void show()
{
cout<<"Phone Number="<<ph<<endl;
}
};
class natphone:public localphone
{
protected:
int ccode;
public:
void input()
{
cout<<"Enter City Code:";
cin>>ccode;
localphone::input();
}
void show()
{
cout<<"City Code="<<ccode<<""<<endl;
localphone::show();
}
};
class phone:public natphone
{
private:
int ncode;
public:
void input()
{
cout<<"Enter Country Code:";
cin>>ncode;
natphone::input();
}
void show()
{
cout<<"Country Code="<<ncode<<""<<endl;
natphone::show();
}
};
int main()
{
phone p;
p.input();
p.show();
return 0;
}
Output:
Enter Country Code:+92
Enter City Code:042
Enter Phone no:03131677
Country Code=92
City Code=42
Phone Number=3131677
EX#5.3:
#include<iostream>
using namespace std;
class Teacher
{
protected:
char name[50],address[100];
int age;
public:
void input()
{
cout<<"Enetr Teacher name:"<<endl;
gets(name);
cout<<"Enter Teacher age:"<<endl;
cin>>age;
cout<<"Enter Teacher Address"<<endl;
gets(address);
}
void show()
{
cout<<"Name ="<<name<<endl;
cout<<"Age="<<age<<endl;
cout<<"Address ="<<address<<endl;
}
};
class writer
{
protected:
char name[50],address[100];
int books;
public:
void input()
{
cout<<"Enter Writer Name:"<<endl;
gets(name);
cout<<"Enter Writer Adrress:"<<endl;
gets(address);
cout<<"Enter Number of Books Written;"<<endl;
cin>>books;
}
void show()
{
cout<<"Writer Name:"<<name<<endl;
cout<<"Writer Address:"<<address<<endl;
cout<<"Number of books:"<<books<<endl;
}
};
class scholar:public Teacher,public writer
{
public:
void input()
{
Teacher::input();
writer::input();
}
void show()
{
Teacher::show();
writer::show();
}
};
int main()
{
scholar s;
s.input();
s.show();
return 0;
}
Output:
Enetr Teacher name:
Nadeem
Enter Teacher age:
30
Enter Teacher Address:
Burewala
Enter Writer Name:
Thomas
Enter Writer Adrress:
Street no 9 california
Enter Number of Books Written;
5
Name =Nadeem
Age=30
Address =Burewala
Writer Name:Thomas
Writer Address:Street no 9 california
Number of books:5
EX#5.4:
#include<iostream>
using namespace std;
class Book
{
protected:
int bid;
char bname[50];
float price;
public:
void input()
{
cout<<"Enter Book Id:"<<endl;
cin>>bid;
cout<<"Enter Book Name"<<endl;
gets(bname);
cout<<"Enter Book Price"<<endl;
cin>>price;
}
void show()
{
cout<<"Book Id:"<<bid<<endl;
cout<<"Book Name:"<<bname<<endl;
cout<<"Book Price:"<<price<<endl;
}
};
class writer
{
protected:
char name[50],address[100];
int books;
Book bk[5];
public:
void input()
{
cout<<"Enter Writer Name:"<<endl;
gets(name);
cout<<"Writer Address:"<<endl;
gets(address);
cout<<"Enter Number of Books Written:"<<endl;
cin>>books;
cout<<"Enter Detail Of Five Book:"<<endl;
for(int i=0;i<5;i++)
bk[i].input();
}
void show()
{
cout<<"Writer Name:"<<name<<endl;
cout<<"Address:"<<address<<endl;
cout<<"Number Of Books:"<<books<<endl;
cout<<"Detail of five books:"<<endl;
for(int i=0;i<5;i++)
bk[i].show();
}
};
int main()
{
writer w;
w.input();
w.show();
return 0;
}