-
Notifications
You must be signed in to change notification settings - Fork 0
/
Perishable.cpp
96 lines (78 loc) · 2 KB
/
Perishable.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
/*
***********************************
Student Name:<Badal Sarkar>
Student#: <137226189>
Student e-mail: [email protected]
Subject: OOP244
Section: <SAA>
Topic: Assignment MS 5
***********************************
*/
#include <iomanip>
using namespace std;
#include "Product.h"
#include "Perishable.h"
#define _CRT_SECURE_NO_WARNINGS
namespace ama {
//constructor
Perishable::Perishable() :Product('P'){
//empty body
}
//function read()
//this function reads data from either file or user input
std::istream& Perishable::read(std::istream& in, bool interractive){
//call base class read function
Product::read(in, interractive);
if (interractive) {
in.clear();
in.ignore(2000, '\n');
std::cout <<std::setw(max_length_label)<< std::right<<"Expiry date (YYYY/MM/DD): ";
in >> productExpiryDate;
//check if reading was successful
if (productExpiryDate.status() != no_error) {
in.setstate(std::ios::failbit);
}
//update the errorsstate message
switch (productExpiryDate.status()) {
case error_year:
message("Invalid Year in Date Entry");
break;
case error_mon:
message("Invalid Month in Date Entry");
break;
case error_day:
message("Invalid Day in Date Entry");
break;
case error_input:
message("Invalid Date Entry");
}
}
else {
in.ignore(2000, ',');
//if not interractive
productExpiryDate.read(in);
}
return in;
}
//function write()
//this function writes the product information either
//into console or in the file
ostream& Perishable::write(ostream& out, int writeMode)const{
//call base class write
Product::write(out, writeMode);
if (isClear() && !isEmpty()) {
//print date
switch (writeMode) {
case write_human:
out << std::setw(max_length_label) << std::right <<"Expiry Date: "<< productExpiryDate<<std::endl;
break;
case write_table:
out << " " << productExpiryDate << " |";
break;
case write_condensed:
out << ", " << productExpiryDate;
}
}
return out;
}
}