Advertisement
steverobinson

Smallest among two numbers

Oct 12th, 2010
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. /* Smallest Among two Numbers Using Class*/
  2. /*             Language: C++             */
  3.  
  4.  
  5.  
  6. #include <iostream.h>
  7. #include <conio.h>
  8.  
  9. class float_num
  10. {
  11.     float a,b;
  12.  
  13.     public:
  14.         float_num(float x,float y)
  15.         {
  16.             a=x;
  17.             b=y;
  18.         }
  19.         friend float compare(float_num &num);
  20. };
  21.  
  22.  
  23. class int_num
  24. {
  25.     int a,b;
  26.  
  27.     public:
  28.         int_num(int x,int y)
  29.         {
  30.             a=x;
  31.             b=y;
  32.         }
  33.         friend int compare(int_num &num);
  34. };
  35.  
  36.  
  37.  
  38. int compare(int_num &num)
  39. {
  40.     if(num.a<num.b)
  41.         return num.a;
  42.     else
  43.         return num.b;
  44. }
  45.  
  46. float compare(float_num &num)
  47. {
  48.     if(num.a<num.b)
  49.         return num.a;
  50.     else
  51.         return num.b;
  52. }
  53.  
  54.  
  55. int main()
  56. {
  57.     system("cls");
  58.     int a,b;
  59.     float c,d;
  60.     cout<<"\nEnter two Integer Numbers: \n";
  61.     cin>>a>>b;
  62.     int_num int_1(a,b);
  63.     cout<<"\nThe Smallest Among the given two number is: "<<compare(int_1);
  64.     cout<<"\n\nEnter two Floating Point Numbers: \n";
  65.     cin>>c>>d;
  66.     float_num float_1(c,d);
  67.     cout<<"\nThe Smallest Among the given two number is: "<<compare(float_1);
  68.     getch();
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement