MuruganAD.com
Murugan Andezuthu Dharmaratnam

  |  HOME   |  BLOG   |  ARTICLES   |  8086   |  C++   |  VC++   |  ASP .NET   |  VB .NET   |  JAVA SCRIPT   |  MS SQL   |  MY   |  VIDEOS   |  DOWNLOADS   |  CONTACT ME   |  



C++ Friend Function Example

Home    C++    Friend Function

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class db;
class dm
{
public:
int met,centi,fet;
float inches;
float tot;
int m,cm;

void read_met_cm(void)
{

cout<<"enter the distance in metern";
cin>>m;
cout<<"enter the distance in centimetern";
cin>>cm;
cout<<" the distance isn";
cout<<m<<"metre"<<cm<<"ceni metren";
}
friend dm add(dm a,db b);

dm()
{
m=0;
tot=0;
cm=0;
met=0;
centi=0;
inches=0;
fet=0;
}
}obj1,obj;


class db
{
int ft;
float inch;
public:
void read_ft_inch(void)
{
cout<<"enter the distance in feetn";
cin>>ft;
cout<<"enter the distance in inchn";
cin>>inch;
cout<<" the distance isn";
cout<<ft<<"feet"<<inch<<"inchesnnnn";
}
friend dm add(dm a,db b);
db()
{
ft=0;
inch=0;
}
}obj2;
dm add(dm a,db b)
{

obj.tot=((a.m*100)+a.cm)+(b.ft*30)+(b.inch*2.5);

return(obj);
}

float main()
{
float p1,p2;
clrscr();
dm a,res1;
db b,res2;
a.read_met_cm();
b.read_ft_inch();
add(a,b);
obj.met=int(obj.tot/100);
obj.centi=int(obj.tot)%100;
obj.fet=int(obj.tot/30.48);
obj.inches=(obj.tot-(obj.fet*30.48))/2.54;
cout<<"the total distance in metre and centi metre nn";
cout<<obj.met<<"metre"<<obj.centi<<"centimetrennnn";
cout<<"the total distance in feet and inchesnn";
cout<<obj.fet<<"feet "<<obj.inches<<"inches";
getch();
return(0);
}




  |  HOME   |  BLOG   |  ARTICLES   |  8086   |  C++   |  VC++   |  ASP .NET   |  VB .NET   |  JAVA SCRIPT   |  MS SQL   |  MY   |  VIDEOS   |  DOWNLOADS   |  CONTACT ME   |  

Copyright 2009 @ Murugan Andezuthu Dharmaratnam