CSC160 Programming Assignment 2
Contents
Overview
Your job in this assignment is to create the second iteration of the Notes program. You are going to redesign your program to use structs and functions. The program should run from the command line in much the same as in PA1, except more information will be kept for each note: the note itself, a priority level (1 is high, 2 is medium, and 3 is low), and a boolean that keeps track of whether the note has been deleted (we call this a flag). Notes with the deleted flag unset (i.e., false
) should have their contents and priority level displayed. Notes with the deleted flag set should not display the the content or priority level.
Step 1
The first thing you should do is to refactor your code to use a struct for each note. Structs are useful for storing values for a set of variables. In this assignment, you should define a struct that holds data for a note (i.e., the note's text, its priority level, and a isDeleted
flag). Make sure you can get your PA1 code to work with structs before moving on to adding functions. The reason for this order is that using structs is going to change the type of parameters you will need for you functions.
Step 2
Once your code uses structs for the notes, you should refactor your code to use multiple functions. You can use as many functions as you want. In general, function definitions should be cohesive, relatively short, and target a single (or very few) goal(s). Blocks of code that you found yourself repeating over and over again in PA1 are good candidates for functions. Think about whether you need to modify the value of the parameters passed in—if so, be sure to pass by reference and not pass by value!
Here's an example of my version of PA2 running (my input is in orange just to make it obvious):
$ ./pa2 Current notes: Note 1: Note 2: Would you like to [d]elete|[m]odify a note or [q]uit? m Which note would you like to modify? 1 Please enter the new note: Finish homework Please enter the new note's priority level: 1 Current notes: Note 1: Finish homework (Priority 1) Note 2: Would you like to [d]elete|[m]odify a note or [q]uit? m Which note would you like to modify? 2 Please enter the new note: Hit the gym Please enter the new note's priority level: 2 Current notes: Note 1: Finish homework (Priority 1) Note 2: Hit the gym (Priority 2) Would you like to [d]elete|[m]odify a note or [q]uit? d Which note would you like to delete? 1 Current notes: Note 1: Note 2: Hit the gym (Priority 2) Would you like to [d]elete|[m]odify a note or [q]uit? q Okay, goodbye!(Back to top)
Requirements
- Does all the things that PA1 required
- Structs are used to store three pieces of information per note:
- note's content
- note's priority (1, 2, or 3)
- an
isDelete
flag that indicates if the note has been deleted
- The output should look like the example above
- Functions should be used appropriately
- Everything in the rubric (posted on Canvas) should be followed
- Make sure to follow the style guidelines
Start by copying your PA1 and work from there.
(Back to top)Extra credit
Make sure you indicate in your program header (in the description) whether you've attempted the extra credit, otherwise I won't count it!!!
EC-1 (2 points)
Make your program hold five notes, not just two.
EC-2 (5 points)
Add some extra functionality, like the ability to copy or move notes. You can be creative here, but make sure you let me know ahead of time what you want to do so I can let you know if it's sufficient.
(Back to top)Submissions
Everything should be uploaded to Canvas by the deadline posted.
(Back to top)