Advertisement
axyd

Lab 8, part 1

May 10th, 2016
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.87 KB | None | 0 0
  1. // This program is a driver that tests a function comparing the
  2. // contents of two int arrays.
  3. #include <iostream>
  4. #include <vector>
  5. using namespace std;
  6. // Function Prototype
  7. bool testPIN(vector <int>, vector <int>, const int);
  8.  
  9. int main()
  10. {
  11.     const int NUM_DIGITS = 7; // Number of digits in a PIN
  12.  
  13.     vector <int> pin1 = { 2, 4, 1, 8, 7, 9, 0 };
  14.     vector <int> pin2 = { 2, 4, 6, 8, 7, 9, 0 };
  15.     vector <int> pin3 = { 1, 2, 3, 4, 5, 6, 7 };
  16.  
  17.     /*
  18.     int pin1[NUM_DIGITS] = { 2, 4, 1, 8, 7, 9, 0 }; // Base set of values.
  19.     int pin2[NUM_DIGITS] = { 2, 4, 6, 8, 7, 9, 0 }; // Only 1 element is
  20.     // different from pin1.
  21.     int pin3[NUM_DIGITS] = { 1, 2, 3, 4, 5, 6, 7 }; // All elements are
  22.     // different from pin1.
  23.     */
  24.  
  25.     if (testPIN(pin1, pin2, NUM_DIGITS))
  26.         cout << "ERROR: pin1 and pin2 report to be the same.\n";
  27.     else
  28.         cout << "SUCCESS: pin1 and pin2 are different.\n";
  29.  
  30.     if (testPIN(pin1, pin3, NUM_DIGITS))
  31.         cout << "ERROR: pin1 and pin3 report to be the same.\n";
  32.     else
  33.         cout << "SUCCESS: pin1 and pin3 are different.\n";
  34.  
  35.     if (testPIN(pin1, pin1, NUM_DIGITS))
  36.         cout << "SUCCESS: pin1 and pin1 report to be the same.\n";
  37.     else
  38.         cout << "ERROR: pin1 and pin1 report to be different.\n";
  39.  
  40.     system("pause");
  41.     return 0;
  42. }
  43.  
  44. //******************************************************************
  45. // The following function accepts two int arrays. The arrays are *
  46. // compared. If they contain the same values, true is returned. *
  47. // If they contain different values, false is returned. *
  48. //******************************************************************
  49. bool testPIN(vector <int> custPIN, vector <int> databasePIN, const int size)
  50. {
  51.     for (int index = 0; index < size; index++)
  52.     {
  53.         if (custPIN[index] != databasePIN[index])
  54.             return false; // We've found two different values.
  55.     }
  56.     return true; // If we make it this far, the values are the same.
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement