-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
140 lines (128 loc) · 4.55 KB
/
main.cpp
File metadata and controls
140 lines (128 loc) · 4.55 KB
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
#include <iostream>
#include <string>
#include <fstream>
//#include <typeinfo>
#include "Assignment.h"
#include "Date.h"
#include "StringTokenizer.h""
#include "assignmentHandler.h"
#include "list.h"
using namespace std;
//will be adding more error detection/correction to the code - CN
bool validEntry(int entry);
void DisplayMenu();
int getResponse(istream& read);
//all of this was me just trying to correctly parse an example of a line of data and make assignments from it
int main()
{
AssignmentHandler assignment_handler;//this class will handle the assignments, main just passes it the data
string filename;
string textline="";
string due,description,assigned,status;//to use to pass into the constructor
int index=0;//to use for parsing the lines of the textfile
bool still_in_menu = true;
int menu_choice=0;
ifstream fin;
ofstream fout;
cout<<"Please enter text file name to populate lists from without the .txt extension: ";
cin>>filename;
filename += ".txt";
fin.open(filename);//need to add error handling around this
if(fin.fail())
cout<<"file failed"<<endl;
while(!fin.eof())
{
getline(fin,textline,'\n');
cout<<"\n"<<textline<<endl;//just wanted to confirm i was reading in ok
assignment_handler.Add_Assignment(textline);
}
//menu block
while (still_in_menu)
{
DisplayMenu();//function that just prints to screen, made to reduce clutter
cin>>menu_choice;//decided to ignore checking for valid response so i could test things-CN
//menu_choice = getResponse(cin);
//cout<<endl;
switch (menu_choice)//will probably put into seperate function to reduce clutter
{
case 1://display assignments
cout<<"\nDue Date,Description,Assign Date,Status\n";
assignment_handler.DisplayAssignments(cout);
break;
case 2://add an assignment
cout<<"\nPlease enter the assignments data in one line in the following manner;\nDue date,description,assigned dates,status\nwith the dates in the format MM/DD/YYYY\n:";
cin>>textline;
assignment_handler.Add_Assignment(textline);
break;
case 3://change due date
cout<<"Please enter the assign date of the assignment you wish to change using the format MM/DD/YYYY\n:";
cin>>assigned;
cout<<"Please enter the new due date of the assignment you are changing in the format MM/DD/YYYY\n:";
cin>>due;
assignment_handler.EditAssignmentDue(assigned,due);
break;
case 4://change description BE VERY CAREFUL!!! IT DOES NOT LIKE HAVING A STRING WITH SPACES PASSED IN!!!
cout<<"Please enter the assign date of the assignment you wish to change using the format MM/DD/YYYY\n:";
cin>>assigned;
cout<<"Please enter the new description of the assignment you are changing\n:";//avoid using spaces for the moment
cin>>description;//NO SPACES!!!!
assignment_handler.EditAssignmentDescrip(assigned,description);
break;
case 5://complete an assignment
cout<<"Please enter the assign date of the assignmeent you wish to complete using the format MM/DD/YYYY\n:";
cin>>assigned;
cout<<"Please enter the date the assignment was completed in the format MM/DD/YYYY\n:";
cin>>due;//using due again instead of making a new variable
assignment_handler.CompleteAssignment(assigned,due);
break;
case 6://count late assignments
cout<<to_string(assignment_handler.CountLate())<<" late assignments.\n";
break;
case 7://saves assignments to textfile
//i need to be very careful doing this, because i am writing to the same file i depend on reading from
//going to try a couple different things in a separate copy, will upload best option
break;
case 8://exists program
still_in_menu = false;
break;
}
}
fin.close();//always close your files
system("pause");
return 0;
}
//prints out the menu, made to reduce clutter
void DisplayMenu()
{
cout<<"Would you like to:"<<endl;
cout<<"1. Display the assignments"<<endl;
cout<<"2. Add an assignment"<<endl;
cout<<"3. Edit an assignment's due date"<<endl;
cout<<"4. Edit the description of an assignment"<<endl;
cout<<"5. Complete an assignment"<<endl;
cout<<"6. See the number of late assignments"<<endl;
cout<<"7. Save the assignments to a text file"<<endl;
cout<<"8. Exit"<<endl<<endl;
cout<<"Type a number (1-8) for the corresponding menu choice"<<endl<<":";
}
//was attempting to solve the menu problem
int getResponse(istream& read)
{
int choice;
cout<<"\nPlease enter a valid number (1-8)\n:";
read>>choice;
if(validEntry(choice))
return choice;
else
{
return getResponse(read);
}
}
//was attempting to solve the menu problem
bool validEntry(int entry)
{
if(entry>=1 && entry<=8)
return true;
else
return false;
}