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
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Pratik Bakane C++
1. /*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
2. }
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;
3. }
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
{
4. 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();
}
20. /*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;
25. /*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;