Top Banner
/*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; Employee Manager Programmer
28

Pratik Bakane C++

May 06, 2015

Download

Engineering

pratikbakane

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
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Pratik Bakane C++

/*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

Page 2: Pratik Bakane C++

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;

Page 3: Pratik Bakane C++

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();

Page 4: Pratik Bakane C++

Programmer p;

// e.accept();

// e.display();

p.take();

p.display();

Manager m;

m.getdata();

m.display();

getch();

}

OUTPUT :

Page 5: Pratik Bakane C++

/***************************Page Number 133****************************/

#include<iostream.h>

#include<conio.h>

Page 6: Pratik Bakane C++

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();

}

Page 7: Pratik Bakane C++

OUTPUT :

/**********************Page Number 125*******************/

#include<iostream.h>

#include<conio.h>

class complex

{

int a,b,c;

public:

complex() {}

Page 8: Pratik Bakane C++

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++;

Page 9: Pratik Bakane C++

cout<<"Increment Complex number\n";

obj.display();

obj--;

cout<<"Decrement Complex Number\n";

obj.display();

getch();

}

OUTPUT:

Page 10: Pratik Bakane C++

******************Page Number 126*******************

#include<iostream.h>

#include<conio.h>

class Sample

{

Page 11: Pratik Bakane C++

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;

Page 12: Pratik Bakane C++

}

void main()

{

clrscr();

Sample P;

P.getdata(1,12,24);

P.show();

-P;

P.show();

getch();

}

OUTPUT

Page 13: Pratik Bakane C++

/***************************Page Number 127******************/

#include<iostream.h>

#include<conio.h>

Page 14: Pratik Bakane C++

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;

Page 15: Pratik Bakane C++

s.display();

getch();

}

OUTPUT:

Page 16: Pratik Bakane C++

/*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);

Page 17: Pratik Bakane C++

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();

}

Page 18: Pratik Bakane C++

OUTPUT:

Page 19: Pratik Bakane C++

/*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>

Page 20: Pratik Bakane C++

#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();

Page 21: Pratik Bakane C++

student s1;

s1.accept();

s1.display();

getch();

}

OUTPUT

Page 22: Pratik Bakane C++

/************************Page Number 61***************/

#include<iostream.h>

Page 23: Pratik Bakane C++

#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();

}

Page 24: Pratik Bakane C++

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>

Page 25: Pratik Bakane C++

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();

}

Page 26: Pratik Bakane C++

OUTPUT: