-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAmaPerishable.cpp
More file actions
86 lines (71 loc) · 2.09 KB
/
AmaPerishable.cpp
File metadata and controls
86 lines (71 loc) · 2.09 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
/*
AmaPerishable.cpp
Name: Yuansheng Lu
Student ID: 136654167
E-mail: ylu140@myseneca.ca
*/
#include "AmaPerishable.h"
using namespace std;
namespace sict {
AmaPerishable::AmaPerishable() : AmaProduct('P') {}
// assessor of expiry_
//
const Date& AmaPerishable::expiry()const {
return expiry_;
}
void AmaPerishable::expiry(const Date &value) {
expiry_ = value;
}
// streamable functions
//
fstream& AmaPerishable::store(fstream& file, bool addNewLine)const {
AmaProduct::store(file, false) << "," << expiry_ << endl;
return file;
}
fstream& AmaPerishable::load(fstream& file) {
AmaProduct::load(file);
file >> expiry_;
file.ignore();
return file;
}
ostream& AmaPerishable::write(ostream& os, bool linear)const {
AmaProduct::write(os, linear);
if (err_.isClear()) { // product is not empty
if (linear) {
os << expiry_;
} else {
os << endl;
os << "Expiry date: " << expiry_;
}
}
return os;
}
istream& AmaPerishable::read(istream& is) {
Date expiry_t;
AmaProduct::read(is);
if (err_.isClear()) {
cout << "Expiry date (YYYY/MM/DD): ";
is >> expiry_t;
if (expiry_t.bad()) {
switch(expiry_t.errCode()) {
case 1:
err_.message("Invalid Date Entry");
break;
case 2:
err_.message("Invalid Year in Date Entry");
break;
case 3:
err_.message("Invalid Month in Date Entry");
break;
case 4:
err_.message("Invalid Day in Date Entry");
break;
}
is.setstate(ios::failbit);
} else {
expiry_ = expiry_t;
}
}
return is;
}
}