Wednesday, 6 June 2012

C++ Program to Adding two angles

C++ Program to Adding two angles


#include<iostream.h>
#include<conio.h>
#include<stdio.h>
// Definition of the structure angle
struct angle
{
// two member variables
int degrees;
int minutes;
};
angle sumangle(angle, angle);
// function with structure as arguments and returning structures.
main()
{
clrscr();
angle pangle[3];
for(int i=0;i<2;i++)
{
cout<<"Enter angle in degrees and minutes";
cin>>pangle[i].degrees;
cin>>pangle[i].minutes;
}
// Data entered in two array cells
pangle[2]=sumangle(pangle[0],pangle[1]);
cout<<"The sum of two angles is ";
cout<<endl;
cout<<pangle[2].degrees<<"Degrees and ";
cout<<pangle[2].minutes<<"Minutes";
cout<<endl;
cout<<endl;
cout<<"Press any key to continue";
getch();
return 0;
}
// Defining the function
angle sumangle(angle x, angle y)
{
angle z;
z.degrees=x.degrees+y.degrees;
z.minutes=x.minutes+y.minutes;
if(z.minutes>=60)
{
z.minutes=z.minutes-60;
z.degrees=z.degrees+1;
}
return z;
}

0 comments:

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More