-
Notifications
You must be signed in to change notification settings - Fork 0
/
historyCommand.cpp
36 lines (30 loc) · 995 Bytes
/
historyCommand.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
/**
* HistoryCommand.cpp
* HistoryCommand is a child of Command class.
* History (denoted as ‘H’): outputs all the transactions of a customer
*
* @author Olga Kuriatnyk
*/
#include "historyCommand.h"
// explicit constructor
HistoryCommand::HistoryCommand(const char &commandType) {
this->commandType = commandType;
this->customerID = 0;
}
// default destructor
HistoryCommand::~HistoryCommand() = default;
// function for reading history commands
void HistoryCommand::read(istream &is) { is >> this->customerID; }
// process history command
void HistoryCommand::process() {
Customer *customerTemp =
CustomerContainer::getInstance().retrieve(this->customerID);
// check if the customerID is valid, if not print ERROR
if (customerTemp == nullptr) {
cerr << "ERROR: invalid customer ID" << endl;
return;
}
customerTemp->printCustomerHistory();
}
// creating the object registers the type at run time
HistoryCommandFactory anonymousHistoryCommandFactory;