You are on page 1of 5

CA – 8

Pranav Nawalkha
BCA (Data Analytics)
OOPS

Inheritance: -

a.Create a base class to hold the marks of 6 subjects for the student. Using the
concept of inheritance display the data and performance of the student.
(single inheritance student--->result).
Program:
#include<iostream>
using namespace std;
class student
{
int usn;
char name[20];
public:
void input()
{
cout<<"Enter the USN no of the student: ";
cin>>usn;
cout<<"Enter the student name: ";
cin.getline(name, 20);
cin.getline(name, 20);
}
void output()
{
cout<<"USN NO: "<<usn<<endl;
cout<<"Student name: "<<name<<endl;
}
};
class result: public student
{
int m1, m2, m3, m4, m5, m6;
public:
void get_marks()
{
cout<<"Enter subject 1 marks: ";
cin>>m1;
cout<<"Enter subject 2 marks: ";
cin>>m2;
cout<<"Enter subject 3 marks: ";
cin>>m3;
cout<<"Enter subject 4 marks: ";
cin>>m4;
cout<<"Enter subject 5 marks: ";
cin>>m5;
cout<<"Enter subject 6 marks: ";
cin>>m6;
}
void display_marks()
{
cout<<"Subject 1 marks: "<<m1<<endl;
cout<<"Subject 2 marks: "<<m2<<endl;
cout<<"Subject 3 marks: "<<m3<<endl;
cout<<"Subject 4 marks: "<<m4<<endl;
cout<<"Subject 5 marks: "<<m5<<endl;
cout<<"Subject 6 marks: "<<m6<<endl;
cout<<"Total Marks: "<<(m1+m2+m3+m4+m5+m6)<<endl;
cout<<"Percentage: "<<((m1+m2+m3+m4+m5+m6)/6)<<endl;
}
};
int main()
{
result r;
r.input();
r.get_marks();
cout<<"\nSTUDENT DETAILS"<<endl;
r.output();
r.display_marks();
}
Output:
b. Create a class called employee with empno,ename,bsal
and create derived called benifits with member data HRA,TA,DA,PF,netsal,
totalsal. read and display employees data with net salary and total salary.

Program:
#include<iostream>
using namespace std;
class employee
{
private:
int empno;
char empname[50];

public:
void input()
{
cout<<"Enter the employee number: ";
cin>>empno;
cout<<"Enter the employee name: ";
cin.getline(empname, 50);
cin.getline(empname, 50);
}
void output()
{
cout<<"\nEMPLOYEE DETAILS"<<endl;
cout<<"Employee number: "<<empno<<endl;
cout<<"Employee name: "<<empname<<endl;
}
};
class benifits: public employee
{
private:
double bsal, hra, ta, da, pf, tsal, netsal;

public:
void input()
{
employee::input();
cout<<"Enter the empoyee salary: ";
cin>>bsal;
hra=bsal*0.15;
ta=bsal*0.20;
da=bsal*0.10;
pf=bsal*0.15;
tsal=bsal+hra+ta+da+pf;
netsal=tsal-pf;
}
void output()
{
employee::output();
cout<<"Employee salary: "<<bsal<<endl;
cout<<"HRA: "<<hra<<endl;
cout<<"TA: "<<ta<<endl;
cout<<"DA: "<<da<<endl;
cout<<"PF: "<<pf<<endl;
cout<<"Net Salary: "<<netsal<<endl;
cout<<"Total Salary: "<<tsal<<endl;
}
};
int main()
{
benifits b;
b.input();
b.output();
}

Output:

You might also like