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
|
// implementation file follows
//implementation file
#include "functions.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int TaskList::getChoice()
{
return choice;
}
void TaskList::setChoice(int choices)
{
choice = choices;
}
//function to show choices
void TaskList::showChoices(int choice)
{
TaskList Task;
cout << "Welcome to your task organizer!\n";
cout << "*****************************************************************************\n\n";
cout << " 1 Enter your task or assignment.\n";
cout << " 2 Display all of the tasks that are in the file.\n";
cout << " 3 Find a task by Course.\n";
cout << " 4 Quit\n\n";
cout << "Please Enter a Number(1,2,3,4): ";
do
{
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');
//switch that controls which choice
switch(choice)
{
case 1:
char* courseName[25];
char* courseDescription[200];
char* dueDate[10];
Task.writeTasksToFile(courseName[25],courseDescription[200],dueDate[10]);
break;
case 2:
Task.readTasksFromFile();
cout << "\n\n";
break;
case 3:
Task.choiceThree();
break;
case 4:
cout << "Goodbye :)";
break;
}
}
while(choice !=4);
}
//-------------------------------------------------------------------------------------------------------
void TaskList::readTasksFromFile()
{
string getData;
ifstream openFile;
openFile.open("tasks.txt");
//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::writeTasksToFile(char courseName[25], char courseDescription[200], char dueDate[10])
{
char correctInfo;
int n = 0, y = 1;
ofstream outData;
//gather information
cout << "*****************************************************************************\n";
cout << "\n\nPlease enter the name of your course: ";
cin.getline(courseName, 25, '\n');
cout << "Please enter the description of your assignment: ";
cin.getline(courseDescription, 200, '\n');
cout << "Please enter the Due Date(9/26/2012): ";
cin.getline(dueDate, 10, '\n');
cout << "\n" << courseName << "\n"
<< courseDescription << "\n"
<< dueDate << "\n";
cout << "\nWould you like to store this information(y/n)? ";
cin >> correctInfo;
if(correctInfo = y)
{
//open tasks.txt
outData.open("tasks.txt", ios::app);
//print data to file tasks.txt
outData << courseName << "\n" << courseDescription;
outData << "\n" << dueDate << "\n\n";
outData.close();
cout << "\n";
}
}
//-------------------------------------------------------------------------------------------------------
void TaskList::choiceThree()
{
string searchStr;
string 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);
}
}
cout << "\n";
}
|