#include <iostream>
#include <limits>
#include "InteractionType.h"
void displayActions() {
std::cout << "Actions: " << std::endl;
size_t id = 0;
for(auto &elem : InteractionType::values()) {
std::cout << id++ << ':' << elem.toString() << std::endl;
}
}
InteractionType getSelectedAction() {
auto interactionTypes = InteractionType::values();
std::cout << "Select an action: ";
int id;
std::cin >> id;
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
return interactionTypes.at(id);
}
int main()
{
displayActions();
std::cout << std::endl;
std::cout << getSelectedAction().toString() << std::endl;
return 0;
}
#ifndef InteractionTypeH
#define InteractionTypeH
#include <string>
#include <array>
class InteractionType {
public:
static const InteractionType PRINTACTIONS;
static const InteractionType PRINTBANKNAME;
static const InteractionType PRINTBANKACTIONS;
static const InteractionType CREATEBRANCH;
static const InteractionType CREATECUSTOMER;
static const InteractionType READBRANCH;
static const InteractionType READCUSTOMER;
static const InteractionType UPDATEBRANCH;
static const InteractionType UPDATECUSTOMER;
static const InteractionType DELETEBRANCH;
static const InteractionType DELETECUSTOMER;
static const InteractionType QUITAPP;
std::string toString() const;
static std::array<InteractionType, 12> values();
private:
std::string description;
InteractionType(std::string description);
};
#endif
#include "InteractionType.h"
const InteractionType InteractionType::PRINTACTIONS("Print Actions");
const InteractionType InteractionType::PRINTBANKNAME("Print Bank Name");
const InteractionType InteractionType::PRINTBANKACTIONS("Print Bank Actions");
const InteractionType InteractionType::CREATEBRANCH("Create a Branch");
const InteractionType InteractionType::CREATECUSTOMER("Create a Customer");
const InteractionType InteractionType::READBRANCH("Read Branches");
const InteractionType InteractionType::READCUSTOMER("Read Customers");
const InteractionType InteractionType::UPDATEBRANCH("Update a Branch");
const InteractionType InteractionType::UPDATECUSTOMER("Update a Customer");
const InteractionType InteractionType::DELETEBRANCH("Delete a Branch");
const InteractionType InteractionType::DELETECUSTOMER("Delete a Customer");
const InteractionType InteractionType::QUITAPP("Quit Application");
InteractionType::InteractionType(std::string description) {
this->description = description;
}
std::string InteractionType::toString() const {
return description;
}
std::array<InteractionType, 12> InteractionType::values() {
return {
PRINTACTIONS,
PRINTBANKNAME,
PRINTBANKACTIONS,
CREATEBRANCH,
CREATECUSTOMER,
READBRANCH,
READCUSTOMER,
UPDATEBRANCH,
UPDATECUSTOMER,
DELETEBRANCH,
DELETECUSTOMER,
QUITAPP
};
}