Tuesday, 3 September 2013

C++ Program for Adding Two Length


#include<conio.h>
#include<stdio.h>
  class length
    {
      int km,m,cm;
  public:
      void input();
      void display();
      length add(length,length);
    };

       void length::input()
        {
cout<<"Enter km:";
cin>>km;
cout<<"Enter meter:";
cin>>m;
cout<<"Enter cm:";
cin>>cm;    
        }
       void swap::display()
        {
cout<<km<<":"<<m<<":"<<cm;
        }
       length::add(length 1,length 2)
       {
length l;
l.cm=(l1.ss+l2.ss)%100;
l.m=((l1.m+l2.m)%1000)+((l1.cm+l2.cm)/100);
l.km=(l1.km+l2.km)+((l1.m+l2.m)/1000);
return l;
       }
 void main()
 {
  clrscr();
  length l1,l2,l3,l;
  l1.input();
  l2.input();
  l3.add(l1,l2);
  l3.display();
  getch();
 }

No comments:

Post a Comment