-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask.cpp
98 lines (67 loc) · 1.73 KB
/
task.cpp
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
//
// Created by EGYPT on 2023-04-13.
//
#include "task.h"
void task::setDescription(string &desc)
{
size_t length = desc.length();
length = ((length < 200) ? length : 199);
if(length == 199)throw invalid_argument("Too much characters the system will take the first 200 characters only.");
desc.copy(description,length);
description[length]='\0';
}
void task::setDueDate(string &date)
{
size_t length = date.length();
length = ((length < 10) ? length : 9);
if(length == 9)throw invalid_argument("Too much characters the system will take the first 10 characters only.");
date.copy(dueDate,length);
dueDate[length]='\0';
}
void task::setStatus(string status)
{
size_t length = status.length();
length = ((length < 50) ? length : 49);
if(length == 49)throw invalid_argument("Too much characters the system will take the first 50 characters only.");
status.copy(completeStatus,length);
completeStatus[length]='\0';
}
string task::getStatus()
{
return completeStatus;
}
string task::getDescription()
{
return description;
}
string task::getDueDate()
{
return dueDate;
}
task::task(string description, string date, string status)
{
setDescription(description);
setDueDate(date);
setStatus(status);
}
ostream &operator<<(ostream &output, task &t)
{
output<<t.description<<"\n"<<t.dueDate<<"\n"<<t.completeStatus<<"\n";
return output;
}
istream &operator>>(istream &input, task &t)
{
if (input.peek() == '\n')
{
input.ignore();
}
input.get(t.description, 200,'\n');
input.ignore();
input >>t.dueDate;
if (input.peek() == '\n')
{
input.ignore();
}
input.get(t.completeStatus, 50,'\n');
return input;
}