Professional Documents
Culture Documents
20bcs0003 Oop Lab Fat Exam
20bcs0003 Oop Lab Fat Exam
___________________________________________________________________________
__________________________________________________
1.Create two classes named DM and DB to store the values of Distance. DM
stores distances in meters and centimeters and DB in feet and inches. Write
a program that can read values for the class objects and add one object of
DM with another object of DB. Use a friend function to carry out the
addition operation. The object that stores the results may be a DM or DB
object depending on units in which the results are required. Your output
display should be either in “feet–inches” or “meter-centimeter” depending
on the object or display.Single line text.
AIM:
In this program we use two classes DM and DB for getting distance in
meter and feet and add two different units using friend function and store results
in DM or DB to display the addition of two distance in any one unit.
DESCRIPTION:
First create two classes DM and DB and each class use function to get
values and display and create friend function for adding two values and by this
friend function we add two units and display the result in one unit.
CODE:
#include<iostream>
#include<conio.h>
class DB;
class DM
{
float meter,centi;
public:
void getdata()
{
cout<<"\nEnter the distance in(meter-centimeter):";
cin>>meter>>centi;
}
void display()
{
cout<<"\nThe distance is:";
cout<<meter<<" meters and "<<centi<<" centimeter";
}
class DB
{
float inch,feet;
public:
void getdata()
{
cout<<"\nEnter the distance in(feet-inch):";
cin>>feet>>inch;
}
void display()
{
cout<<"\nThe distance is:";
cout<<feet<<" feet and "<<inch<<" inch";
}
else
{
d.meter=0;
d.centi=c;
}
d.display();
}
else
{
DB d;
int i=(a.meter*39.37+a.centi*.3937008+b.feet*12+b.inch);
if(i>=12)
{
d.feet=i/12;
d.inch=i%12;
}
else
{
d.feet=0;
d.inch=i;
}
d.display();
}
}
int main()
{
system("color 02");
cout<<"\n NAME : P.NITHISH| REG. NO. : 20BCS0003\n"<<endl;
DM a;
DB b;
a.getdata();
b.getdata();
add(a,b);
getch();
}
OUTPUT: