For these two labs you are going to construct functionality tocreate a simple ToDo list. Conceptually the ToDo list uses astructure called MyToDo to hold information about each todo item.The members of the MyToDo struct are description, due date, andpriority. Each of these items will be stored in an array calledToDoList.
Visually think of the ToDoList like this:
There are two ways to add items to the ToDoList. The first is tosimply fill out a MyToDo struct and pass it to a function calledaddToList. This is depicted in the following:
The second way to add items to the list is by passing to thefunction the description (as a string), the priority (as an int),and the DueDate (as a string).
When you get an item from the ToDoList, you call a functioncalled getNextItem which returns the first item in the list. Witheach successive call to getNextItem, you get the next item in thearray. For instance, the first call to getItem will get “Dr.Appointment”, ” when you make the second call to getNextItem youwould get “Groceries” so on and so forth. After you get the lastperson from the array the next call to getNextItem will start overat the beginning (“Dr. Appointment” in this case).
This lab is intended to prepare you to start working with objectoriented programming. Just so you know, in the advanced class wewill be creating classes and objects. A class is an encapsulationof data and functions that operate on that data. Since we haven’tcovered how to create a class here we are going to simulate it. Howdo we do that? Well hopefully it will be simple.
First off we need to determine what the data section is. In thiscase it is going to be the array called ToDoList that holds MyToDostructs. Because the functions you write need to operate on thedata in some way you are going to have to put this array in globalscope. This way all of the functions have direct access to thearray without it having to be passed around. One thing of note andthat is if we think about this from main’s perspective main shouldnot know how the data is stored or what it is stored in. All mainshould know is that if you use the addToList function you can add anew MyToDo item to the todo list. This is what we call a publicinterface to private data. Since we are putting the array in globalscope in ToDo.cpp we pseudo encapsulate it. This means that onlyToDoList functions have access to the array and variables in globalscope. Of course since it is in global scope there is a way aroundthis but again, we are simulating.
|addToList||A MyToDo Struct||Adds a single MyToDoStruct to the ToDoList. The struct shouldcontain information about a todo item|
|addToList||Description (string), date (string),priority (int)||Overloaded function that adds a single MyToDo Struct to theToDoList. In this case you are passing individual items that needto go into a struct|
|getNextItem||A MyToDo struct (by reference)||Gets the next MyToDo struct from the ToDoList. When the lastitem is returned the next call to getNextItem should return thefirst item in the list|
|getNextItem||Description (string), date (string),priority (int)||All variables should be passed by reference, This functionworks like the overloaded version except that it returns theinformation from the struct as individual values not structs|
|getByPriority||An array of MyToDo structs, priority (asint)||This function searches theToDoList array looking for items thathave a matching priority. A list of all of the items with matchingpriorities will be returned to main|
|printToDo||None||Simply prints out each item in the todo array list onetime.|
Ok, so you should have three files
main.cpp – holds you main function
ToDo.cpp – holds the ToDo list functions that are required forthe assignment
ToDo.h – which holds the definitions for ToDo list
Here is how things should flow for theaddToList function:
In main create a MyToDo struct
fill the struct with information about an item to do. Get itfrom the keyboard if you want.
Pass the struct to addToList which attempts to add the MyToDo tothe next slot in the array.
If the ToDoList is full and an item cannot be added thenaddToList returns false
If the item was successfully added to the array addToListreturns true
Here is how things should flow for the getNextItemfunction:
In main create a MyToDo struct
call getNextItem function passing the created struct byreference
If the ToDoList is empty getNextItem simply returns false
If the ToDoList is not empty the next itme in the ToDo list iscopied to the struct passed by reference and true is returned
*If the last item in the todo list is returned back, the nextcall to getNextItem will get the first item in the todo listagain.
*This is circular so if have 5 items in the ToDo list and youcall getNextItem in a loop 25 times from main all five todo itemswill be returned five times.
Here is how the getByPriortiy functions shouldflow:
In main create an array that will hold MyToDo Items
pass the array along with a priority to search for to thegetByPriority function.
the getByPriority function will search the array looking tomatch the priority
If a match is found the found the struct is copied to the arraythat was passed to the function.
If no match is found the function simply returns false.
When the funciton returns from main you should be able to printa list of items with the matching priority.
Conceptually what you are creating is a circular queue that holdsstructs. Because you need to know where the next available spot inthe array is you will need an index. This should be in the globalsection of ToDo.cpp. You are actually probably going to need twoindexes, one to keep track of what is being added, and one thatkeeps track of what is being removed.
What not to do
Using any of the following will drop your grade for thisassignment by 70%
cin in any funciton other than main
*cout in any funciton other than main and the printToDofunction
passing the ToDoList array to any function.