/* Copyright (C) 2007 Ankur Banerjee. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. http://www.fsf.org/licensing/licenses/lgpl.html /
/ Function returning reference to a structure – WAP to add distances
entered in feet and inches /
#include <iostream.h>
#include <conio.h>
struct dist
{
int feet, inches;
} result;
void main()
{
clrscr();
dist d1, d2;
dist& add (dist&, dist&);
cout<<“Enter first distance : “;
cin>>d1.feet>>d1.inches;
cout<<“Enter the second distance : “;
cin>>d2.feet>>d2.inches;
result = add(d1, d2);
cout<<“Added result is “<<result.feet<<” feet ” <<result.inches<<” inches”<<endl;
getch();
}
dist& add (dist &a1, dist &a2)
{
dist res;
res.feet = (a1.feet + a2.feet) + ((a1.inches + a2.inches)/12);
res.inches = (a1.inches + a2.inches)%12;
return res;
}
/ Output */
Enter first distance :6
5
Enter
the second distance :8
2
Added result is 14 feet 7 inches