Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #include <stdlib.h>
  4. #include <string>
  5. #include <vector>
  6.  
  7.  
  8. using namespace std;
  9.  
  10. class Adaptee
  11. {
  12. // Existing way request are implemented provide full precision
  13. public :
  14.  
  15. double SpecificRequest ( double a, double b )
  16. {
  17. return a / b ;
  18. }
  19. };
  20.  
  21. class ITarget
  22. {
  23. // Required standard for requests. Rough estimate required
  24. public :
  25.  
  26. virtual double Request ( int i ) = 0;
  27.  
  28. };
  29.  
  30. class Adapter : public Adaptee, public ITarget
  31. {
  32. // Implementing the required standard vie the Adaptee
  33. public :
  34. double Request ( int i )
  35. {
  36. double val = SpecificRequest ( i , 3 );
  37. // double val = 37.77777779
  38. double rounded_own = floorf ( val * 100 ) / 100; // Result 37.77
  39. double nearest = roundf ( val * 100 ) / 100; // Result 37.78
  40. double rounded_up = ceilf ( val * 100 ) / 100; // Result 37.78
  41. return nearest;
  42. }
  43. };
  44.  
  45.  
  46. int main ()
  47. {
  48. // Shhowing the Adaptee in stand-alone mode
  49. Adaptee first;
  50. cout << " Before the new standard \nPrecise reading : " << endl;
  51. cout << first.SpecificRequest(5, 3) << endl;
  52.  
  53. //What the client really wants
  54. Adapter second;
  55. cout << "\nMoving to the new standard" << endl;
  56. cout << second.Request(5) << endl;
  57.  
  58. return 0;
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement