Lab 5: Loops
- Due No Due Date
- Points 1
Note: You are encouraged to work on the following with a partner.
Overview
In this lab, you'll practice more with branches, Boolean expressions, and string functions.
Learning outcomes
By the end of this lab, you should be more comfortable...
- using loops to execute code 0 or more times
- breaking programming problems into smaller pieces
Exercises
Complete the following zyLabs in the zyBook. While you do them, be sure to implement incrementally—write a line or two of code, then compile/run it. Test frequently by clicking "Submit mode" and then "Submit for grading". You have unlimited submits, so don't worry about using some quota up.
- pick one of the zyLabs from Lab 4: Branching II you haven't completed (if any) and work on it
- zyLab 4.19: Password modifier
- zyLab 4.25: Palindrome
- zyLab 4.26: Brute force equation solver
Submitting
Click "Submit mode" then "Submit for grading" when you are finished so I can see that you have done the zyLab.
PA options
Please see the syllabus and course schedule (both on the homepage) for more information about how many programming assignments you are required to pass, due dates, etc. Of note: you do not need to attempt every or even most PAs.
PA 5.1: Password generator++
This is similar to PA option 4.1, except:
- the program should ask the user to enter the desired password length directly (e.g., 5, 10, 12, 20, 100, etc.) rather than select from the options "short", "medium", and "long"
- the program should ask the user to enter how many random passwords to generate, and the program will generate that many (instead of only one password)
For example, consider the following run of the program that generates 5 passwords, each of length 15 characters, and consisting of random upper case, numeric, and special characters (orange text is the user input):
$ ./pa5.1.exe
==== PASSWORD GENERATOR ====
What character groups would you like to include in the generated passwords? Enter one or
more of the following on the same line:
uppers -- upper case letters A-Z
lowers -- lower case letters a-z
nums -- numbers 0-9
specials -- special characters (!@#$%^&*()-_[]'";:.,><~`\|)
> uppers specials nums
Enter the number of characters should each password have: 15
Enter the number of passwords would you like to generate: 5
Passwords:
----------
A834#,3$3IUN#,(
.~MX@;)LF9$-^,%
Z~SHXVL4Z@]_.,U
DH8~~(SIV,"6!$0
4`":Q#9F6<$SMY%
// Name:
// Date:
// Partner:
//
// Specifications checklist for PA Option 5.1
// [ ] the header includes your name and anyone you worked with
// [ ] the header includes this specifications checklist
// [ ] the code in indented properly (use the autoformatter if you're not sure)
// [ ] useful comments are present above chunks of code that "hang together" (work toward a higher level goal)
// [ ] the identifiers are well named
// [ ] the program compiles
// [ ] the program runs without crashing
// [ ] all output and prompts look clean (correct spelling, capitalization, nothing squished)
// [ ] the program prompts the user for a line of input that include each of the character
// groups they want to include in their password
// [ ] the valid group options are: uppers (A-Z), lowers (a-z), nums (0-9),
// specials (!@#$%^&*()-_[]'";:.,><~`\|)
// [ ] each character group is stored in its own constant string, defined at the top of main,
// using the proper conventions (the constant names are all caps)
// [ ] your program uses branches to decide whether to add each character group to the string
// of characters to generate the password from
// [ ] the program prompts the user for the length of the passwords once at the beginning (not for each password)
// [ ] each generated password is of that length
// [ ] the program prompt the user for the number of passwords to generate
// [ ] the program generates as many passwords as specified by the user
// [ ] each password is generated randomly using only characters from the user-specified groups
// [ ] `srand(time(0))` is used once at the beginning of the program to provide random results on
// each run of the program rather than `srand(1)` or something similar
// [ ] the program uses the appropriate loop types
Here are the expected scores for several combinations of easy and difficult questions answered correctly (this is not exhaustive):
Submit your PA to First programming assignment, Second programming assignment, Third programming assignment, or Fourth programming assignment based on whether this is your first, second, third, or forth PA. If you are working with a partner, both of you must submit individually.
Rubric
Criteria | Ratings | ||
---|---|---|---|
Worked diligently on the lab problems
|
|
||
Submitted all materials according to the instructions
|
|
||
|