Lab 7: Functions I
- 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 using functions.
Learning outcomes
By the end of this lab, you should be more comfortable...
- defining functions
- deciding on what parameters a function should take
- deciding on the return type of a function
- invoking functions
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.
- zyLab 5.23: Contains the character
- zyLab 6.19: Miles to track laps
- zyLab 6.21: A jiffy
- zyLab 6.23: Swapping variables
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 7.1 (Advanced): Word stats with functions
This PA is the same as PA 6.1, except you need to define and use the following functions:
- a function that downcases a word
- input: a word
- return: the downcased version
- a function that prints a word's entry in the distribution list (i.e. "lamb ####")
- input: the word to print and its frequency
- return: nothing (it should display text to the screen, but not return anything)
Here are the specs:
// Name:
// Date:
// Partner:
//
// Specifications checklist for PA Option 7.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 or hanging
// [ ] all output and prompts look clean (correct spelling, capitalization, nothing squished)
// [ ] all prompts specify the required format of the input and work as expected
// [ ] the program prompts the user for their text
// [ ] all words entered by the user are read in until the sentinel END is read in
// [ ] the END sentinel is not used in any of the stats
// [ ] the program uses parallel (multiple) arrays or vectors to store words and their counts
// [ ] words are stored and reported at the end in all lower case
// [ ] these stats are displayed at the end and are accurate:
// [ ] the number of total words entered
// [ ] the number of distinct words (case insensitive)
// [ ] the number of characters (the length of all input words summed together)
// [ ] the distribution of distinct words and their corresponding counts represented as a bar graph
// [ ] the left side of the bar graphs are aligned across words
// [ ] a function is defined and invoked correctly that downcases words
// (inputs: a word, return: the downcased)
// [ ] a function is defined and invoked correctly that prints a word's entry in the distribution output
// (inputs: a word and its frequency, return: nothing)
// [ ] all function have a JavaDoc above them describing the function, parameters (if any), and return value (if any)
PA 7.2: Password generator++ with functions
This PA is the same as PA 5.1, except you need to define and use the following functions:
- a function that processes the user's character group input (the line where they enter, for example, "uppers specials") and generates a string of characters that combines all the specified groups
- input: a string of character group names (e.g., "lowers nums")
- return: the string of characters from the specified character groups (e.g., "abcdefghijk....0123456789")
- a function that generates a password
- input: the length of the password, the string of characters to sample the password from
- return: a randomly generated password (a string of the specified length with characters sampled from the second parameter)
Here are the specs:
// Name:
// Date:
// Partner:
//
// Specifications checklist for PA Option 7.2
// [ ] 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 or hanging
// [ ] all prompts specify the required format of the input and work as expected
// [ ] 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
// [ ] a function is defined and invoked correctly that parses the user's character group selections
// (inputs: a string containing the names of character groups to include,
// return: a string containing the characters from the specified character groups)
// [ ] a function is defined and invoked correctly that generates a password
// (inputs: the length of the password, a string containing the characters to sample the password from,
// return: a randomly generated password of the given length using only characters from the second parameter)
// [ ] all function have a JavaDoc above them describing the function, parameters (if any), and return value (if any)
Submit your PA to First programming assignment, Second programming assignment, Third programming assignment, Fourth programming assignment, or Fifth programming assignment based on whether this is your first, second, etc. 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
|
|
||
|