/* Vector Modification - This program is a modification of the National
Commerce Bank case study presented in Program 7.23. Pin 1, pin 2 and
pin 3 are vectors instead of arrays. The function is also modified,
so that it now accepts a vector instead of an array. */
#include "Utility.h"
/* Function prototype: Test pin */
bool testPin(vector<int>, vector<int>);
int main()
{
/* Variables: Pin 1, Pin 2, Pin 3 */
vector<int> pin1 = { 2, 4, 1, 8, 7, 9, 0 },
pin2 = { 2, 4, 6, 8, 7, 9, 0 },
pin3 = { 1, 2, 3, 4, 5, 6, 7 };
/* Compare the pins */
testPin(pin1, pin2) ? cout << "ERROR: pin1 and pin2 report to be the same.\n" :
cout << "SUCCESS: pin1 and pin2 are different.\n";
testPin(pin1, pin3) ? cout << "ERROR: pin1 and pin3 report to be the same.\n" :
cout << "SUCCESS: pin1 and pin3 are different.\n";
testPin(pin1, pin1) ? cout << "SUCCESS: pin1 and pin1 report to be the same.\n" :
cout << "ERROR: pin1 and pin1 report to be different.\n";
pauseSystem();
return 0;
}
/* **********************************************************
Definition: testPin
This function accepts to vectors:
* custPin<>
* databasePin<>
The vectors are compared. If they contain the same values,
true is returned. If they contain different values, false
is returned.
********************************************************** */
bool testPin(const vector<int> custPin, const vector<int> databasePin)
{
for (size_t compare = 0; compare < custPin.size(); compare++)
{
if (custPin[compare] != databasePin[compare])
return false;
}
return true;
}
Tuesday, February 14, 2017
Programming Challenge 7.15 - Vector Modification
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment