Lab 10: Structs II
- Due No Due Date
- Points 1
Note: You are encouraged to work on the following with a partner.
Overview
In this lab, you'll get more practice with functions and structs.
Learning outcomes
By the end of this lab, you should be more comfortable...
- defining and invoking functions
- defining and using structs
- passing structs to functions
- using vectors of structs
Exercises
zyLab
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 16.30: Account struct (if you didn't do it last week)
- zyLab 16.37: Digital Address Book
Submitting
For the zyLabs, 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 10.1: Palindrome detector with struct
This PA option has all the same requirements as PA9.2: Palindrome detector, except that instead of using two parallel vectors to keep track of each word and whether it's a palindrome or not, you will use a vector of Palindrome struct instances. You will need to define a struct called Palindrome that has two fields: word and palindromeStatus (the latter indicates whether word is a palindrome or not).
Here are the specs (make sure to copy and paste these at the top of your source code; fill out your name, date, etc. and place an 'x' in each of the boxes; if any of the boxes aren't checked, then it's not ready to submit!).
// Name:
// Date:
// Partner:
//
// Specifications checklist for PA Option 10.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 allows the user to enter as many phrases as they want, one per line
// [ ] END is used as a sentinel and is not included in any of the processing or later output
// [ ] palindromes are accurately classified
// [ ] all palindrome phrases are listed in the output of the program above the non-palindrome phrases
// [ ] there's a "Palindromes:" header above the list of palindrome phrases
// [ ] there's a "Non-palindromes:" header above the list of no-palindrome phrases
// [ ] all phrases in both lists are indented slightly
// [ ] each of the required functions are defined and invoked properly
// [ ] bool IsPalindrome(string phrase)
// [ ] void PrintPalindromes(vector<Palindrome> phrases)
// [ ] void PrintNonPalindromes(vector<Palindrome> phrases)
// [ ] all functions have a properly formatted, completed, and accurate JavaDoc above them
// [ ] a stuct named Palindrome is defined with two fields: word and palindromeStatus
// [ ] a vector holding Palindrome instances is used to track all of the words and their palindrome status
PA 10.2 (advanced): Digital Rolodex
ZyLab 16.37 asks you to create a program to keep track of contacts (very similar to a Rolodex Links to an external site.). However, it's not very helpful to have a program that simply asks you to enter a bunch of contacts and then displays them. A more useful program is one that lets the user interactively add, remove, and search contacts. That's what you'll do in this PA.
In main, you should have a loop that presents the user with a menu, processes their choice, and then iterates unless the user entered the menu option to quit. Something like this:
do:
present menu (see below for menu choices)
read in menu selection
process selection
loop as long as the menu selection isn't quit
The menu should include these options:
- add a contact
- when processing, the program should read in all of the fields as in zyLab 16.37
- list all contacts
- when processing, print all of the contacts entered so far; include the index of each contact in the contacts vector—the user will need this when removing a contact
- remove a contact
- when processing, the program should ask the user for the index of the contact
- if the user elects to remove the contact at index i, then all the contacts that occur later in the vector (at indexes i+1 all the way up to size()-1) should be shifted down one index
- removing the contact at index 1 from a vector with these five contacts : { contact1, contact2, contact3, contact4, contact5 } would result in the vector having these elements: {contact1, contact3, contact4, contact5 }
- you'll have to resize the vector to be 1 less than it's previous size: contacts.resize(contacts.size()-1)
- search contacts by name
- when processing, the program should ask the user for the search phrase, then display only contacts whose name includes the search phrase
- e.g., the search phrase "Smith" would match contacts with the name "Joe Smith" and "Pat Smith"
- quit the program
You should store contacts in a vector. The program should include helper functions to handle the bulk of each operation (i.e., a function to list all contacts, a function to list only contacts whose name contains a search phrase, and to remove a contact).
Here's a demonstration of how it should behave:
Link
Links to an external site.
Here are the specs:
// Name:
// Date:
// Partner:
//
// Specifications checklist for PA Option 10.2 (Advanced)
// [ ] 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 defines a struct called Contact that includes the data members listed in zyLab 16.37
// [ ] a function is defined for each operation: adding a contact (ReadInContact, but include a prompt for each
// piece of information), listing all contacts (DisplayContacts), searching contacts, and removing a contact
// [ ] the user is presented with a menu with the options: add, list, remove, search, and quit
// [ ] if the user selects add, they are prompted to enter each piece of information
// [ ] if the user selects search, they are prompted to enter the search phrase and the contacts whose
// name contains the search phrase are displayed along with their indexes in the vector
// [ ] if the user selects to list all, all contacts are displayed with their indexes
// [ ] if the user selects to remove a contact, they are prompted to enter the index of the contact
// to remove and that contact is removed from the vector by shifting every contact after the delete
// contact down one position in the vector and resizing the vector
// [ ] if the user select quit, the program ends
// [ ] the menu is shown again after processing the previous selection until they select to quit
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
|
|
||
|