In: Computer Science
For this assignment I need to use information from a previous assignment which I will paste here:
#ifndef TODO
#define TODO
#include <string>
using std::string;
const int MAXLIST = 10;
struct myToDo
{
string description;
string dueDate;
int priority;
};
bool addToList(const MyToDo &td);
bool addToList(string description, string date, int
priority);
bool getNextItem(MyToDo &td);
bool getNextItem(string &description, string &date, int
&priority);
bool getByPriority(MyToDo list[], int priority int
&count);
void printToDo();
#endif
#include <iostream>
#include "ToDo.h"
using namespace std;
myToDo ToDoList[MAXLIST];
int head = 0, tail = -1;
bool addToList(const myToDo &td)
{
if(head < MAXLIST)
{
if(tail ==
-1)
tail++;
ToDoList[head] =
td;
head++;
return true;
}
return false;
}
bool addTolist(string description, string date, int priority)
{
MyToDo td;
td.description = description;
td.dueDate = date;
td.priority = priority;
return addToList(td);
}
bool getNextItem(MyToDo &td)
{
if(tail >= 0)
{
if(tail >=
MAXLIST)
tail
= 0;
td =
ToDoList[tail];
tail++;
return true;
}
return false;
}
bool getNextItem(string &description, string &date,
int&priority)
{
myToDo tmp;
bool status = getNextItem(tmp);
if(status == true)
{
description =
tmp.description;
date =
tmp.dueDate;
priority =
tmp.priority;
}
return status;
}
bool getByPriority(MyToDo list[], int priority, int
&count)
{
if(tail < 0)
return
fals;
count = 0;
for(int i = 0; i
< head; i++)
{
if(ToDoList[i].priority
== priority)
{
list[count]
= ToDoList[i];
count++;
}
}
if(count > 0)
return
true;
return false;
}
void printToDo())
{
for(int i = 0; i < head; i++)
{
cout <<
"Description" << ToDoList[i].description << endl;
cout << "Due
Date" << ToDoList[i].dueDate << endl;
cout <<
"Priority" << ToDoList[i].priority << endl;
}
With this info I am asked:
Creating A Classes
This assignment is geared to check your understanding of Object Oriented Programming and class creationg. The class type is called a complex type because it is a type that you create from the primitive types of the language. Even though you create it it is still a full fledged type.
This activity is designed to support the following Learning Objective:
Instructions
In Assignment 19 you created a simple ToDo list that would hold structs that contained information about each item that would be in the list.. For this assignment I want you to take lab 19 an 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.
// ToDo.h
#ifndef TODO
#define TODO
#include <string>
using std::string;
const int MAXLIST = 10;
struct myToDo
{
string description;
string dueDate;
int priority;
};
#endif
//end of ToDo.h
// ToDoList.h
#ifndef TODOLIST
#define TODOLIST
#include <iostream>
#include "ToDo.h"
using namespace std;
class ToDoList
{
private:
myToDo toDoList[MAXLIST];
int head, tail;
public:
ToDoList();
ToDoList(string description, string date, int priority);
bool addToList(const myToDo &td);
bool addToList(string description, string date, int priority);
bool getNextItem(myToDo &td);
bool getNextItem(string &description, string &date, int &priority);
bool getByPriority(myToDo list[], int priority, int &count);
void printToDo();
};
#endif
//end of ToDoList.h
// ToDoList.cpp
#include "ToDoList.h"
ToDoList::ToDoList()
{
head = 0;
tail = -1;
}
ToDoList::ToDoList(string description, string date, int priority)
{
head = 0;
tail = -1;
myToDo td;
td.description = description;
td.dueDate = date;
td.priority = priority;
toDoList[head] = td;
addToList(td);
}
bool ToDoList:: addToList(const myToDo &td)
{
if(head < MAXLIST)
{
if(tail == -1)
tail++;
toDoList[head] = td;
head++;
return true;
}
return false;
}
bool ToDoList:: addToList(string description, string date, int priority)
{
myToDo td;
td.description = description;
td.dueDate = date;
td.priority = priority;
return addToList(td);
}
bool ToDoList:: getNextItem(myToDo &td)
{
if(tail >= 0)
{
if(tail >= MAXLIST)
tail = 0;
td = toDoList[tail];
tail++;
return true;
}
return false;
}
bool ToDoList:: getNextItem(string &description, string &date, int &priority)
{
myToDo tmp;
bool status = getNextItem(tmp);
if(status == true)
{
description = tmp.description;
date = tmp.dueDate;
priority = tmp.priority;
}
return status;
}
bool ToDoList:: getByPriority(myToDo list[], int priority, int &count)
{
if(tail < 0)
return false;
count = 0;
for(int i = 0; i < head; i++)
{
if(toDoList[i].priority == priority)
{
list[count] = toDoList[i];
count++;
}
}
if(count > 0)
return true;
return false;
}
void ToDoList:: printToDo()
{
for(int i = 0; i < head; i++)
{
cout << "Description" << toDoList[i].description << endl;
cout << "Due Date" << toDoList[i].dueDate << endl;
cout << "Priority" << toDoList[i].priority << endl;
}
}
//end of ToDoList.cpp