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
|
#include <iostream>
using namespace std;
const int size = 5;
// test whether the first ‘SIZE’ elements of arrays A and B are equal
bool equal(int A[], int num[], int SIZE) {
int i;
if (num[SIZE] == A[SIZE]) {
cout << "Please re-enter your password." << endl;
cin >> num[SIZE];
return false;
}
else
return true;
}
void reset(int A[], int num[], int SIZE) {
int i;
int flag;
cin >> num[SIZE];
for (i = 0; i < SIZE; i++) {
cin >> num[i];
}
if (A == num) {
flag = equal(A, num, SIZE);
cout << "The password you entered matched the current password.\n";
}
else
cout << "New password has been set.\n";
}
bool guessw(int A[], int guess[], int SIZE) {
int i;
for (i = 0; i < SIZE; i++) {
if (A[SIZE] == guess[SIZE]) {
return true;
}
else {
return false;
}
}
return 0;
}
int main() {
int choice, guess[size], num[size];
int A[size] = {9, 1, 6, 5, 1};
cout << "Enter your choice:" << endl;
cout << "(1) Guess Password" << endl;
cout << "(2) Reset Password" << endl;
cout << "(3) Quit" << endl;
cin >> choice;
switch(choice)
{
case 1:
cout << "Please enter the password of guess." << endl;
cin >> guess[size];
guessw(A, guess, size);
if (guessw(A, guess, size))
cout << "You got it right!" << endl;
else
cout << "You got it wrong!" << endl;
system("ABORT");
break;
case 2:
cout << "Please enter a new password." << endl;
cin >> num[size];
reset(A, num, size);
break;
case 3:
cout << "Quit." << endl;
break;
default:
cout << "Invalid choice; program will be terminated." << endl;
break;
}
return 0;
}
|