View
194
Download
7
Category
Preview:
DESCRIPTION
Pratik Bakane C++ programs...............This are programs desingedby sy diploma student from Governement Polytecnic Thane.....programsare very easy alongwith coding andscreen shot of the output
Citation preview
/*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<<"\n\n\t\tEnter the Emplyee Name : ";
cin>>name;
cout<<"\n\n\t\tEnter the salary : ";
cin>>sal;
}
virtual void display() //virtual function
{
Employee
ManagerProgrammer
cout<<"\n\n\t\tEmployee name : ";
cout<<"\n\n\t\tEmployee salary : ";
}
};
class Programmer:public Employee
{
protected:
char name[20];
float sal;
int dept_no;
public:
void take()
{
cout<<"\n\n\t\tEnter the name of Programmer: ";
cin>>name;
cout<<"\n\n\t\tEnter the salary : ";
cin>>sal;
cout<<"\n\n\t\tEnter the department Number : ";
cin>>dept_no;
}
void display() //virtual function
{
cout<<"\n\n\t\tThe naem of Programmer is : "<<name;
cout<<"\n\n\t\tThe salary is : "<<sal;
cout<<"\n\n\t\tThe department number is :"<<dept_no;
}
};
class Manager:public Employee
{
protected:
char name[20],post[20];
public:
void getdata()
{
cout<<"\n\n\t\tEnter the Name of the Manager : ";
cin>>name;
cout<<"\n\n\t\tEnter the post of Manager : ";
cin>>post;
}
void display() //virtual function
{
cout<<"\n\n\t\tThe Name is : "<<name;
cout<<"\n\n\t\tThe 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<<"\n\n\t\tBase Class ";
}
};
class Derived:public Base
{
public:
void display()
{
cout<<"\n\n\t\tDerived 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 number\n";
obj.display();
obj--;
cout<<"Decrement Complex Number\n";
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<<"\n\n\t\t"<<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<<"\n\n\t\tThe sum of ten Integers numbers : "<<x;
cout<<"\n\n\t\tThe 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<<"\n\n\t\tEnter the Roll Number : ";
cin>>r_no;
cout<<"\n\n\t\tEnter the Percentage : ";
cin>>per;
}
void display()
{
cout<<"\n\n\t\tRoll Number is : ";
cout<<this->r_no;
cout<<"\n\n\t\tPercentage 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<<"\n\n\t\tI am Constructor ";
}
void display()
{
cout<<"\n\n\t\tValues : "<<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<<"\n\n\t\tGross Salary : "<<gross_sal;
}
};
void main()
{
clrscr();
salary s(1000,1000);
s.display_sal();
getch();
}
OUTPUT:
Recommended