Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. How can I compile this program with only one header file and without a class? This is assignment 20, and we we asked to

1. How can I compile this program with only one header file and without a class? This is assignment 20, and we we asked to create a class from assignment 19 which is what i need. So i need to be able to compile the program without a class present.

2. Also getting this message in the compiler:

Warning C6385 Reading invalid data from 'todoList': the readable size is '(unsigned int)*60+4' bytes, but '120' bytes may be read. TODOLIST.CPP 84

Main.cpp

#include #include #include #include "ToDoList.h" using namespace std; int main() { int choice = 0; char nextmove = 'y'; MyToDo* tempTodo = NULL, getToDoItem, getToDoData; ToDoList td; int nn = 1; string todoDesc1; string date; int todoPriority1; int ss; while (nextmove == 'y') { cout << " What would you like to do?" << endl; cout << "1. Add task" << endl; cout << "2. Display next task" << endl; cout << "3. Search by priority" << endl; cout << "4. Print list" << endl; cout << "5. Exit" << endl; cin >> choice; if (choice == 1) { cout << " Enter the # of task you want to add." << endl; cin >> nn; for (int aa = 0; aa < nn; aa++) { cout << " Enter Description: "; cin >> todoDesc1; cout << "Enter Priority: "; cin >> todoPriority1; cout << "Enter Due Date(mm/dd): "; cin >> date; td.addToList(todoDesc1, date, todoPriority1); } } else if (choice == 2) { if (!td.getNextItem(getToDoData)) continue; cout << " The first task on the list is:" << endl; cout << "Description: " << getToDoData.todoDesc << endl; cout << "Priority: " << getToDoData.todoPriority << endl; cout << "Due Date: " << getToDoData.dueDate << endl; cout << endl; cout << "The next tasks after that are: " << endl; for (int aa = 1; aa < nn; aa++) { td.getNextItem(getToDoData); cout << "Description: " << getToDoData.todoDesc << endl; cout << "Priority: " << getToDoData.todoPriority << endl; cout << "Due Date: " << getToDoData.dueDate << endl << endl; } } else if (choice == 3) { cout << " Priority # to search for:" << endl; int fPrior; cin >> fPrior; if (td.getByPriority(tempTodo, fPrior, ss)) { for (int kk = 0; kk < ss; kk++) { cout << " Description: " << tempTodo[kk].todoDesc << endl; cout << "Priority: " << tempTodo[kk].todoPriority << endl; cout << "Due Date: " << tempTodo[kk].dueDate << endl; } } else { cout << " No priority " << fPrior << " tasks." << endl; } } else if (choice == 4) { cout << endl; td.printToDo(); cout << endl; } else if (choice == 5) { nextmove = 'n'; } else { cout << "That was an incorrect choice!" << endl; } } cout << " Goodbye " << endl; return 0; } 

ToDoList.cpp

#include #include #include #include "ToDoList.h" using namespace std; ToDoList::ToDoList() { listcapacity = 5; list = new MyToDo[listcapacity]; nelem = 0; nextElement = 0; } bool ToDoList::addToList(MyToDo todo) { if (nelem == listcapacity) return false; else list[nelem++] = todo; return true; } bool ToDoList::addToList(string desc, string ddate, int p) { if (nelem == listcapacity) return false; list[nelem].todoDesc = desc; list[nelem].dueDate = ddate; list[nelem].todoPriority = p; nelem++; return true; } bool ToDoList::getNextItem(MyToDo& todo) { if (nelem == 0) return false; if (nextElement == nelem) nextElement = 0; todo = list[nextElement]; nextElement++; return true; } bool ToDoList::getNextItem(string& Description, string& Date, int& priority) { if (nelem == 0) return false; if (nextElement == nelem) nextElement = 0; Description = list[nextElement].todoDesc; Date = list[nextElement].dueDate; priority = list[nextElement].todoPriority; nextElement++; return true; } bool ToDoList::getByPriority(MyToDo*& todoList, int priority, int& size) { int cc = 0; bool matched = false; for (int aa = 0; aa < nelem; aa++) { if (list[aa].todoPriority == priority) { cc++; matched = true; } } if (matched == false) { return false; } size = cc; todoList = new MyToDo[size]; cc = 0; for (int aa = 0; aa < nelem; aa++) { if (list[aa].todoPriority == priority) { todoList[cc] = list[aa]; cc++; } } return true; } void ToDoList::printToDo() { cout << "Description" << setw(20) << "Priority " << setw(15) << " Due_Date" << endl; for (int aa = 0; aa < nelem; aa++) { cout << left << setw(20) << list[aa].todoDesc << right << setw(7) << list[aa].todoPriority << right << setw(16) << list[aa].dueDate << endl; } } 

ToDoList.h

#ifndef TODOLIST_H #define TODOLIST_H #include "ToDo.h" class ToDoList { private: MyToDo* list; int nelem; int nextElement; int listcapacity; public: ToDoList(); bool addToList(MyToDo todo); bool addToList(string Description, string Date, int priority); bool getNextItem(MyToDo& todo); bool getNextItem(string& Description, string& Date, int& priority); bool getByPriority(MyToDo*& todoList, int priority, int& size); void printToDo(); }; #endif 

ToDo.h

#ifndef todo_h #define todo_h #include using namespace std; struct MyToDo { string todoDesc; int todoPriority; string dueDate; }; #endif 

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

Intelligent Information And Database Systems 12th Asian Conference ACIIDS 2020 Phuket Thailand March 23 26 2020 Proceedings

Authors: Pawel Sitek ,Marcin Pietranik ,Marek Krotkiewicz ,Chutimet Srinilta

1st Edition

9811533792, 978-9811533792

More Books

Students also viewed these Databases questions