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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
#include <iostream>
#include <string>
/* Program to simulate flowcharts, adding console applications.
Flowcharts are composed of cells, which are interconnected.
Cells are either linked to other Cells by yes or no, or they
do not have links. The former are called LinkCell, the later
are PassCell. PassCells display a message, then the program
either 'passes' to another Cell or exists.*/
using namespace std;
// Generic Cell class
class Cell {
protected:
string msg;
public:
string getMsg() { return msg; }
virtual void flow() = 0;
};
// Linked Cell class
class LinkCell : public Cell {
private:
string val;
Cell* yLink;
Cell* nLink;
public:
LinkCell( const string& );
LinkCell( const string&, Cell*, Cell* );
void setVal();
string getVal(){ return val; }
void flow();
void setLink(Cell*, Cell*);
Cell* getyLink() { return yLink; }
Cell* getnLink() { return nLink; }
};
LinkCell::LinkCell( const string& setMsg ) {
this->msg = setMsg;
#warning setting up to call LinkCell constructor call without links - make sure links are defined for object with setLink()
}
LinkCell::LinkCell ( const string& setMsg, Cell *yParam, Cell *nParam ) {
this->msg = setMsg;
this->yLink = yParam;
this->nLink = nParam;
}
void LinkCell::setLink( Cell *yParam, Cell *nParam ){
this->yLink = yParam;
this->nLink = nParam;
}
void LinkCell::setVal() {
cout << this->getMsg() << " [y/n] ";
cin >> this->val;
while (( this->getVal()!="y" ) && ( this->getVal()!="n" )){
cout << "Please enter y or n: ";
cin >> val;
}
}
void LinkCell::flow(){
setVal();
if ( this->getVal()=="y" ) { this->yLink->flow(); }
if ( this->getVal()=="n" ) { this->nLink->flow(); }
}
// EndCell class
class EndCell : public Cell {
public:
EndCell( const string& );
void flow();
};
EndCell::EndCell ( const string& setMsg ) {
this->msg = setMsg;
}
void EndCell::flow() {
cout << this->getMsg() << endl;
}
// PassCell class
class PassCell : public Cell {
Cell *link;
public:
PassCell( const string& );
PassCell( const string&, Cell* );
void flow();
void setLink(Cell*);
Cell* getLink() { return link; };
};
PassCell::PassCell ( const string& setMsg ) {
this->msg = setMsg;
#warning setting up to call PassCell constructor without link - make sure link is defined for object with setLink()
}
PassCell::PassCell ( const string& setMsg, Cell *param ) {
this->msg = setMsg;
this->link = param;
}
void PassCell::setLink(Cell * param) {
this->link = param;
}
void PassCell::flow() {
cout << this->getMsg() << endl;
this->link->flow();
}
|