upsidedown

oops3_a

Feb 10th, 2012
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.80 KB | None | 0 0
  1. #include<iostream.h>
  2. int max(int,int);
  3. float max(float,float,float);
  4. double max(double,double,double);
  5.  
  6. int main()
  7. {
  8.     int a,b,c;
  9.     float x,y,z;
  10.     double p,q,r;
  11.     cout<<"enter a choice\n";
  12.     cout<<"1.max of two integers\n";
  13.     cout<<"2.max of three floats\n";
  14.     cout<<"3.max of three doubles\n";
  15.     cin>>a;
  16.     switch(a)
  17.     {
  18.     case 1:
  19.         cout<<"enter two inegers:\n";
  20.         cin>>b>>c;
  21.         cout<<"maximum of two integers is: "<<max(b,c)<<endl;
  22.         break;
  23.  
  24.     case 2:
  25.         cout<<"enter three floating point values:\n";
  26.         cin>>x>>y>>z;
  27.         cout<<"the maximum of three floating point values are: "<<max(x,y,z)<<endl;
  28.         break;
  29.    
  30.     case 3:
  31.         cout<<"enter three double values:\n";
  32.         cin>>p>>q>>r;
  33.         cout<<"the maximum of three floating point values are: "<<max(p,q,r)<<endl;
  34.         break;
  35.  
  36.     default:
  37.         cout<<"invalod operator\n";
  38.         break;
  39.     }
  40.     return 0;
  41. }
  42.  
  43.  
  44. int max(int a,int b)
  45. {
  46.     if (a>b)
  47.         return a;
  48.     else
  49.         return b;
  50. }
  51.  
  52. float max(float a,float b,float c)
  53. {
  54.     if(a>b&&a>c)
  55.         return a;
  56.     else
  57.     {
  58.         if(b>c)
  59.             return b;
  60.         else
  61.             return c;
  62.     }
  63. }
  64.  
  65. double max(double a,double b,double c)
  66. {
  67.     if(a>b&&a>c)
  68.         return a;
  69.     else
  70.     {
  71.         if(b>c)
  72.             return b;
  73.         else
  74.             return c;
  75.     }
  76. }
  77.  
  78. OUTPUT:
  79. enter a choice
  80. 1.max of two integers
  81. 2.max of three floats
  82. 3.max of three doubles
  83. 1
  84. enter two inegers:
  85. 24
  86. 75
  87. maximum of two integers is: 75
  88. Press any key to continue
  89.  
  90. enter a choice
  91. 1.max of two integers
  92. 2.max of three floats
  93. 3.max of three doubles
  94. 2
  95. enter three floating point values:
  96. 42.4
  97. 62.4
  98. 75.4
  99. the maximum of three floating point values are: 75.4
  100. Press any key to continue
  101.  
  102. enter a choice
  103. 1.max of two integers
  104. 2.max of three floats
  105. 3.max of three doubles
  106. 3
  107. enter three double values:
  108. 45.7594
  109. 45.8412
  110. 45.9985
  111. the maximum of three floating point values are: 45.9985
  112. Press any key to continue
Advertisement
Add Comment
Please, Sign In to add comment