1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
#include <vector>
#include <iostream>
using namespace std;
// prototype
bool samePIN(vector<int> & customerPIN, vector<int> & databasePIN);
void writePIN(vector<int> & pin); // You must define the function below
int main()
{
const int NUM_DIGITS = 7;
vector<int> pin1 = { 2, 4, 1, 8, 7, 9, 0 };
vector<int> pin2 = { 2, 4, 6, 8, 7, 9, 0 };
vector<int> pin3 = { 1, 2, 3, 4, 5, 6, 7 };
if (samePIN(pin1, pin2))
cout << "Error: pin1 and pin2 report to be the same.\n";
else
cout << "SUCCESS: pin1 and pin2 are different.\n";
if (samePIN(pin1, pin3))
cout << "Error: pin1 and pin3 report to be the same.\n";
else
cout << "SUCCESS: pin1 and pin3 are different.\n";
if (samePIN(pin1, pin1))
cout << "Error: pin1 and pin1 report to be the same.\n";
else
cout << "SUCCESS: pin1 and pin1 are different.\n";
return 0;
}
// Return TRUE if PINs are different
// Return FALSE if the PINs are the same
bool samePIN(vector<int> & customerPIN, vector<int> & databasePIN)
{
if (customerPIN.size() != databasePIN.size())
return false; // different in sizes
int length = customerPIN.size();
for (int i = 0; i < length; ++i)
{
if (customerPIN[i] != databasePIN[i])
return false;
}
return true;
}
void writePIN(vector<int> & pin)
{
/*
Your function must iterate through the PIN vector such that the
PIN is printed out enclosed in square brackets as follows:
[2 4 1 8 7 9 0]
There is a single space between each digit but no space after the last digit
*/
}
|