Use beginner level of C++ string
CS 143 Laboratory Exercise 9
Purpose:
The purpose of this lab is to gain practical experience with strings, random number, and enumerated types.
Contents:
I. Startup II. Course Evaluation
III. String and Character manipulation IV. Random Numbers and enumerated types
I. Startup:
You will work with your lab partner to find the solutions to the proposed problems. At the end of the lab session your group should submit the code your write today via Drexel Learn. Only one submission per group is required. Make sure you and your partner agree on who will be responsible for submitting your lab assignment for this week.
Note: It is important that both partners participate in the programming process for the entire assignment. One student shouldn't hog the machine, or bully the others into doing things a certain way. Try to act professional when working with your partners - treat them with the respect of knowledgeable co-workers on a job.
II. Course Evaluation: Please take a few minutes to complete the College of Computing and Informatics course evaluation form. The form is available at: https://cci.drexel.goaefis.net/index.cfm Each student must complete the course evaluation form before starting the lab exercise. NOTE: The completion of the course evaluation form is part of you grade for this lab, so please make sure you show the lab instructor that you completed the evaluation form. We will make a list of the students who complete the evaluation so they can receive full credit for the lab.
III. String and Character manipulation:
Start up a new project for today’s lab. If you are working on one of the classroom laptops, it’s recommended that you save your project in the Desktop.
Add the following header comment at the top of the file:
//Lab Assignment #9, Characters and Strings manipulation //Program Name: //Purpose of the program: //Authors: Your and your partner’s names //Date: write today’s date Write a program that will check a new password and make sure it’s valid. The program will start by asking the user to enter his/her full name (as one string that is, the full name must be store in one string variable), and then his/her login ID (also a string variable). Then the program as the user to enter a new password and validates it. Here is the criteria for valid passwords: Must contain at least 8 characters
Must contain at least one character from three of the following four categories:
Uppercase letters (A – Z). Lowercase letters (a – z). Numbers (digits 0 – 9). Non-alphabetic characters (for example: @ # $ % ^ & * - + = | \ { ] ? / etc.).
Must not contain any of following:
The user’s login ID. The user’s first or last name The user’s initials (defined as the first name initial followed by the last name initial)
If the password entered by the user meets the all criteria the program let’s the user know that the password has been changed. If the password entered does not meet at least one of the criteria, the program issues an error message and ask the user to try again (as many time as needed unti lthe user provides a valid password). You should consider writing functions to solve this problem, othewise you may end up with a very long main function. Here is a typical sample run for the program:
IV. Random Numbers and enumerated types:
Remove the current cpp file from the project, following these steps: 1) In the Solution Explorer, find the Source Files folder and then your cpp file.
2) Right-click on the name of your cpp file. You will see a menu pop-up. Pick the Remove option. You will see a confirmation window. Click on the Remove button.
3) Now add a New Item, by right-clicking the Source File folder and then Add New Item
4) At Add New Item dialog box select C++ File (.cpp)). Give this file a name and then click on the Add button.
Your source code must include the following header comment at the top of the file:
//Lab Assignment #9, Random Numbers and enumerated types //Program Name: //Purpose of the program: //Authors: Your and your partner’s names //Date: write today’s date
For this part of the lab we are going to implement a simple guessing game that the user can play against the computer. Start by creating an enumerated type to represent fruits (have at least 10 fruits of your choice listed). Generate a random number between 0 and 9 – this number will be used to access a “random” fruit from the list. This will be the computer choice. The program will ask the user to guess the name of the fruit the computer has picked. The user then enters a guess. If the user is right he/she wins. Otherwise the computer wins. The user can play as many times as he/she wants. Once the user decides to quit the game, display the tally, that is, the number of times the computer won and the number of times the player won.
This program must be implemented using enumerated types. You must write at least two functions: One to handle the input of a fruit as an enumerated type; and one to handle the display of a fruit name. Here is a typical sample run for the program:
Submitting your lab work
For today’s lab your group must submit the .cpp files for the programs you wrote today. Please make sure you upload and submit your files via Drexel Learn by the end of the lab session, or by Friday at 11:59 PM at the latest. Submissions via email will not be graded.
For the programs: Do not copy and paste you code in a Word file (or any other type of document). Only cpp files will be read and graded.