-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignmentFile.cpp
More file actions
113 lines (94 loc) · 2.98 KB
/
AssignmentFile.cpp
File metadata and controls
113 lines (94 loc) · 2.98 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
// Alfred Ledgin
// 10/3/2015
// CS 303
// Project 1
#include <iostream>
#include "AssignmentFile.h"
using namespace std;
bool AssignmentFile::read(istream& input)
{
string inputString;
string inputDueDate;
string inputDescription;
string inputAssignedDate;
string inputStatus;
Assignment newAssignment;
if (input)
{
while (getline(input, inputString))
{
int spaceCount = 0;
for (int counter = 0; counter < inputString.length(); counter++)
{
if ((inputString[counter] == ' ') && (inputString[counter + 1] != ' '))
spaceCount++;
}
// Count the spaces in each line.
// Count any string of consecutive spaces as a single space.
String_Tokenizer tokenizer(inputString, ", ");
if (tokenizer.has_more_tokens())
inputDueDate = tokenizer.next_token();
if (tokenizer.has_more_tokens())
{
inputDescription = "";
while (spaceCount > 2)
{
inputDescription += tokenizer.next_token();
spaceCount--;
if (spaceCount > 2)
inputDescription += " ";
} // Handle descriptions that include spaces.
}
if (tokenizer.has_more_tokens())
inputAssignedDate = tokenizer.next_token();
if (tokenizer.has_more_tokens())
inputStatus = tokenizer.next_token();
// Consistently use hyphens in date strings.
for (int counter = 0; counter < inputDueDate.length(); counter++)
{
if (inputDueDate[counter] == '/')
inputDueDate[counter] = '-';
}
for (int counter = 0; counter < inputAssignedDate.length();
counter++)
{
if (inputAssignedDate[counter] == '/')
inputAssignedDate[counter] = '-';
}
newAssignment.setDueDate(inputDueDate);
newAssignment.setDescription(inputDescription);
newAssignment.setAssignedDate(inputAssignedDate);
newAssignment.setStatus(convertStatus(inputStatus));
// Add the assignment to the appropriate list.
if (inputStatus == "assigned")
{
uncompleted.addAssignment(newAssignment);
}
else
completed.addAssignment(newAssignment);
}
return true;
}
else
return false;
}
bool AssignmentFile::write(ostream& output)
{
if (output)
{
completed.displayAll(output);
uncompleted.displayAll(output);
return true;
}
else
return false;
}
int AssignmentFile::convertStatus(string inputStatus)
{
if (inputStatus == "completed")
return 1;
else if (inputStatus == "late")
return 2;
else
return 0;
}