100% found this document useful (1 vote)
62 views

Practical 6

The document defines 5 different classes: student, distance, employee, and provides code examples to demonstrate each class. It includes data members and member functions for each class and test programs to demonstrate the functionality.

Uploaded by

rudraraicha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
62 views

Practical 6

The document defines 5 different classes: student, distance, employee, and provides code examples to demonstrate each class. It includes data members and member functions for each class and test programs to demonstrate the functionality.

Uploaded by

rudraraicha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

PRACTICAL:6

Define minimum 5 different classes such as student, distance, shape, employee,


account, inventory, vector, movie-ticket booking, time, point, etc. with data member &
member functions. Also develop programs to test those classes functionality.

PRACTICAL 6.1

Aim: Develop a class student with data member & member function.

INPUT:
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
class student
{
private:
int rollnum;
char name[20];
public:
void getdata()
{
cout<<"Enter roll number:";
cin>>rollnum;
cout<<"Enter name:";
cin>>name;
}
void putdata()
{
cout<<"Your name is:"<<name<<endl;
cout<<"Your roll number is:"<<rollnum;
}
};
void main()
{
student s1;

Basic Object Oriented Programming(4320702) Enrollment No :239830331080


clrscr();
s1.getdata();
s1.putdata();
getch();
}

OUTPUT:

Basic Object Oriented Programming(4320702) Enrollment No :239830331080


PRACTICAL:6.2

Aim: Develop a class distance with data member & member function.

INPUT:
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
class distance
{
int feet,inch;
public:
void set_distance()
{
cout<<"Enter feet:";
cin>>feet;
cout<<"Enter inch:";
cin>>inch;
}
void get_distance()
{
cout<<"Feet are:"<<feet<<"\tInch are:"<<inch;
}
void add(distance d1,distance d2)
{
feet=d1.feet+d2.feet;
inch=d1.inch+d2.inch;
feet=feet+(inch/12);
inch=inch%12;
}
};
void main()
{
distance d1,d2,d3;
clrscr();
d1.set_distance();

Basic Object Oriented Programming(4320702) Enrollment No :239830331080


d2.set_distance();
d3.add(d1,d2);
d3.get_distance();
getch();
}

OUTPUT:

Basic Object Oriented Programming(4320702) Enrollment No :239830331080


PRACTICAL:6.3

Aim: Write a program to demonstrate use of employee.

INPUT:
#include<iostream.h>
#include<conio.h>
class emp
{
int emp_no;
clrscr();
char emp_name[20];
float emp_basic;
float emp_da;
float emp_it;
float emp_net_sal;
public:
void get_emp_detail();
float find_net_sal(float basic,float da, float it);
void show_emp_detail();
};
void emp::get_emp_detail()
{
cout<<"enter emp basic";
cin>>emp_basic;
cout<<"enter emp_da";
cin>>emp_da;
cout<<"enter emp_it";
cin>>emp_it;
}
float emp::find_net_sal(float basic,float da,float it)
{
return(basic+da)-it;

Basic Object Oriented Programming(4320702) Enrollment No :239830331080


}
void emp::show_emp_detail()
{
cout<<"enter emp_basic";
cout<<"enter emp_da";
cout<<"enter emp_it";
cout<<"net salary="<<find_net_sal(emp_basic,emp_da,emp_it);
}
void main()
{
emp e;
e.get_emp_detail();
e.show_emp_detail();
getch();
}
OUTPUT:

Basic Object Oriented Programming(4320702) Enrollment No :239830331080

You might also like