Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(the program is written using arrays. You have to change this program and modify

ID: 3891729 • Letter: #

Question

(the program is written using arrays. You have to change this program and modify the program to use vectors instead of arrays.)

Modify the following program so pin1, pin2, and pin3 a

re vectors instead of arrays

// This program is a driver that tests a function comparing the

// contents of two int arrays.

#include <iostream>

using namespace std;

// Function Prototype

bool testPIN(const int [], const int [], int);

int main ()

{

const int NUM_DIGITS = 7; // Number of digits in a PIN

int pin1[NUM_DIGITS] = {2, 4, 1, 8, 7, 9, 0}; // Base set of v

alues.

int pin2[NUM_DIGITS] = {2, 4, 6, 8, 7, 9, 0}; // Only 1

element is

//

different from pin1.

int pin3[NUM_DIGITS] = {1, 2, 3, 4, 5, 6, 7}; // All elem

ents are

//

different from pin1.

if (testPIN(pin1, pin2, NUM_DIGITS))

cout << "ERROR: pin1 and pin2 report to be the same. ";

else

cout << "SUCCESS: pin1 and pin2 are different. ";

if (testPIN(pin1, pin3, NUM_DIGITS))

cout << "ERROR: pin1 and pin3 report to be the same. ";

else

cout << "SUCCESS: pin1 and pin3 are different. ";

if (testPIN(pin1, pin1, NUM_DIGITS))

cout << "SUCCESS: pin1 and pin1 report to be the same.

";

else

cout << "ERROR: pin1 and pin1 report to be different. ";

return 0;

}

//******************************************************************

// The following function accepts two int arrays. The arrays are *

// compared. If they contain the same values, true is returned. *

// If the contain different values, false is returned. *

//******************************************************************

bool testPIN(const int custPIN[], const int databasePIN[], int

size)

{

for (int index = 0; index < size; index++)

{

if (custPIN[index] != databasePIN[index])

return false; // We've found two different values.

}

return true; // If we make it this far, the values are the same.

}

int main ) const int NUM_DIGITS 7;// Number of digits in a PIN int pin1[NUM_DIGITS] 12, 4, 1, 8, 7,9, 0|; // Base set of values. int pin2[NUM_DIGITS] 12, 4, 6, 8,7,9,0;//Only 1 element is // different from pin1. int pin3[NUM_DIGITS] (1, 2,3, 4,5,6, 7;//All elements are // different from pin1. if (testPIN(pin1, pin2, NUM_DIGITS) cout

Explanation / Answer

#include <iostream>
#include<bits/stdc++.h>

using namespace std;

bool testPIN(const vector<int>& custPIN, const vector<int>& databasePIN, int size);

int main ()

{

const int NUM_DIGITS = 7; // Number of digits in a PIN

vector<int> pin1 = {2, 4, 1, 8, 7, 9, 0}; // Base set of values.

vector<int> pin2 = {2, 4, 6, 8, 7, 9, 0}; // Only 1 element is different from pin1.

vector<int> pin3 = {1, 2, 3, 4, 5, 6, 7}; // All elements are different from pin1.

if (testPIN(pin1, pin2, NUM_DIGITS))

cout << "ERROR: pin1 and pin2 report to be the same. ";

else

cout << "SUCCESS: pin1 and pin2 are different. ";

if (testPIN(pin1, pin3, NUM_DIGITS))

cout << "ERROR: pin1 and pin3 report to be the same. ";

else

cout << "SUCCESS: pin1 and pin3 are different. ";

if (testPIN(pin1, pin1, NUM_DIGITS))

cout << "SUCCESS: pin1 and pin1 report to be the same. ";

else

cout << "ERROR: pin1 and pin1 report to be different. ";

return 0;

}

//******************************************************************

// The following function accepts two int vectors. 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, int size)

{
if (custPIN == databasePIN)
return true;
else
return false;

}

Output:

SUCCESS: pin1 and pin2 are different.                                                                                            

SUCCESS: pin1 and pin3 are different.                                                                                            

SUCCESS: pin1 and pin1 report to be the same.