You are on page 1of 11

Name Muhammad Umair

Class BSSE-3B
Roll No 19F-0952
Question 1
#include<iostream>
using namespace std;
#define nameof "your name"
class Employee
{
string Name;
string rank;
float MD;
float HR;
float grossPay;
float basicpay;
friend void display(Employee *E);
friend void Read_record(Employee *E);
friend void Gross_pay(Employee *E);
friend void Annual_Increment(Employee *E);
public:

Employee(){
Name=" ";
rank=" ";
basicpay=0;
MD=0;
HR=0;
grossPay=0;
}
~Employee(){
cout<<"Developed By: "<<nameof;
}
};
void display(Employee *E){
cout<<"Name: "<<E->Name<<endl;
cout<<"Rank: "<<E->rank<<endl;
cout<<"Basic Pay: "<<E->basicpay<<endl;
cout<<"Medical Allowance: "<<E->MD<<endl;
cout<<"House Rent: "<<E->HR<<endl;
cout<<"Gross Pay: "<<E->grossPay<<endl;
}
void Read_record(Employee *E){
cout<<"Enter Name: ";
cin>>E->Name;
cout<<"Enter Rank: ";
cin>>E->rank;
cout<<"Basic Pay: ";
cin>>E->basicpay;
E->MD=E->basicpay*0.6;
E->HR=E->basicpay*(28.9/100);
Gross_pay(E);
}
void Gross_pay(Employee *E){
E->grossPay=E->basicpay+E->MD+E->HR;
}
void Annual_Increment(Employee *E){
E->basicpay=E->basicpay+(E->basicpay*0.2);
}
int main(){
Employee *e=new Employee;
int choice;
do{
cout<<"1. Add record "<<endl;
cout<<"2. Annual increment "<<endl;
cout<<"3. Dispay "<<endl;
cout<<"enter choice: ";
cin>>choice;
switch(choice){
case 1:
Read_record(e);
break;
case 2:
Annual_Increment(e);
break;
case 3:
display(e);
break;
}
}while(choice!=4);
}

Output

Question 2
#include<iostream>
#include<cstdlib>
using namespace std;
class Reciever;
class Channel
{
int frequency;
string datetime;
string port;
public:
void input_detail()
{
cout<<"Enter frequency: ";
cin>>frequency;
datetime="29-11-2020 2:51";
cout<<"Enter Port: ";
cin>>port;
}
void print_detail()
{
cout<<"Frequency: "<<frequency<<endl;
cout<<"datetime: "<<datetime<<endl;
cout<<"port: "<<port<<endl;
}
};
struct messege
{
string mess;
int mess_id;
};
class Sender
{
messege m;
Channel c;
public:
void LoadMessege()
{
c.input_detail();
cout<<"Enter Messege: ";
cin>>m.mess;
m.mess_id=rand();
}
friend void path(Sender *s,Reciever *r);
};
class Reciever{
messege m;
bool recieved;
public:
void PrintMessege()
{
cout<<"Enter Messege: "<<m.mess<<endl;
cout<<"Messege Id: "<<m.mess_id<<endl;
}
friend void path(Sender *s,Reciever *r);
};
void path(Sender *s,Reciever *r)
{
r->m=s->m;
s->c.print_detail();
r->PrintMessege();
r->recieved=true;
}
int main()
{
int choice;
Sender s;
Reciever r;
do
{
cout<<"1.Load Messege\n";
cout<<"2.Recieved Messege\n";
cout<<"3.exit\n";
cout<<"Enter choice: ";
cin>>choice;
switch(choice)
{
case 1:
s.LoadMessege();
break;
case 2:
path(&s,&r);
break;

}
}while(choice!=3);
}

Output
Question 3
#include<iostream>
using namespace std;
class Friend_Class;
class Friend2_Class;
class BASE
{
int base3;
public:
int base1;
int base2;
BASE()
{
base1=0;
base2=0;
base3=0;
}
BASE(int i,int j,int k){
base1=i;
base2=j;
base3=k;
}
void display()
{
cout<<"Base1 "<<base1<<endl;
cout<<"Base2 "<<base2<<endl;
cout<<"Base3 "<<base3<<endl;

}
friend class Friend_Class;

};
class Friend_Class
{
public:
void Access_Method(BASE *b)
{
b->base1=3;
b->base2=4;
b->base3=7;

}
friend class Friend2_Class;
};
class Friend2_Class
{
public:
void Access_Method(BASE *b,Friend_Class *f){
f->Access_Method(b);
b->display();
}
};

int main()
{
BASE b;
Friend_Class f;
Friend2_Class f1;
cout<<"Calling Base from friend class "<<endl;
b.display();
f.Access_Method(&b);
cout<<"Calling base and friend class from friend2 class"<<endl;
f1.Access_Method(&b,&f);

cout<<"\nGot an error when trying to access base from freind2 class\n";


}

Output

You might also like