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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
|
//this is the implementation file for labThree
#include "tasks.h"
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
//creating the user interface
void TaskList::userInterface()
{
//prints user interface to the screen using cout
cout << "Welcome to your task organizer!\n\n"
<< "*******************************************************************************\n\n\n"
<< "\t\t1. Enter your task or assignment.\n"
<< "\t\t2. Display all of the tasks that are in the file.\n"
<< "\t\t3. Find a task by Course.\n"
<< "\t\t4. Quit\n\n\n"
<< "*******************************************************************************\n\n\n";
}
//-----------------------------------------------------------------------------------------------------------
void TaskList::enterTasks()
{
Task task;
char correctInfo;
int n = 0, y = 1;
//gather information
task.getTaskName();
task.getDescription();
task.getDueDate();
cout << "\nWould you like to store this information(y/n)? ";
cin >> correctInfo;
cout << "\n\n";
if(correctInfo = y)
{
cout << "\n\n";
task.setTaskName();
task.setDescription();
task.setDueDate();
makeChoice();
cout << "\n";
}
else
{
makeChoice();
}
}
//-----------------------------------------------------------------------------------------------------------
void TaskList::displayAllTasks()
{
ifstream openFile;
string getData;
//open tasks.txt
openFile.open("tasks.txt");
if(openFile.is_open())
{
//print everything to end of file
while(!openFile.eof())
{
getline(openFile, getData);
cout << getData << endl;
}
//close tasks.txt
openFile.close();
}
}
//-----------------------------------------------------------------------------------------------------------
void TaskList::searchForTaskName()
{
string searchStr, line;
int lineNumber = 0;
cout << "\nPlease enter the name of the task you want to find: ";
cin >> searchStr;
cout << "\n";
ifstream file("tasks.txt");
while(getline(file, line))
{
if(line.find(searchStr) != string::npos)
for(lineNumber = 0; lineNumber <= 2; lineNumber++)
{
cout << line << '\n';
if(lineNumber!=3)
getline(file, line);
}
makeChoice();
}
cout << "\n";
}
//-----------------------------------------------------------------------------------------------------------
void TaskList::makeChoice()
{
int choice;
TaskList list;
do
{
list.userInterface();
cout << "Please enter a number between 1 and 4: ";
cin >> choice;
//error control
while(!cin)
{
cin.clear();
cin.ignore(100, '\n');
cout << endl << "You've entered an illegal integer, please try again!\n\n";
cout << "Please Enter a Number(1,2,3,4): ";
cin >> choice;
}
cin.ignore(100, '\n');
while(choice != 4)
{
switch(choice)
{
case 1:
list.enterTasks();
break;
case 2:
list.displayAllTasks();
break;
case 3:
list.searchForTaskName();
break;
default:
break;
} //end switch
}
}
while(choice != 4);
}
//-----------------------------------------------------------------------------------------------------------
void Task::getTaskName()//gets the name of the task from the user
{
cout << "*****************************************************************************\n";
cout << "\n\nPlease enter the name of your course: ";
cin.getline(taskName, 100, '\n');
}
//-----------------------------------------------------------------------------------------------------------
void Task::getDescription() //gets the description
{
cout << "Please enter the description of your assignment: ";
cin.getline(taskDescription, 5000, '\n');
}
//-----------------------------------------------------------------------------------------------------------
void Task::getDueDate() //gets the due date
{
cout << "Please enter the Due Date(9/26/2012): ";
cin.getline(taskDueDate, 10, '\n');
cout << "\n";
cout << "\n" << taskName << "\n"
<< taskDescription << "\n"
<< taskDueDate << "\n\n";
}
//-----------------------------------------------------------------------------------------------------------
void Task::setTaskName() //outputs the task name to "tasks.txt"
{
ofstream outData;
//open tasks.txt
outData.open("tasks.txt", ios::app);
//print data to file tasks.txt
outData << taskName << "\n";
outData.close();
}
//-----------------------------------------------------------------------------------------------------------
void Task::setDescription() //outputs the description to "task.txt"
{
ofstream outData;
outData.open("tasks.txt", ios::app);
outData << taskDescription << "\n";
outData.close();
}
//-----------------------------------------------------------------------------------------------------------
void Task::setDueDate() //outputs the due date to "task.txt"
{
ofstream outData;
outData.open("tasks.txt", ios::app);
outData << taskDueDate << "\n\n";
outData.close();
}
|