Question

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:

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

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:

ToDo2.png

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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1


#ifndef OURTODO_H
#define OURTODO_H
#include<string>
using namespace std;


struct ToDoStruct
{
  
string todo_desc;
int todo_prior;
string todo_duedate;
};


class ToDoClass
{
  
private:

  
ToDoStruct *todo_list;

  
int noofelements;
int nextelement;
int capacityoflist;

  
public:

  
ToDoClass();
ToDoClass(string des,string due,int pri);

  
bool addToList(struct ToDoStruct todo);
bool addToList(string des, string due, int pri);
bool getNextItem(struct ToDoStruct &todo);
bool getNextItem(string &des, string &due, int &pri);
bool getByPriority(struct ToDoStruct *todoList, int pri);
void printToDo();
};
#endif


#include<iostream>
#include<string>
#include<iomanip>
#include"ToDo.h"
using namespace std;


ToDoClass::ToDoClass()
{
  
capacityoflist=10;
todo_list=new ToDoStruct[capacityoflist];
noofelements=0;
nextelement=0;
}


bool ToDoClass::addToList(struct ToDoStruct todo)
{
  
if(noofelements==capacityoflist)

  
return false;

  
else

todo_list[noofelements++]= todo;


return true;
}

//Method addToList()
bool ToDoClass::addToList(string des, string due, int pri)
{
//Check condition
if(noofelements==capacityoflist)

//Return
return false;

//Update
todo_list[noofelements].todo_desc=des;
todo_list[noofelements].todo_duedate=due;
todo_list[noofelements].todo_prior=pri;

//Increment
noofelements++;

//Return
return true;
}

//Method getNextItem()
bool ToDoClass::getNextItem(struct ToDoStruct &todo)
{
//Check condition
if(noofelements==0)

//Return
return false;

//Check condition
if(nextelement==capacityoflist)

//Update
nextelement=0;
todo=todo_list[nextelement];

//Increment
nextelement++;

//Return
return true;
}

//Method getNextItem()
bool ToDoClass::getNextItem(string &des, string &due, int &pri)
{
//Check condition
if(noofelements==0)

//Return
return false;

//Check condition
if(nextelement==capacityoflist)

//Update
nextelement=0;
des=todo_list[nextelement].todo_desc;
due=todo_list[nextelement].todo_duedate;
pri=todo_list[nextelement].todo_prior;

//Increment
nextelement++;

//Return
return true;
}

//Method getByPriority()
bool ToDoClass::getByPriority(struct ToDoStruct *todoList, int pri)
{
//Declare and initialize
int index = 0;
bool match = false;

//Loop
for (int idx = 0; idx < noofelements; idx++)
{
//Check condition
if (todo_list[idx].todo_prior == pri)
{
//Update
todoList[index] = todo_list[idx];

//Increment
index++;

//Update
match = true;
}
}

//Check condition
if (match == false)
{
//Return
return false;
}

//Return
return true;
}

//Method printToDo()
void ToDoClass::printToDo()
{
//Display
cout << "Description" << setw(20) << "Priority " << setw(14) << "DueDate" << endl;

//Loop
for (int idx = 0; idx < noofelements; idx++)
{
//Display
cout << left << setw(20) << todo_list[idx].todo_desc << right << setw(7)
<< todo_list[idx].todo_prior << right << setw(16)
<< todo_list[idx].todo_duedate << endl;
}
}


#include<iostream>
#include<iomanip>
#include<string>
#include"ToDo.h"
using namespace std;


int main()
{
  
struct ToDoStruct *tmptodo, getitem, getdata;

  
ToDoClass tdc;

  
int number, ssize, todopri1;
string tododes1, tododue1;

  
cout << "Enter the number of items you want to insert: ";

  
cin >> number;


cout << "\nEnter the description, priority and due date" << endl;


for (int idx = 0; idx < number; idx++)
{
  
cout << "Enter description: ";

  
cin >> tododes1;


cout << "Enter priority: ";

  
cin >> todopri1;

  
cout << "Enter due date (mm/dd) format: ";

cin >> tododue1;

  
tdc.addToList(tododes1, tododue1, todopri1);

  
cout << endl;
}

  
struct ToDoStruct ournewtodolist;

  
ournewtodolist.todo_desc = "Test";
ournewtodolist.todo_duedate = "08/14";
ournewtodolist.todo_prior = 3;
tdc.addToList(ournewtodolist);

  
number++;


tdc.getNextItem(getdata);

  
cout << "First TODO in list: " << endl;
cout << "Description: " << getdata.todo_desc << endl;
cout << "Priority: " << getdata.todo_prior << endl;
cout << "DueDate: " << getdata.todo_duedate << endl;

  
cout << endl << endl;

  
cout << "Next TODO in list: " << endl;

  
for (int idx = 1; idx < number ; idx++)
{
  
tdc.getNextItem(getdata);


cout << "TODO " << idx << ":" << endl;
cout << "Description: " << getdata.todo_desc << endl;
cout << "Priority: " << getdata.todo_prior << endl;
cout << "DueDate: " << getdata.todo_duedate << endl << endl;
}

  
cout << endl;

  
tmptodo = new struct ToDoStruct[number];


if (tdc.getByPriority(tmptodo, 3))
{

ssize= sizeof(*tmptodo) / sizeof(tmptodo[0]);

  
cout << "TODO with priority 3: " << endl;

  
for (int idx = 0; idx <ssize; idx++)
{
  
cout << "TODO " << idx << ":" << endl;
cout << "Description: " << tmptodo[idx].todo_desc << endl;
cout << "Priority: " << tmptodo[idx].todo_prior << endl;
cout << "DueDate: " << tmptodo[idx].todo_duedate << endl << endl;
}
}

  
else
{
  
cout << "No TODO with priority 3!" << endl;
}


cout << endl;


cout << "Total TODOs in the list:" << endl;

  
tdc.printToDo();

  
cin.get();cin.get();

  
return 0;
}

Add a comment
Know the answer?
Add Answer to:
C++ LAB 19 Construct functionality to create a simple ToDolist. Conceptually the ToDo list uses a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a simple todo list application. This will require use of classes, objects, and possibly structs....

    Write a simple todo list application. This will require use of classes, objects, and possibly structs. Here are the requirements: 1. Menu-driven - upon running the program, the user should be prompted to press one of the following: 1. View all Todos in list 2. Remove a todo item from the list * if there are not any todos, the user should be prompted and sent back to the menu * choose a todo from list based on title to...

  • Write a C++ program that demonstrates use of programmer-defined data structures (structs), an array of structs, passing...

    Write a C++ program that demonstrates use of programmer-defined data structures (structs), an array of structs, passing an array of structs to a function, and returning a struct as the value of a function. A function in the program should read several rows of data from a text file. (The data file should accompany this assignment.) Each row of the file contains a month name, a high temperature, and a low temperature. The main program should call another function which...

  • JAVA PROGRAMMING PLEASE This lab has three parts: Create an ArrayList class. Create a LinkedList class....

    JAVA PROGRAMMING PLEASE This lab has three parts: Create an ArrayList class. Create a LinkedList class. Print out the results after testing each of the methods in both of the classes and solving a simple problem with them. Task 1 – ArrayList Class Create an ArrayList class. This is a class that uses an internal array, but manipulates the array so that the array can be dynamically changed. This class should contain a default and overloaded constructor, where the default...

  • 8.9 Coding lab #5: create a dynamic array ADT and a singly linked list ADT. Honor Code...

    8.9 Coding lab #5: create a dynamic array ADT and a singly linked list ADT. Honor Code Your answers to this homework must be your own work.You are not allowed to share your solutions.You may not engage in any other activities that will dishonestly improve your results or dishonestly improve or damage the results of others. Plagiarism Plagiarism is when you copy words, ideas, or any other materials from another source without giving credit. Plagiarism is unacceptable in any academic environment....

  • C++ Create an array-based implementation of a stack. Each element of the stack should store a...

    C++ Create an array-based implementation of a stack. Each element of the stack should store a string. The stack class should include 3 private member variables (maximum stack size, top of the stack index, and a pointer to the array that holds the stack elements). Public member methods should include a constructor (with an argument of stack maximum size that is used to create a dynamic array), a destructor (that deletes the dynamic array), a push method (argument is a...

  • I need c++ code Given the complete main() function, partial playlist class header playlist.h, and playlist.cpp,...

    I need c++ code Given the complete main() function, partial playlist class header playlist.h, and playlist.cpp, you will complete the class declaration and class implementation. The following member functions are required: constructor copy constructor destructor addSong(song tune) adds a single node to the front of the linked list no return value displayList() displays the linked list as formatted in the example below no return value overloaded assignment operator A description of all of these functions is available in the textbook's...

  • Write a program that demonstrates use of programmer - defined data structures. Please provide code! Thank...

    Write a program that demonstrates use of programmer - defined data structures. Please provide code! Thank you. Here are the temps given: January 47 36 February 51 37 March 57 39 April 62 43 May 69 48 June 73 52 July 81 56 August 83 57 September 81 52 October 64 46 November 52 41 December 45 35 Janual line Iranin Note: This program is similar to another recently assigned program, except that it uses struct and an array of...

  • lab 11 Do not change main.cpp, i need c++ code for queue.h and queue.cpp Given the...

    lab 11 Do not change main.cpp, i need c++ code for queue.h and queue.cpp Given the complete main() function, partial queue class header queue.h, and queue.cpp, you will complete the class declaration and class implementation. The following member functions are required: constructor enqueue() dequeue() You may elect to create the following helper functions: isFull() isEmpty() A description of these ADT operations are available in this Zybook and in the textbook's chapter 17. Example: If the input is: 3 Led Zepplin...

  • c++ please Given the following skeleton of an unsorted list class that uses an unsorted linked...

    c++ please Given the following skeleton of an unsorted list class that uses an unsorted linked list: template<class ItemType> struct NodeType {                 ItemType item;                 NodeType* next; }; template<class ItemType> class UList { public:                 UList(); // default constrctor                 UList(const UList &x); // we implement copy constructor with deep copy                 UList& operator = (UList &x); // equal sign operator with deep copy                 bool IsThere(ItemType item) const; // return true of false to indicate if item is...

  • A grocery list is provided below: Create three different classes named Milk. Bread, and Eggs, where...

    A grocery list is provided below: Create three different classes named Milk. Bread, and Eggs, where each has the following members: private data member "unit_price private data member "quantity". Default and overloaded constructors Provide properties for the private data members public total_price method which returns the total price (e.g., unit_price times quantity) A ToString() method that returns the info of the object Create a class named Grocery, which has the following members my_milk of type Milk my_bread of type Bread...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT