C++ 1. Write a function named "acceptKey" that accepts an array of valid keys and its size. The method will read in a key from the user and check whether the user has entered one of the valid keys in the given array or not. If not, it will allow the user to try up to 3 times. If the user was able to enter the expected key number within 3 tries, it will return true. Otherwise, it returns false and key value of 0. In addition, it also returned the key to the caller. For example, assuming the given valid key array contains {111, 222, 333, 444} here are 2 different sets of runs:
C++
1. Write a function named "acceptKey" that accepts an array of valid keys
and its size. The method will read in a key from the user
and check whether the user has entered one of the valid keys in the given array or not.
If not, it will allow the user to try up to 3 times. If the user was able to enter the expected
key number within 3 tries, it will return true. Otherwise, it returns false and key value of 0.
In addition, it also returned the key to the caller.
For example, assuming the given valid key array contains {111, 222, 333, 444}
here are 2 different sets of runs:
Please enter your key: 123
Please enter your key: 456
Please enter your key: 789
Return false and the returned key of 0
Please enter your key: 123
Please enter your key: 456
Please enter your key: 444
Return true and the returned key of 444
Requirement: please use only pointer notation. No array notation.
The use of pass-by-reference parameters is also not allowed. Use pointer parameters instead.
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 4 images