Saturday, 7 March 2015

C++ LAB Part-A 4


//Program : Part A-4
//Create a class DISTANCE with the data members feet and inches and the member //functions read() and show().Write a C++ program to add two distances by using //objects as function arguments(inches should not be>=12).
//Name : LDK E-NOTES                                                                                        Reg.No : **********
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
class distance
{
private:
int feet;
int inches;
public:
void read()
{
cout<<"Enter feet value      : ";
cin>>feet;
cout<<"Enter inches value : ";
cin>>inches;
}
void show(void)
{
cout<<feet<<" Feet and ";
cout<<inches<<" Inches "<<endl;
}
void add(distance d1,distance d2);
};
void distance::add(distance d1,distance d2)
{
inches=d1.inches+d2.inches;
feet=inches/12;
inches=inches%12;
feet=feet+d1.feet+d2.feet;
}
void main()
{
clrscr();
distance d1,d2,d3;
d1.read();
d2.read();
d3.add(d1,d2);
cout<<"Distance 1 = ";d1.show();
cout<<"Distance 2 = ";d2.show();
cout<<"Distance 3 = ";d3.show();
getch();
}


Output 1 :
Enter feet value      : 5
Enter inches value : 8
Enter feet value      : 4
Enter inches value : 9
Distance 1 = 5 Feet and 8 Inches
Distance 2 = 4 Feet and 9 Inches
Distance 3 = 10 Feet and 5 Inches



Output 2 :
Enter feet value      : 6
Enter inches value : 7
Enter feet value      : 27
Enter inches value : 10
Distance 1 = 6 Feet and 7 Inches
Distance 2 = 27 Feet and 10 Inches
Distance 3 = 34 Feet and 5 Inches

No comments:

Post a Comment