Skip to content

Instantly share code, notes, and snippets.

@allisons
Created October 8, 2009 17:38
Show Gist options
  • Select an option

  • Save allisons/205222 to your computer and use it in GitHub Desktop.

Select an option

Save allisons/205222 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <iomanip>
#include <cstring>
#include <fstream>
#include <string.h>
#define OUTPUT_FILE "/Users/Kav/text.txt"
using namespace std;
const int ARRAY_SIZE = 1000;
int showAllTasks (int);
int showTasksByDueDate (int, char*);
int showTasksByCourse (int, char*);
int main ()
{
char* course[ARRAY_SIZE];
char* task[ARRAY_SIZE];
char* duedate[ARRAY_SIZE];
ofstream outFile;
outFile.open(OUTPUT_FILE);
cout << "Thanks for using the Task List Manager" << endl;
cout << "This program will help keep track of your To-Do list." << endl;
cout << "Please hit enter to continue.";
if (!outFile)
{
cout << "File does not open. Please check the file and try running the Task List Manager again.";
return -1;
}
char more;
int i = 1;
//while loop repeats until user changes more value to N or n
while (more != 'Y' || more != 'y')
{
char correct;
cin.ignore( 1, '\n');
cout << "Please enter the task you need to complete ";
cin.getline(task[i], 20);
cout << "Please enter the course you need to complete this task ";
cin.getline(course[i], 20);
cout << "Please enter the task's due date ";
cin.getline(duedate[i], 20);
cout << "Did you enter " << task[i] << " for " << course[i] << " due " << duedate[i] << "? Y/N ";
cin >> correct;
//if command excutes if user confirms correct information
if (correct == 'Y' || correct == 'y')
{
outFile << task[i] << ";" << course[i] << ";" << duedate[i] << ";" << endl;
i++;
}
//else case executes if the user fails to confirm, fails to advance the counter and thus rewrites over same entry
else
{
cout << "Previous entry not saved, try your entry again." << endl;
}
cout << "Do you wish to add more tasks? Y/N ";
cin >> more;
if (more == 'N' || more == 'n')
break;
}
outFile.close();
char options;
char* choosecourse;
char* choosedate;
while (options != 'Q' || options != 'q')
{
cout << "These are the following options for the Task List Manager program:" << endl;
cout << "(L)ist all tasks, Find Task by (C)ourse, Find Task by (D)uedate, (Q)uit,";
cin >> options;
switch (options) {
case 'L':
case 'l': showAllTasks(i);
break;
case 'C':
case 'c': cout << "Please enter the course:";
cin.getline (choosecourse, 256);
showTasksByCourse(i, choosecourse);
break;
case 'D':
case 'd': cout << "Please enter the duedate:";
cin.getline (choosedate, 256);
showTasksByDueDate(i, choosedate);
break;
}
}
return 0;
}
int showAllTasks (int count)
{
ifstream inFile;
string course[256];
string task[256];
string duedate[256];
inFile.open(OUTPUT_FILE);
if (! inFile.is_open())
{
cout << "Oops, something went wrong. Please try again.";
return 0;
}
int t;
cout << "Task" << setw(4) << "Course" << setw(5) << "Duedate" << setw(4) << endl;
for (t = 0; t <= count; t++)
{
getline (inFile, task[t], ';');
cout << task[t] << setw(4);
getline (inFile, course[t], ';');
cout << course[t] << setw(5);
getline (inFile, duedate[t], ';');
cout << duedate[t] << endl;
}
inFile.close();
return 0;
}
int showTasksByDueDate (int count, char selectedDueDate[30])
{
ifstream inFile;
int taskcount = 0;
int a;
string course[256];
string task[256];
string duedate[256];
cout << "Starting showTasksByDueDate";
inFile.open("task.txt");
if (! inFile.is_open())
{
cout << "Oops, something went wrong. Please try again.";
return 0;
}
int t;
for (t = 0; t <= count; t++)
{
getline (inFile, task[t], ';');
cout << task[t];
getline (inFile, course[t], ';');
cout << course[t];
getline (inFile, duedate[t], ';');
cout << duedate[t];
}
for (a = 0; a <= count; a++)
{
if (duedate[a].find(selectedDueDate[30]) != string::npos)
{cout << task[a] << "( " << course[a] << ")" << endl;
taskcount++;
}
}
int i;
for (i=0; i <= count; i++)
{
cout << task[i] << ";" << course[i] << ";" << duedate[i] << ";" << endl;
}
cout << taskcount << " tasks due on " << selectedDueDate[30] << endl;
inFile.close();
return 0;
}
//function inputs task list size, selected course, and task list and outputs tasks due for specific course.
int showTasksByCourse (int count, char selectedCourse[30])
{
int taskcount = 0;
string course[256];
string task[256];
string duedate[256];
ifstream inFile;
int q;
inFile.open("tasklistmanager.txt");
for (q = 0; q <= count; q++)
{
getline (inFile, task[q], ';');
getline (inFile, course[q], ';');
getline (inFile, duedate[q], ';');
}
int b;
for (b = 0; b <= count; b++)
{
if (course[b].find(selectedCourse[30]) != string::npos)
{cout << task[b] << "( " << duedate[b] << ")" << endl;
taskcount++;
}
}
cout << taskcount << " tasks due for " << selectedCourse[30] << endl;
inFile.close();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment