Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ LAB 19 Construct functionality to create a simple ToDolist. Conceptually the ToDo list uses a structure called MyToDo to hold information about each todo

C++

LAB 19

Construct functionality to create a simple ToDolist. Conceptually the ToDo list uses a structure called MyToDo to hold information about each todo item. The members of the MyToDo struct are description, due date, and priority. Each of these items will be stored in an array called ToDoList. The definition for the MyToDo struct should be placed in the header file called ToDo.h

Visually think of the ToDoList like this:

image text in transcribed

There are two ways to add items to the ToDoList. The first is to simply fill out a MyToDo structand pass it to a function called addToList. This is depicted in the following:

image text in transcribed

The second way to add items to the list is by passing to the function 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 function called getNextItem which returns the first item in the list. With each successive call to getNextItem, you get the next item in the array. For instance, the first call to getItem will get "Dr. Appointment", " when you make the second call togetNextItem you would get "Groceries" so on and so forth. After you get the last person from the array the next call to getNextItem will start over at the beginning ("Dr. Appointment" in this case).

Details: This lab is intended to prepare you to start working with object oriented programming. Just so you know, in the advanced class we will be creating classes and objects. A class is an encapsulation of data and functions that operate on that data. Since we haven't covered how to create a class here we are going to simulate it. How do we do that? Well hopefully it will be simple. First off we need to determine what the data section is. In this case it is going to be the array called ToDoList that holds MyToDo structs. Because the functions you write need to operate on the data in some way you are going to have to put this array in global scope. This way all of the functions have direct access to the array without it having to be passed around. One thing of note and that is if we think about this from main's perspective main should not know how the data is stored or what it is stored in. All main should know is that if you use the addToListfunction you can add a new MyToDoitem to the todo list. This is what we call a public interface to private data. Since we are putting the array in global scope in ToDo.cpp we pseudo encapsulate it. This means that only ToDoList functions have access to the array and variables in global scope. Of course since it is in global scope there is a way around this but again, we are simulating.

Required functions

Funciton Arguments Description
addToList A MyToDoStruct Adds a single MyToDoStruct to the ToDoList. The struct should contain information about a todo item
addToList Description (string), date (string), priority (int) Overloaded function that adds a single MyToDo Struct to the ToDoList. In this case you are passing individual items that need to go into a struct
getNextItem A MyToDostruct (by reference) Gets the next MyToDo struct from the ToDoList. When the last item is returned the next call to getNextItem should return the first item in the list
getNextItem Description (string), date (string), priority (int) All variables should be passed by reference, This function works like the overloaded version except that it returns the information from the struct as individual values not structs
getByPriority An array of MyToDostructs, priority (as int) This function searches theToDoList array looking for items that have a matching priority. A list of all of the items with matching priorities will be returned to main
printToDo None Simply prints out each item in the todo array list one time.

Ok, so you should have three files

main.cpp - holds you main function

ToDo.cpp - holds the ToDo list functions that are required for the assignment

ToDo.h - which holds the definitions for ToDo list

Here is how things should flow for the addToList function:

In main create an instance of the MyToDo struct

fill the struct with information about an item to do. Get it from the keyboard if you want.

Pass the struct to addToList which attempts to add the MyToDo to the next slot in the array.

If the ToDoList is full and an item cannot be added then addToList returns false

If the item was successfully added to the array addToList returns true

Here is how things should flow for the getNextItem function:

In main create a MyToDo struct

call getNextItem function passing the created struct by reference

If the ToDoList is empty getNextItem simply returns false

If the ToDoList is not empty the next itme in the ToDo list is copied to the struct passed by reference and true is returned

*If the last item in the todo list is returned back, the next call to getNextItem will get the first item in the todo list again.

*This is circular so if have 5 items in the ToDo list and you call getNextItem in a loop 25 times from main all five todo items will be returned five times.

Here is how the getByPriortiy functions should flow:

In main create an array that will hold MyToDo Items

pass the array along with a priority to search for to the getByPriority function.

the getByPriority function will search the array looking to match the priority

If a match is found the found the struct is copied to the array that 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 print a list of items with the matching priority.

Conceptually what you are creating is a circular queue that holds structs. Because you need to know where the next available spot in the array is you will need an index. This should be in the global section of ToDo.cpp. You are actually probably going to need two indexes, one to keep track of what is being added, and one that keeps track of what is being removed.

What not to do

cin in any funciton other than main

*cout in any funciton other than main and the printToDo function

passing the ToDoList array to any function.

SECOND PART

For this I want you to take lab 19 and create a class out of it.

Your class should be called ToDoList. The definition for the ToDoList should be in the header file. The variables that make up the data section should be put in the private area of the class. The prototypes for the interface functions should be in the public area of the class.

Data Section

You can easily identify the variables that make up the data section from the fact that all of the functions use these variables. You should remember from the lecture material on classes that the data section should be the private section of the class. You should also note that if a variable should not have direct access to it then it should be in the private section. What I mean here is that if a person can directly access a variable from a function outside of the class and if modifying this variable can cause unknown problems to the operation of your class then it should be in the private section of the class.

Prototype Functions

All of the function prototypes should also go in the class. If a function is an interface into the class then it should go in the public section. For this assignment all functions are interfaces so all prototypes should go in the public section of the class.

In the previous step you prototyped all of the functions and put them in the public section of the class definition. The bodies for these functions should go in ToDoList.cpp. Don't forget to use the scope resolution operator to relate the function bodies to the prototypes in the class definition.

Constructors

You should have a default and overloaded constructors. The overloaded constructor should take 2-strings and an int which represent the descrition, dueDate, and priority.

Description MyToDo StructDueDate Priority Descriptiorn DueDate Description DueDate Priority Description DueDate Priority Description DueDate Priornty Priority Array of MyToDo Structs

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions