summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSanto Cariotti <sancn@live.com>2017-02-14 17:30:59 +0100
committerGitHub <noreply@github.com>2017-02-14 17:30:59 +0100
commit5ea86370bc21c8328ae54511cb134933ea9766a4 (patch)
treec38cb91ed858f0aaae7623a5fc4d2fa7a92a8dcc
parent6a8f0077c086f4d76546b361095b672f67c5c346 (diff)
Create ascensore.cc
-rw-r--r--ascensore.cc93
1 files changed, 93 insertions, 0 deletions
diff --git a/ascensore.cc b/ascensore.cc
new file mode 100644
index 0000000..b6810de
--- /dev/null
+++ b/ascensore.cc
@@ -0,0 +1,93 @@
+#include <iostream>
+#include <stdlib.h>
+#include <string>
+#include <unistd.h>
+
+class Ascensore
+{
+private:
+ unsigned short int floor;
+ bool doors;
+ unsigned short int maxFloor;
+public:
+ Ascensore(unsigned short int plan = 0) {floor = plan; maxFloor = 5;}
+ void Up(void);
+ void Down(void);
+ void Doors(void);
+ void getFloor(void);
+};
+
+void _clear(void);
+
+using namespace std;
+
+int main(void)
+{
+ char choose;
+ Ascensore *ascensore = new Ascensore();
+ do {
+ ascensore->getFloor();
+ cin >> choose;
+ choose = tolower(choose);
+ if(choose == 'u' || choose == 'd') ascensore->Doors();
+ sleep(2);
+ switch(choose)
+ {
+ case 'u' : ascensore->Up(); break;
+ case 'd' : ascensore->Down(); break;
+ case 'e' : break;
+ }
+ _clear();
+ if(choose == 'u' || choose == 'd') ascensore->Doors();
+ } while(choose != 'e');
+
+ cout << "SEI USCITO DALL'ASCENSORE CON SUCCESSO!";
+
+ return 0;
+}
+
+void _clear(void)
+{
+ #ifdef OS_WINDOWS
+ system("CLS");
+ #else
+ system("clear");
+ #endif
+}
+
+void Ascensore::getFloor(void)
+{
+ if(floor == maxFloor) cout << "Sei arrivato all'ultimo piano" << endl;
+ if(floor == 0) cout << "Non puoi scendere più di così" << endl;
+ cout << "SEI ATTUALMENTE AL PIANO " << floor << endl;
+ cout << "\nQUALE AZIONE SI VUOLE COMPIERE?" << endl;
+ cout << "U - salire" << endl;
+ cout << "D - scendere" << endl;
+ cout << "E - Uscire" << endl;
+ cout << "> ";
+}
+
+void Ascensore::Up(void)
+{
+ if(floor < maxFloor) floor+=1;
+}
+
+void Ascensore::Down(void)
+{
+ if(floor > 0) floor-=1;
+}
+
+void Ascensore::Doors(void)
+{
+ if(doors == true)
+ {
+ cout << "> APERTURA PORTE" << endl;
+ doors = false;
+ } else {
+ cout << "> CHIUSURA PORTE..." << endl;
+ doors = true;
+ }
+}
+
+ Contact GitHub API Training Shop Blog About
+