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
|
#include <iostream>
using namespace std;
#include <fstream>
#include "myutil.h"
#include "tasklist.h"
void displayMenu();
char readInOption();
void performOption(char option, TaskList& list);
void readInTask(Task& aTask);
void readInCourseName(char courseName[], const char prompt[]);
void readInTaskName(char taskName[], const char prompt[]);
void readInDueDate(char dueDate[], const char prompt[]);
int main()
{
char option;
char fileName[] = "tasks.txt";
TaskList list(fileName);
cout << "Welcome to the assignment database.\n" << endl;
displayMenu();
option = readInOption();
while(option != 'q')
{
performOption(option, list);
displayMenu();
option = readInOption();
}
return 0;
}
void performOption(char option, TaskList& list)
{
Task task;
switch (option)
{
case 'a' :
readInTask(task);
list.addTask(task);
break;
case 'd':
list.displayAll();
break;
case 'f': cout << "search is invoked" << endl;
break;
default:
cout << "Invalid entry. Please enter a, d, f, or q." << endl;
break;
}
}
void displayMenu()
{
cout << "a. Add a task.\n"
<< "d. Display all tasks.\n"
<< "f. Find a task by course.\n"
<< "q. Quit.\n";
}
char readInOption()
{
char option;
cout << "Please enter an option (a, d, f, q): ";
cin >> option;
cin.ignore(100, '\n');
return tolower(option);
}
void readInTask(Task& aTask)
{
char courseName[MAX_CHAR];
char taskName[MAX_CHAR];
char dueDate[MAX_CHAR];
readInCourseName(courseName, "Please enter the course name: ");
readInTaskName(taskName, "Please enter the task name: ");
readInDueDate(dueDate, "Please enter the due date: ");
aTask.setCourseName(courseName);
aTask.setTaskName(taskName);
aTask.setDueDate(dueDate);
}
void readInCourseName(char courseName[], const char prompt[])
{
getString(prompt, courseName, MAX_CHAR);
}
void readInTaskName(char taskName[], const char prompt[])
{
getString(prompt, taskName, MAX_CHAR);
}
void readInDueDate(char dueDate[], const char prompt[])
{
getString(prompt, dueDate, MAX_CHAR);
}
|