I'm working on a lab for my C++ class that is the first to use classes and objects. It requires a search function that lists tasks found for a target course. I can't get the search function to work. Here is the relevant code:
from main source code:
void processCommand(char command, TaskList& list)
{
Task entry;
char task[MAX_CHAR];
char course[MAX_CHAR];
char date[MAX_CHAR];
switch (command)..
case 's': readInTask(course);
if(list.searchEntry(course, entry))
{
entry.getTask(task); // gets matching task
entry.getDate(date); // gets matching date
cout << endl << " The tasks for course " << course << " are: \n" << endl;
//column titles
cout << setw(TASK_COL_WIDTH) << " Task"
<< setw(DATE_COL_WIDTH) << " Date";
cout << endl ;
cout << setw(TASK_COL_WIDTH) << task
<< setw(DATE_COL_WIDTH) << date
<< endl;
}
.. [B]from TaskList::searchEntry function[/B]
bool TaskList::searchEntry(const char course[], Task& match) const
{
int index;
char currentTask[MAX_CHAR];
char currentCourse[MAX_CHAR];
char currentDate[MAX_CHAR];
for(index=0; index < size; index++)
{
list[index].getTask(currentTask);
list[index].getCourse(currentCourse);
list[index].getDate(currentDate);
if(strcmp(course, currentCourse) == 0)
{
match.setTask(currentTask);
match.setCourse(currentCourse);
match.setDate(currentDate);
}
}
if (index == size)
return false;
else
return true;
}
The search outputs one search result when there are more than one. I can't tell if the problem is in the output (in the switch statement) or in the actual search function.
Thanks for your help.
WFWS