Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- #include <stdlib.h>
- #include <string>
- #include <vector>
- using namespace std;
- class Adaptee
- {
- // Existing way request are implemented provide full precision
- public :
- double SpecificRequest ( double a, double b )
- {
- return a / b ;
- }
- };
- class ITarget
- {
- // Required standard for requests. Rough estimate required
- public :
- virtual double Request ( int i ) = 0;
- };
- class Adapter : public Adaptee, public ITarget
- {
- // Implementing the required standard vie the Adaptee
- public :
- double Request ( int i )
- {
- double val = SpecificRequest ( i , 3 );
- // double val = 37.77777779
- double rounded_own = floorf ( val * 100 ) / 100; // Result 37.77
- double nearest = roundf ( val * 100 ) / 100; // Result 37.78
- double rounded_up = ceilf ( val * 100 ) / 100; // Result 37.78
- return nearest;
- }
- };
- int main ()
- {
- // Shhowing the Adaptee in stand-alone mode
- Adaptee first;
- cout << " Before the new standard \nPrecise reading : " << endl;
- cout << first.SpecificRequest(5, 3) << endl;
- //What the client really wants
- Adapter second;
- cout << "\nMoving to the new standard" << endl;
- cout << second.Request(5) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement