This Cpp / C++ Program is to enter values in meter using constructor function as meters & cm pass the value to friend function where you convert this value to feet & inches.
Mumbai University MCA Colleges Programs
Friend Functions is a concept of C++ / CPP. Using friend function we can merge the data of different classes. Using Friend Function we can also access the private data members of class. Friend Function is one reason for Cpp / C++ not being a complete Object Oriented Language.
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
class centimeter;
class meter
{
float met;
public:
meter();
friend void convert(meter m,centimeter cm);
};
class centimeter
{
float centi;
public:
centimeter();
friend void convert(meter m,centimeter cm);
};
meter::meter(void)
{
cout<<"\nEnter The Value For Meter: "<<endl;
cin>>met;
}
centimeter::centimeter(void)
{
cout<<"\nEnter The Valued For Centimeter : "<<endl;
cin>>centi;
}
void convert(meter m,centimeter cm)
{
float feet,inch;
feet=m.met*100;
feet=feet/30;
inch=cm.centi/2.50;
cout<<m.met<<" Meter = "<<feet<<" Feet"<<endl;
cout<<cm.centi<<" Centimeter = "<<inch<<" Inch"<<endl;
}
void main()
{
clrscr();
meter m;
centimeter cm;
convert(m,cm);
getch();
}
Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.
Friend Functions is a concept of C++ / CPP. Using friend function we can merge the data of different classes. Using Friend Function we can also access the private data members of class. Friend Function is one reason for Cpp / C++ not being a complete Object Oriented Language.
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
class centimeter;
class meter
{
float met;
public:
meter();
friend void convert(meter m,centimeter cm);
};
class centimeter
{
float centi;
public:
centimeter();
friend void convert(meter m,centimeter cm);
};
meter::meter(void)
{
cout<<"\nEnter The Value For Meter: "<<endl;
cin>>met;
}
centimeter::centimeter(void)
{
cout<<"\nEnter The Valued For Centimeter : "<<endl;
cin>>centi;
}
void convert(meter m,centimeter cm)
{
float feet,inch;
feet=m.met*100;
feet=feet/30;
inch=cm.centi/2.50;
cout<<m.met<<" Meter = "<<feet<<" Feet"<<endl;
cout<<cm.centi<<" Centimeter = "<<inch<<" Inch"<<endl;
}
void main()
{
clrscr();
meter m;
centimeter cm;
convert(m,cm);
getch();
}
Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.
No comments:
Post a Comment