Assignment 03

Due: Friday, Feb. 9, 2018 at noon 100 points

The Specialnesses: Now you need to know the secret stuff:

  1. the special, super-secret and highly-classified lock #1 value is .... 15

  2. the required distance for lock #2 is .... 17.45

  3. the tolerance for the aforementioned required distance is .... 0.1

  4. the magic ratio for lock #3 is ... 3.4

Notes: A few things to think about. First, for this assignment, you are to use if and if-else statements and NOT the switch-case statement. Second, you need to be able to compute the length of a string-type variable. To do this, you will need to #include<string> and use a special string library function. The easy way to explain how to use this function is simply to show you an example code block. Explaining functions in C++ will be done in a much later lecture.

For this assignment, you will submit a single C++ compilable file containing a program written in C++. Remember, to submit a file for this course electronically, from the directory in which the file resides type in at the UNIX prompt the command: cssubmit 1570 section_letter assignment_number. Be sure that only the file you want to submit is in that directory - make a directory for every assignment! The submit system will deliver every .cpp file in the current directory to me. Name your file a meaningful name and give it a .cpp extension since you will be compiling it. Also, make sure that you compile and run your program using the GNU (g++) compiler before submitting to make sure that it will work for the submit script.Background: Have you ever had a roommate who quietly steals your stuff and doesn't want to own up to it because he/she thinks it's just minor thievery? Yeah, real bummer, eh? BoJack has that problem. One of his friends swipes his favorite cookies from his cookie jar. He thought about loading up the cookie jar with rat traps so that Todd would get his dirty little fingers in a bind the next time!! But, BoJack has a real plan. He builds a device that has three different kinda locks on it, all run by c++ code. You are to write the program that controls it. And, once again, this is part of the reason Atlantis sank! Petty thievery. Yep, it did in the Auto-man Empire, the Row-man Empire, and the Man-GoLeanOnEm Empire. Ghengis Khan, and his brother Don, they could not keep from keepin' on.

Specifications: So, your program is to first prompt for and read in the user's name and use that name in the next prompt. (Remember: C++ will only read up to the first space when inputting a string value. Input a first name only that has no spaces in it.) Next, your code will go through a sequence of prompts for information from the user to unlock three locks. If at any lock the user (finally) fails to input the satisfactory information, control will pass to the end of the program whereupon the appropriate message is displayed. If all locks are "unlocked", then your program will output a congratulations message to the user and eject 4 cookies from the fourth thumb drive on your computer.1 If a lock is unlocked, output an appropriate message and move on to the next lock.

  • Lock #1: Prompt for and input a positive five-digit integer. For this assignment, assume the proffered value is indeed positive and five-digit and an integer. [Note: if you code the foregoing requirement, it won't matter if the input value isn't five-digit or negative anyway!] The first lock is unlocked IF the product of the tens digit and the thousands digit of the input is a special, super-secret, highly-classified value. That value is revealed below (for all the world to see) ... but don't tell anyone. If the input doesn't unlock the lock, give the user one more try by reprompting them. Then either pass them on to the next lock or to the end of the program. The special, super-secret, highly-classified lock #1 value is the number of turns for a tumbler-type lock. This has no bearing whatsoever on your code, but is vitally important for all you lock-o-maniacs out there.

  • Lock #2: Prompt for and input a positive real (floating point) number. This value is the amount that the second locking mechanism slides a release. If that input value is with in tolerance of the required distance, then the lock opens. The required distance and the tolerance are revealed below along with the super-secret info for lock #1. Thus, your code should compute the difference of the input value and the required distance and see if that is less than the tolerance. If so, the lock is opened and you move on to the next lock. If not, well that's just too bad...they don't get another chance.

  • Lock #3: Prompt for and read in a string that represents a "secret pass code" made up of characters from the keyboard, e.g."password" - that's a particularly popular one that is very, very secure. Your code will divide the integer part of the secret distance required for lock #2 by the length of the string input for lock #3. If that value is the "magic ratio" for lock #3, given below with all the other top secret information the world shouldn't know, then the lock is open. If not, then the lock is not opened and the user is ushered to the end of the input once again. On the off chance that the user is really tricky and enters a single character string (length of one), then we conclude he/she is smarter than all of us and your code should unlock the third lock.

After the user has unlocked all the locks with correct and astute inputs and your code has output accolades extolling their virtues and worthinesses, the program should end. However, if the user has not managed to input information to unlock all the locks, then your code should prompt them (yes/no) to try again (starting from lock #1), and continue to do so until they either respond in the negative or get it right.

ex: string variable;

int length;

cout << "enter a string of characters: ";

cin >> variable; // suppose user enters "hello" and hits enter (without the quotes, of course)

length = variable.length(); // assigns the length of the input to integer variable named length, the value assigned will be an integer

cout << length; // outputs 5, since there are 5 chars in "hello"

When you submit: As always, when you submit, you will become the user of the program and will have to enter inputs. For consistency, all students submitting will use the same inputs. They are:

  • enter your name or some other name

  • enter 12345, then re-enter 13456

  • enter 16

  • choose to start over

  • enter 15934

  • enter 17.5

  • enter "bye"

  • choose to start over

  • enter 13456

  • enter 17.4

  • enter "u", or some other clever single character string

  • the program should end at this point

As always, if you have any questions, be sure to ask your instructor.

1Ejecting the cookies from the thumb drive part of this assignment is optional. In fact, if you can pull that off, we'll give you 5 bonus points.