- 1. WAP to calcuate netsalary of an employee using a class name employee.
- 2. write c++ program to read data on N employee and compute net salary of each employee using class employee.
- 3. define a student class with other member data. decalre an array of 10 student , find the average of two better marks for each student.
- 4. WAP to implement function overloading fucntion ADD that returns complex number. a. ADD(a,s1) where a is interger and s1 is complex. b. ADD(s1,s2) where s1 and s2 both are complex.
- 5. WAP to implement hybrid inheritance
Program number 1
#include<conio.h> class employee { int emp_id; char emp_name[20]; float basic,da,it,netsal,gross; public: void read_data(); void net_cal(); void write_data(); }; void employee::read_data() { cout<<"\n\t EMPLOYEE DETAILS"<<endl; cout<<"enter name:"<<endl; cin>>emp_name; cout<<"emp_id:"<<endl; cin>>emp_id; cout<<"enter basic:"<<endl; cin>>basic; } void employee::net_cal() { da=0.52*basic; gross=basic+da; it=0.30*gross; netsal=gross-it; } void employee::write_data() { cout<<"\n\t EMPLOYEE DETAILS"<<endl; cout<<"emp_name:"<<emp_name<<endl; cout<<"emp_id:"<<emp_id<<endl; cout<<"basic:"<<basic<<endl; cout<<"da:"<<da<<endl; cout<<"gross:"<<gross<<endl; cout<<"it:"<<it<<endl; cout<<"netsal:"<<netsal<<endl; } void main() { clrscr(); employee e1; e1.read_data(); e1.net_cal(); e1.write_data(); getch(); } Program number 2#include<iostream.h> #include<conio.h> class employee { int emp_id; char emp_name[20]; float basic,da,it,netsal,gross; public: void read_data(); void net_cal(); void write_data(); }; void employee::read_data() { cout<<"\n\t EMPLOYEE DETAILS"<<endl; cout<<"enter name:"<<endl; cin>>emp_name; cout<<"emp_id:"<<endl; cin>>emp_id; cout<<"enter basic:"<<endl; cin>>basic; } void employee::net_cal() { da=0.52*basic; gross=basic+da; it=0.30*gross; netsal=gross-it; } void employee::write_data() { cout<<"\n\t EMPLOYEE DETAILS"<<endl; cout<<"emp_name:"<<emp_name<<endl; cout<<"emp_id:"<<emp_id<<endl; cout<<"basic:"<<basic<<endl; cout<<"da:"<<da<<endl; cout<<"gross:"<<gross<<endl; cout<<"it:"<<it<<endl; cout<<"netsal:"<<netsal<<endl; } void main() { int i; clrscr(); employee e[3]; for(i=0;i<3;i++) { e[i].read_data(); e[i].net_cal(); } cout<<"EMPLOYEE DETAILS"<<endl; for(i=0;i<3;i++) e[i].write_data(); getch(); }
\\\\\\\\\\
Program number 4
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
class sample
{
private:
int real;
int img;
public:
void getdata();
//void sum();
void display();
friend sample add(sample s1, sample s2);
friend sample add(int a, sample s2);
};
void sample::getdata()
{
cout<<"Enter the data:";
cin>>real>>img;
}
void sample::display()
{
cout<<real<<"+i"<<img;
}
sample add(int a, sample s1)
{
sample tmp;
tmp.real=a + s1.real;
tmp.img=s1.img;
return tmp;
}
sample add(sample s1, sample s2)
{
sample temp;
temp.real=s1.real+s2.real;
temp.img=s1.img+s2.img;
return temp;
}
void main()
{
clrscr();
sample s1,s2,s3,s4;
int a;
s1.getdata();
s2.getdata();
cout<<"enter a:";
cin>>a;
s4=add(a,s1);
s4.display();
s3=add(s1,s2);
s3.display();
getch();
}
HYBRID INHERITANCE
#include<iostream.h>
#include<conio.h>
class student
{
protected:
int roll;
public:
void getroll(int a)
{roll=a;}
void putroll()
{
cout<<"roll="<<roll;
}
};
class test:public student
{
protected:
int game;
public:
void gettest(int a)
{
game=a;
}
void puttest()
{
cout<<"game="<<game;
}
};
class sports
{
protected:
int score;
public:
void getscore(int v)
{
score=v;
}
void putscore()
{
cout<<"scorre="<<score;
}
};
class result:public sports, public test
{
protected:
int total;
public:
void display()
{
total=score+game;
cout<<"total="<<total;
}
};
void main()
{
result r;
r.getroll(5);
r.gettest(20);
r.getscore(12);
r.display();
getch();
}
6:25 AM |
Category: |
