C++ program to illustrate passing of structures by value.

Sunday, August 12, 2012


Write a C++ program to illustrate passing of structures by value. 

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct distance{
 int feet;
 int inches;
};
int main()
{
clrscr();
    distance length1, length2;
void prnsum(distance l1, distance l2);
cout<<"\n"<<"Enter length 1:\n";
cout<<"\n"<<"Feet:\n";
cin>>length1.feet;
cout<<"\n"<<"Inches:\n";
cin>>length1.inches;
cout<<"\n"<<"\n"<<"Enter length 2:\n";
cout<<"\n"<<"Feet:\n";
cin>>length2.feet;
cout<<"\n"<<"Inches\n";
cin>>length2.inches;
prnsum(length1, length2);
return 0;
}
void prnsum(distance  l1, distance l2)
{
  distance l3;
  l3.feet = l1.feet + l2.feet + (l1.inches +l2.inches)/12;
  l3.inches =( l1.inches + l2.inches)%12;
  cout<<"\n"<<"\n";
  cout<<"\n"<<"Total Feet:"<<l3.feet<<"\n";
  cout<<"\n"<<"Total Inches:"<<l3.inches;
  return;
}
/*
OUTPUT
------

Enter length 1:

Feet:
10

Inches:
1

Enter length 2:

Feet:
12

Inches
2

Total Feet:22

Total Inches:3


*/

0 comments:

Post a Comment

Blogroll

Bookmark and Share
Powered By Blogger
CBSE 12th Grader.