OOPC Practical 5


Practical : 5
Subject : Object Oriented Programming with C++

Aim : C++ Program to sum of two distance (feet and inch)


Source Code :
#include<iostream.h>
#include<conio.h>
class distance
{
public:
   int feet,inch,a;
   void getdata()
   {
   cout<<"enter inch and feet \n";
   cin>>inch>>feet;
   }
   void display()
   {
   cout<<"\n the sum in inch is : "<<inch<<"\n the sum in feet is : "<<feet;
   }
   void add(distance obj1,distance obj2)
   {
   inch=obj1.inch+obj2.inch;
   a=inch/12;
   inch=inch%12;
   feet=a+obj1.feet+obj2.feet;
   }
   };
void main()
{
 clrscr();
distance ob1,ob2,ob3;
ob1.getdata();
ob2.getdata();
ob3.add(ob1,ob2);
ob3.display();
getch();
}

Output :


Pratik Boghani

Author & Editor

Life is all about the next step.

0 comments:

Post a Comment