-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask.cpp
More file actions
169 lines (141 loc) · 3.92 KB
/
Copy pathTask.cpp
File metadata and controls
169 lines (141 loc) · 3.92 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
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
#include"Task.h"
#include"Person.h"
#include"Project.h"
#include<string>
#include <iomanip>
#include<iostream>
using namespace std;
Task::Task(const string& id,const string& name,const string& startDate,const string& endDate,const string& status1,const string& description,const string& ID,const Person& person,string due,string status2):Project(id,name,startDate,endDate,status1,description)
{
taskID=ID;
assignedPerson=person;
dueDate=due;
status=status2;
}
void Task::setTaskID(const string& ID)
{
this->taskID=ID;
}
void Task::setAssignedPerson(const Person& person)
{
this->assignedPerson=person;
}
void Task::setDueDate(string Due)
{
this->dueDate=Due;
}
void Task::setStatus(string status)
{
this->status=status;
}
string Task::getTaskID() const
{
return taskID;
}
Person Task::getAssignedPerson() const
{
return assignedPerson;
}
string Task::getDueDate() const
{
return dueDate;
}
string Task::getStatus() const
{
return status;
}
void Task::display() const
{
ifstream file("tasks.txt");
string fileTaskID, fileProjectID, fileAssignedPersonID, fileAssignedPersonName, fileAssignedPersonRole, fileDueDate, fileStatus;
bool found = false;
if (file.is_open())
{
while (file >> fileTaskID >> fileProjectID >> fileAssignedPersonID >> fileDueDate >> fileStatus) {
if (fileTaskID == taskID) {
cout << left << setw(10) << fileTaskID;
cout << left << setw(15) << fileProjectID;
cout << left << setw(15) << fileAssignedPersonID;
cout << left << setw(15) << fileDueDate;
cout << left << setw(15) << fileStatus << endl;
found = true;
break;
}
}
if (!found)
{
cout << "Task with ID " << taskID << " not found." << endl;
}
file.close();
}
else
{
cout << "Unable to open tasks file for reading." << endl;
}
}
void Task::readFromTasksFile()
{
ifstream file("tasks.txt");
string taskID, projectID, assignedPersonID, dueDate, status;
if (file.is_open())
{
cout << left << setw(16) << "Task ID";
cout << left << setw(16) << "Project ID";
cout << left << setw(16) << "Assigned Person ID";
cout << left << setw(16) << "Due Date";
cout << left << setw(16) << "Status" << endl;
while (file >> taskID >> projectID >> assignedPersonID >> dueDate >> status)
{
cout << left << setw(16) << taskID;
cout << left << setw(16) << projectID;
cout << left << setw(16) << assignedPersonID;
cout << left << setw(16) << dueDate;
cout << left << setw(16) << status << endl;
}
file.close();
}
else
{
cout << " Unable to open tasks file for reading." << endl;
}
}
void Task::appendToTasksFile() const
{
ofstream file("tasks.txt", ios::app);
if (file.is_open())
{
file << left << setw(15) << taskID;
file << left << setw(15) << getID();
file << left << setw(15) << assignedPerson.getID();
file << left << setw(15) << dueDate;
file << left << setw(15) << status << endl;
file.close();
}
else
{
cout<<" Unable to open tasks file for appending."<<endl;
}
}
void Task::removeFromFile(const string& filename, const string& taskID)
{
ifstream inFile(filename);
ofstream outFile("temp.txt");
if (!inFile.is_open())
{
cerr << "Error opening file: " << filename <<endl;
return;
}
string line;
while (getline(inFile, line))
{
if (line.find(taskID) == string::npos)
{
outFile << line <<endl;
}
}
inFile.close();
outFile.close();
remove(filename.c_str());
rename("temp.txt", filename.c_str());
cout << "Task with ID " << taskID << " removed from file successfully." <<endl;
}