Lab 11: nCurses
- Due No Due Date
- Points 1
- Submitting a file upload
- File Types cpp, pdf, docx, and doc
Note: You are encouraged to work on the following with a partner.
Overview
In this lab, we're changing gears a bit so you can play around with a slightly more visually appealing console experience. Specifically, the ncurses library.
Learning outcomes
By the end of this lab, you should be more comfortable...
- using functions
- reading and modifying existing code
- compiling an ncurses program
- using basic ncurses functions
- solving programming problems
Exercises
This lab has a report associated with it, which you should fill out with your partner. Make a copy of the Lab 11 Report document Links to an external site. and share it with your partner.
For part 1, download this source code: snake.cpp Download snake.cpp
For part 2, download this source code: form.cpp Download form.cpp
Follow and answer the questions in the report document.
Submitting
Upload a copy of your lab report (you can download it as a PDF or Word Document) and your two modified source code files (snake.cpp and form.cpp).
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 11.1: Cipher with dynamic delta
Start with the (fixed) cipher from class: pa11-1.cpp Download pa11-1.cpp. Adapt it to use rand() to generate a new delta for each character being processed. As long as the encryption and decryption of a file seeds the random number generator with the same seed, we will get the same sequence of random numbers from rand(). Rather than having the user input the seed directly (i.e., a number), ask the user for a password phrase (any string, which may include spaces). Write a function that reduces this to an unsigned int using the following formula:
seed = ∑ipasswordi⋅(i+1),
That is, for each character in the password, multiply its ASCII value by its index+1. Sum this value across all the character in the password. For example, the password: abc would result in the following seed: 97*1 + 98*2 + 99*3 = 590.
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 11.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 user is prompted for a password phrase (which can include spaces)
// [ ] a seed is generated using the password using the formula described in the PA description
// [ ] the seed is used to seed the random number generator once using srand()
// [ ] for each character being encrypted or decrypted, a delta is computed using a call to rand()
// [ ] files encrypted with a given password can be decrypted with that same password
// [ ] generally speaking, files cannot be decrypted with a different password than was used
// for encryption
PA 11.2 (advanced): Digital Rolodex with files
Extend PA 10.2 Digital Rolodex to include two additional menu options:
- load a file of contacts—this should ask the user for the name of the file to load and then read in that file, replacing the current list of contacts
- save contacts to a file—this should ask the user for the name of the file to save the contacts to, then write all of the contacts to that file
You should define a function for each of these.
You will need to establish a format for you files. For example, you could place the value of each Contact data member on its own line of the output file. In your load function, you will then need to ensure that you read in the data in the same order you wrote it in the save function.
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 11.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, load, save, 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 selects load, they are prompted for the name of the file to load, which is then read in
// and the current contacts list is replaced with the ones from the file
// [ ] if the user select save, they are prompted for the name of the file to save to, and the contacts list
// is written to that file
// [ ] if the user selects 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
|
|
||
|