Advertisement
Guest User

C++ Help

a guest
Apr 7th, 2020
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. //worked with kenneth, alejandro, elijah, eric
  2.  
  3. #include <iostream>
  4. #include <string>
  5. using namespace std;
  6.  
  7. /**
  8.    A simulated lock with digit buttons.
  9. */
  10. class Lock
  11. {
  12. public:
  13.    /**
  14.       Simulates a digit button push.
  15.       @param button a digit 0 ... 9
  16.    */
  17.    void push(int button);
  18.  
  19.    /**
  20.       Simulates a push of the open button.
  21.       @return true if the lock opened
  22.    */
  23.    bool open();
  24. private:
  25.    string combination = "0042";
  26.    string input;
  27. };
  28.  
  29.  
  30.  
  31. void Lock::push(int button)
  32. {
  33.    string button_as_string = to_string(button);
  34.    . . .
  35. }
  36.  
  37. bool Lock::open()
  38. {
  39.    . . .
  40. }
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47. int main()
  48. {
  49.    Lock my_lock;
  50.    my_lock.push(4);
  51.    my_lock.push(2);
  52.    cout << boolalpha;
  53.    cout << my_lock.open() << endl;
  54.    cout << "Expected: false" << endl;
  55.    my_lock.push(0);
  56.    my_lock.push(0);
  57.    my_lock.push(4);
  58.    my_lock.push(2);
  59.    cout << my_lock.open() << endl;
  60.    cout << "Expected: true" << endl;
  61.    my_lock.push(0);
  62.    my_lock.push(4);
  63.    my_lock.push(2);
  64.    cout << my_lock.open() << endl;
  65.    cout << "Expected: false" << endl;
  66.    my_lock.push(0);
  67.    my_lock.push(0);
  68.    my_lock.push(0);
  69.    my_lock.push(4);
  70.    my_lock.push(2);
  71.    cout << my_lock.open() << endl;
  72.    cout << "Expected: false" << endl;
  73.    my_lock.push(0);
  74.    my_lock.push(0);
  75.    my_lock.push(4);
  76.    my_lock.push(2);
  77.    cout << my_lock.open() << endl;
  78.    cout << "Expected: true" << endl;
  79.    return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement