1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
//memory leak detection tool headers
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#include <iostream>
#include <cctype>
#include "TasksList.h"
#include "EntryList.h"
#include "InputTools.h"
using namespace std;
void displayMenu();
char readInCommand();
void processCommand(char command, Tasks& list);
void readInEntry(TaskList& anEntry);
void readInName(char name[]);
int main ()
{
char command;
char fileName[] = "tasks.txt";
Tasks list(1, fileName);
displayMenu();
command = readInCommand();
while (command != 'q')
{
processCommand(command, list);
displayMenu();
command = readInCommand();
}
list.saveTasksBook(fileName);
return 0;
}
void displayMenu()
{
cout << endl << "Hello User! Welcome to the TaskManager" << endl << endl;
cout << "\ta: To add an entry" << endl
<< "\tl: To list all the entries" << endl
<< "\ts: To search class by name" << endl
<< "\tq: To exit this program" << endl << endl;
}
char readInCommand()
{
char cmd;
cmd = readChar("Please enter the command (a,l,s or q): ");
return tolower(cmd);
}
void processCommand(char command, Tasks& list)
{
TaskList entry;
char name[MAX_CHAR];
char description[MAX_CHAR];
char duedate[MAX_CHAR];
switch (command)
{
case 'a': readInEntry(entry);
list.addTasks(entry);
break;
case 'l': list.printAll();
break;
case 's': readInName(name);
if(list.searchTasks(name, entry))
{
entry.getDescription(description);
entry.getDuedate(duedate);
cout << endl << "The class for " << name << ": " << description << ": " << duedate << endl;
}
else
cout << endl << "The class for " << name << " doesn't exist." << endl;
break;
default: cout << endl << "Illegal Command!" << endl;
break;
}
}
void readInEntry(TaskList& anEntry)
{
char name[MAX_CHAR];
char description[MAX_CHAR];
char duedate[MAX_CHAR];
readString("Please enter the name: ", name, MAX_CHAR);
readString("Please enter the description: ", description, MAX_CHAR);
readString("Please enter the duedate: ", duedate, MAX_CHAR);
anEntry.setName(name);
anEntry.setDescription(description);
anEntry.setDuedate(duedate);
}
void readInName(char name[])
{
readString("Please enter the name you want to search: ", name, MAX_CHAR);
}
|