/*Program for above Hierachy where Employee id Base class and Programmer
and manager are child class. Make display function virtual which is common
for all the three classes*/
/**************************Experiment 16****************************/
#include<iostream.h>
#include<conio.h>
class Employee
{
private:
char name[20];
float sal;
public:
void accept()
{
cout<<"nnttEnter the Emplyee Name : ";
cin>>name;
cout<<"nnttEnter the salary : ";
cin>>sal;
Employee
ManagerProgrammer
}
virtual void display() //virtual function
{
cout<<"nnttEmployee name : ";
cout<<"nnttEmployee salary : ";
}
};
class Programmer:public Employee
{
protected:
char name[20];
float sal;
int dept_no;
public:
void take()
{
cout<<"nnttEnter the name of Programmer: ";
cin>>name;
cout<<"nnttEnter the salary : ";
cin>>sal;
cout<<"nnttEnter the department Number : ";
cin>>dept_no;
}
void display() //virtual function
{
cout<<"nnttThe naem of Programmer is : "<<name;
cout<<"nnttThe salary is : "<<sal;
cout<<"nnttThe department number is :"<<dept_no;
}
};
class Manager:public Employee
{
protected:
char name[20],post[20];
public:
void getdata()
{
cout<<"nnttEnter the Name of the Manager : ";
cin>>name;
cout<<"nnttEnter the post of Manager : ";
cin>>post;
}
void display() //virtual function
{
cout<<"nnttThe Name is : "<<name;
cout<<"nnttThe Post is : "<<post;
}
};
void main()
{
clrscr();
Programmer p;
// e.accept();
// e.display();
p.take();
p.display();
Manager m;
m.getdata();
m.display();
getch();
}
OUTPUT :   
/***************************Page Number 133****************************/
#include<iostream.h>
#include<conio.h>
class Base
{
public:
virtual void display()
{
cout<<"nnttBase Class ";
}
};
class Derived:public Base
{
public:
void display()
{
cout<<"nnttDerived Class";
}
};
void main()
{
clrscr();
Base b;
Derived d;
b.display();
d.display();
getch();
}
OUTPUT : 
/**********************Page Number 125*******************/
#include<iostream.h>
#include<conio.h>
class complex
{
int a,b,c;
public:
complex() {}
void getvalue()
{
cout<<"Enter the two Numbers : ";
cin>>a>>b;
}
void operator++()
{
a=++a;
b=++b;
}
void operator--()
{
a=--a;
b=--b;
}
void display()
{
cout<<a<<"+t"<<b<<"i"<<endl;
}
};
void main()
{
clrscr();
complex obj;
obj.getvalue();
obj++;
cout<<"Increment Complex numbern";
obj.display();
obj--;
cout<<"Decrement Complex Numbern";
obj.display();
getch();
}
OUTPUT:  
******************Page Number 126*******************
#include<iostream.h>
#include<conio.h>
class Sample
{
private:
int p,q,r;
public:
void getdata(int p,int q,int r);
void show()
{
cout<<"np="<<p;
cout<<"nq="<<q;
cout<<"nr="<<r;
}
void operator-();
};
void Sample::getdata(int m,int n,int z)
{
p=m;
q=n;
r=z;
}
void Sample::operator-()
{
p=p*p*p;
q=q*q*q;
r=r*r*r;
}
void main()
{
clrscr();
Sample P;
P.getdata(1,12,24);
P.show();
-P;
P.show();
getch();
}
OUTPUT   
/***************************Page Number 127******************/
#include<iostream.h>
#include<conio.h>
class SYIT
{
protected:
int count;
public:
SYIT()
{
count=0;
}
void operator++()
{
count++;
}
void display()
{
cout<<endl<<"nntt"<<count;
}
};
void main()
{
clrscr();
SYIT s;
s++;
s.display();
++s;
s.display();
getch();
}
OUTPUT:  
/*Program using function overloading to calculate addition of ten
integer number and five floating numbers.*/
#include<iostream.h>
#include<conio.h>
int add(int,int,int,int,int,int,int,int,int,int);
float add(float,float,float,float,float);
int add(int a,int b,int c,int d,int e,int f,int g,int h,int i,int j)
{
return (a+b+c+d+e+f+g+h+i+j);
}
float add(float k,float l,float m,float n,float o)
{
return (k+l+m+n+o);
}
void main()
{
clrscr();
int x;
float y;
x=add(1,2,3,4,5,6,7,8,9,10);
y=add(1.0,1.1,1.2,1.3,1.4);
cout<<"nnttThe sum of ten Integers numbers : "<<x;
cout<<"nnttThe sum of five floating numbers : "<<y;
getch();
}
OUTPUT:  
/*Program to declare a class student having data members as roll_no
and percentage. Using ‘this’ pointer invoke member functions to
accept and display this data for one object of the class.*/
#include<iostream.h>
#include<conio.h>
#include<math.h>
class student
{
private:
int r_no,per;
public:
void accept()
{
cout<<"nnttEnter the Roll Number : ";
cin>>r_no;
cout<<"nnttEnter the Percentage : ";
cin>>per;
}
void display()
{
cout<<"nnttRoll Number is : ";
cout<<this->r_no;
cout<<"nnttPercentage is : ";
cout<<this->per;
}
};
void main()
{
clrscr();
student s1;
s1.accept();
s1.display();
getch();
}
OUTPUT   
/************************Page Number 61***************/
#include<iostream.h>
#include<conio.h>
#include<math.h>
class example
{
int a,b;
public:
example(int x,int y)
{
a=x;
b=y;
cout<<"nnttI am Constructor ";
}
void display()
{
cout<<"nnttValues : "<<a<<"t"<<b;
}
};
void main()
{
clrscr();
example obj(10,20);
obj.display();
getch();
}
OUTPUT:  
/*Program to define a class salary which will contain member variable
basic,ta,da,hra. Devlop a program using constructor with default
value(s) for da and hra and calculate the salary of employee*/
#include<iostream.h>
#include<conio.h>
#include<math.h>
class salary
{
float basic,ta,da,hra;
public:
salary(float b,float t,float d=1000,float h=1000)
{
basic=b;
ta=t;
da=d;
hra=h;
}
void display_sal()
{
float gross_sal;
gross_sal=(basic+ta+da+hra);
cout<<"nnttGross Salary : "<<gross_sal;
}
};
void main()
{
clrscr();
salary s(1000,1000);
s.display_sal();
getch();
}
OUTPUT:  

Pratik Bakane C++