17 November 2011

Length program using classes.

#include<iostream.h>
#include<conio.h>
class db;
class dm
 {
  float mt;
  int cm;
  public:
  void getdata(void);
  void display(void);
  friend dm add(dm,db);
  };
  class db
  {
  int feet;
  float inches;
  public:
  void getdata(void);
  void display(void);
  friend dm add(dm,db);
  };   void dm :: getdata(void)
  {
  clrscr();
  cout<<"\t\tDM GETDATA FUNCTION\n\n";
  cout<<"Enter Values for metres :-";
  cin>>mt;
  cout<<"Enter Values for centimetres:-";
  cin>>cm;
  }
  void dm :: display(void)
  {
  cout<<"\n\nThe value of distance in metres is"<<mt;
  cout<<"\nThe value of distance in Centimetres is "<<cm;
  }
  void db ::getdata(void)
  {
  clrscr();
  cout<<"\t\tDB GETDATA FUNCTION\n\n";
  cout<<"\n\nEnter Values forn feet:-";
  cin>>feet;
  cout<<"Enter Values for inches:-";
  cin>>inches;
  }
  void db :: display(void)
  {
  cout<<"\n\nThe value of distance in feet is "<<feet;
  cout<<"\nThe value of distance in inches is"<<inches;
  }
  dm add(dm a,db b)
  {
  dm temp;
  temp.cm=a.cm+(b.feet*30)+((b.inches*30)/12.0);
  temp.mt=a.mt+(temp.cm% 100);
  temp.cm=temp.cm-((temp.cm% 100)*100);
  return(temp);
  }
  void main()
  {
  dm a;
  a.getdata();
  db b;
  b.getdata();
  clrscr();
  cout<<"\n\t\tAFTER CONVERSION AND THEIR ADDITION IS PERFORMED\n";
  //extra variable of type dm to display result of adding two different types of distance
  dm extra;
  extra=add(a,b);
  extra.display();
  getch();
  }

 

0 comments:

Post a Comment