summaryrefslogtreecommitdiffstats
path: root/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance
diff options
context:
space:
mode:
authorSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
committerSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
commit33613a85afc4b1481367fbe92a17ee59c240250b (patch)
tree670b842326116b376b505ec2263878912fca97e2 /Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance
downloadStudium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.gz
Studium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.bz2
add new repoHEADmaster
Diffstat (limited to 'Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance')
-rw-r--r--Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/ElevatorSimulation.cpp45
-rw-r--r--Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/bell.cpp44
-rw-r--r--Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/bell.h30
-rw-r--r--Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/building.cpp65
-rw-r--r--Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/building.h42
-rw-r--r--Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/button.cpp52
-rw-r--r--Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/button.h41
-rw-r--r--Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/clock.cpp52
-rw-r--r--Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/clock.h34
-rw-r--r--Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/door.cpp81
-rw-r--r--Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/door.h40
-rw-r--r--Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/elevator.cpp231
-rw-r--r--Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/elevator.h75
-rw-r--r--Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/elevatorButton.cpp49
-rw-r--r--Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/elevatorButton.h32
-rw-r--r--Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/floor.cpp98
-rw-r--r--Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/floor.h63
-rw-r--r--Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/floorButton.cpp54
-rw-r--r--Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/floorButton.h35
-rw-r--r--Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/light.cpp64
-rw-r--r--Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/light.h35
-rw-r--r--Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/person.cpp91
-rw-r--r--Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/person.h42
-rw-r--r--Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/scheduler.cpp133
-rw-r--r--Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/scheduler.h53
25 files changed, 1581 insertions, 0 deletions
diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/ElevatorSimulation.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/ElevatorSimulation.cpp
new file mode 100644
index 0000000..e50e422
--- /dev/null
+++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/ElevatorSimulation.cpp
@@ -0,0 +1,45 @@
+// Fig. 7.24: elevatorSimulation.cpp
+// Driver for the simulation.
+#include <iostream>
+
+using std::cout;
+using std::cin;
+using std::endl;
+
+#include "building.h" // Building class definition
+
+int main()
+{
+ int duration; // length of simulation in seconds
+
+ cout << "Enter run time: ";
+ cin >> duration;
+ cin.ignore(); // ignore return char
+
+ Building building; // create the building
+
+ cout << endl << "*** ELEVATOR SIMULATION BEGINS ***"
+ << endl << endl;
+
+ building.runSimulation( duration ); // start simulation
+
+ cout << "*** ELEVATOR SIMULATION ENDS ***" << endl;
+
+ return 0;
+
+} // end main
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/bell.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/bell.cpp
new file mode 100644
index 0000000..2c97771
--- /dev/null
+++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/bell.cpp
@@ -0,0 +1,44 @@
+// Fig. 7.32: bell.cpp
+// Member-function definitions for class Bell.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include "bell.h" // Bell class definition
+
+// constructor
+Bell::Bell()
+{
+ cout << "bell created" << endl;
+
+} // end Bell constructor
+
+// destructor
+Bell::~Bell()
+{
+ cout << "bell destroyed" << endl;
+
+} // end ~Bell destructor
+
+// ring bell
+void Bell::ringBell() const
+{
+ cout << "elevator rings its bell" << endl;
+
+} // end function ringBell
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/bell.h b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/bell.h
new file mode 100644
index 0000000..7b8a9c3
--- /dev/null
+++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/bell.h
@@ -0,0 +1,30 @@
+// Fig. 7.31: bell.h
+// Bell class definition.
+#ifndef BELL_H
+#define BELL_H
+
+class Bell {
+
+public:
+ Bell(); // constructor
+ ~Bell(); // destructor
+ void ringBell() const; // ring the bell
+
+}; // end class Bell
+
+#endif // BELL_H
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/building.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/building.cpp
new file mode 100644
index 0000000..630cc91
--- /dev/null
+++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/building.cpp
@@ -0,0 +1,65 @@
+// Fig. 7.26: building.cpp
+// Member-function definitions for class Building.
+#include <iostream>
+
+using std::cout;
+using std::cin;
+using std::endl;
+
+#include "building.h" // Building class definition
+
+// constructor
+Building::Building()
+ : floor1( Floor::FLOOR1, elevator ),
+ floor2( Floor::FLOOR2, elevator ),
+ elevator( floor1, floor2 ),
+ scheduler( floor1, floor2 )
+{
+ cout << "building created" << endl;
+
+} // end Building constructor
+
+// destructor
+Building::~Building()
+{
+ cout << "building destroyed" << endl;
+
+} // end ~Building destructor
+
+// function to control simulation
+void Building::runSimulation( int totalTime )
+{
+ int currentTime = 0;
+
+ while ( currentTime < totalTime ) {
+ clock.tick(); // increment time
+ currentTime = clock.getTime(); // get new time
+ cout << "TIME: " << currentTime << endl;
+
+ // process person arrivals for currentTime
+ scheduler.processTime( currentTime );
+
+ // process elevator events for currentTime
+ elevator.processTime( currentTime );
+
+ // wait for Enter key press, so user can view output
+ cin.get();
+
+ } // end while
+
+} // end function runSimulation
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/building.h b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/building.h
new file mode 100644
index 0000000..5d47f07
--- /dev/null
+++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/building.h
@@ -0,0 +1,42 @@
+// Fig. 7.25: building.h
+// Building class definition.
+#ifndef BUILDING_H
+#define BUILDING_H
+
+#include "elevator.h" // Elevator class definition
+#include "floor.h" // Floor class definition
+#include "clock.h" // Clock class definition
+#include "scheduler.h" // Scheduler class definition
+
+class Building {
+
+public:
+ Building(); // constructor
+ ~Building(); // destructor
+ void runSimulation( int ); // controls simulation
+
+private:
+ Floor floor1; // floor1 object
+ Floor floor2; // floor2 object
+ Elevator elevator; // elevator object
+ Clock clock; // clock object
+ Scheduler scheduler; // scheduler object
+
+}; // end class Building
+
+#endif // BUILDING_H
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/button.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/button.cpp
new file mode 100644
index 0000000..2195a4f
--- /dev/null
+++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/button.cpp
@@ -0,0 +1,52 @@
+// Fig. 9.34: button.cpp
+// Member function definitions for class Button.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include "button.h" // Button class definition
+
+// constructor
+Button::Button( Elevator &elevatorHandle )
+ : elevatorRef( elevatorHandle ), pressed( false )
+{
+ cout << "button created" << endl;
+
+} // end Button constructor
+
+// destructor
+Button::~Button()
+{
+ cout << "button destroyed" << endl;
+
+} // end Button destructor
+
+// press button
+void Button::pressButton()
+{
+ pressed = true;
+
+} // end function pressButton
+
+// reset button
+void Button::resetButton()
+{
+ pressed = false;
+
+} // end function resetButton
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/button.h b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/button.h
new file mode 100644
index 0000000..fbc0f94
--- /dev/null
+++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/button.h
@@ -0,0 +1,41 @@
+// Fig. 9.33: button.h
+// Definition for class Button.
+#ifndef BUTTON_H
+#define BUTTON_H
+
+class Elevator; // forward declaration
+
+class Button {
+
+public:
+ Button( Elevator & ); // constructor
+ ~Button(); // destructor
+ void pressButton(); // sets button on
+ void resetButton(); // resets button off
+
+protected:
+
+ // reference to button's elevator
+ Elevator &elevatorRef;
+
+private:
+ bool pressed; // state of button
+
+}; // end class Button
+
+#endif // BUTTON_H
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/clock.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/clock.cpp
new file mode 100644
index 0000000..725a189
--- /dev/null
+++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/clock.cpp
@@ -0,0 +1,52 @@
+// Fig. 7.28: clock.cpp
+// Member-function definitions for class Clock.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include "clock.h" // Clock class definition
+
+// constructor
+Clock::Clock()
+ : time( 0 ) // initialize time to 0
+{
+ cout << "clock created" << endl;
+
+} // end Clock constructor
+
+// destructor
+Clock::~Clock()
+{
+ cout << "clock destroyed" << endl;
+
+} // end ~Clock destructor
+
+// increment time by 1
+void Clock::tick()
+{
+ time++;
+
+} // end function tick
+
+// return current time
+int Clock::getTime() const
+{
+ return time;
+
+} // end function getTime
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/clock.h b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/clock.h
new file mode 100644
index 0000000..de97814
--- /dev/null
+++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/clock.h
@@ -0,0 +1,34 @@
+// Fig. 7.27: clock.h
+// Clock class definition.
+#ifndef CLOCK_H
+#define CLOCK_H
+
+class Clock {
+
+public:
+ Clock(); // constructor
+ ~Clock(); // destructor
+ void tick(); // increment clock by one second
+ int getTime() const; // returns clock's current time
+
+private:
+ int time; // clock's time
+
+}; // end class Clock
+
+#endif // CLOCK_H
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/door.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/door.cpp
new file mode 100644
index 0000000..7adbe37
--- /dev/null
+++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/door.cpp
@@ -0,0 +1,81 @@
+// Fig. 7.36: door.cpp
+// Member-function definitions for class Door.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include "door.h" // Door class definition
+#include "person.h" // Person class definition
+#include "floor.h" // Floor class definition
+#include "elevator.h" // Elevator class definition
+
+// constructor
+Door::Door()
+ : open( false ) // initialize open to false
+{
+ cout << "door created" << endl;
+
+} // end Door constructor
+
+// destructor
+Door::~Door()
+{
+ cout << "door destroyed" << endl;
+
+} // end ~Door destructor
+
+// open the door
+void Door::openDoor( Person * const passengerPtr,
+ Person * const nextPassengerPtr, Floor &currentFloor,
+ Elevator &elevator )
+{
+ if ( !open ) { // if door is not open, open door
+ open = true;
+
+ cout << "elevator opens its door on floor "
+ << currentFloor.getNumber() << endl;
+
+ // if passenger is in elevator, tell person to leave
+ if ( passengerPtr != 0 ) {
+ passengerPtr->exitElevator( currentFloor, elevator );
+ delete passengerPtr; // passenger leaves simulation
+
+ } // end if
+
+ // if passenger waiting to enter elevator,
+ // tell passenger to enter
+ if ( nextPassengerPtr != 0 )
+ nextPassengerPtr->enterElevator(
+ elevator, currentFloor );
+
+ } // end outer if
+
+} // end function openDoor
+
+// close the door
+void Door::closeDoor( const Floor &currentFloor )
+{
+ if ( open ) { // if door is open, close door
+ open = false;
+ cout << "elevator closes its door on floor "
+ << currentFloor.getNumber() << endl;
+
+ } // end if
+
+} // end function closeDoor
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/door.h b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/door.h
new file mode 100644
index 0000000..05c7b3e
--- /dev/null
+++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/door.h
@@ -0,0 +1,40 @@
+// Fig. 7.35: door.h
+// Door class definition.
+#ifndef DOOR_H
+#define DOOR_H
+
+class Person; // forward declaration
+class Floor; // forward declaration
+class Elevator; // forward declaration
+
+class Door {
+
+public:
+ Door(); // constructor
+ ~Door(); // destructor
+
+ void openDoor( Person * const, // opens door
+ Person * const, Floor &, Elevator & );
+ void closeDoor( const Floor & ); // closes door
+
+private:
+ bool open; // open or closed
+
+};
+
+#endif // DOOR_H
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/elevator.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/elevator.cpp
new file mode 100644
index 0000000..26e01f4
--- /dev/null
+++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/elevator.cpp
@@ -0,0 +1,231 @@
+// Fig. 7.42: elevator.cpp
+// Member-function definitions for class Elevator.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include "elevator.h" // Elevator class definition
+#include "person.h" // Person class definition
+#include "floor.h" // Floor class definition
+
+// static constants that represent time required to travel
+// between floors and directions of the elevator
+const int Elevator::ELEVATOR_TRAVEL_TIME = 5;
+const int Elevator::UP = 0;
+const int Elevator::DOWN = 1;
+
+// constructor
+Elevator::Elevator( Floor &firstFloor, Floor &secondFloor )
+ : elevatorButton( *this ),
+ currentBuildingClockTime( 0 ),
+ moving( false ),
+ direction( UP ),
+ currentFloor( Floor::FLOOR1 ),
+ arrivalTime( 0 ),
+ floor1NeedsService( false ),
+ floor2NeedsService( false ),
+ floor1Ref( firstFloor ),
+ floor2Ref( secondFloor ),
+ passengerPtr( 0 )
+{
+ cout << "elevator created" << endl;
+
+} // end Elevator constructor
+
+// destructor
+Elevator::~Elevator()
+{
+ delete passengerPtr;
+ cout << "elevator destroyed" << endl;
+
+} // end ~Elevator destructor
+
+// give time to elevator
+void Elevator::processTime( int time )
+{
+ currentBuildingClockTime = time;
+
+ if ( moving ) // elevator is moving
+ processPossibleArrival();
+
+ else // elevator is not moving
+ processPossibleDeparture();
+
+ if ( !moving )
+ cout << "elevator at rest on floor "
+ << currentFloor << endl;
+
+} // end function processTime
+
+// when elevator is moving, determine if it should stop
+void Elevator::processPossibleArrival()
+{
+ // if elevator arrives at destination floor
+ if ( currentBuildingClockTime == arrivalTime ) {
+
+ currentFloor = // update current floor
+ ( currentFloor == Floor::FLOOR1 ?
+ Floor::FLOOR2 : Floor::FLOOR1 );
+
+ direction = // update direction
+ ( currentFloor == Floor::FLOOR1 ? UP : DOWN );
+
+ cout << "elevator arrives on floor "
+ << currentFloor << endl;
+
+ // process arrival at currentFloor
+ arriveAtFloor( currentFloor == Floor::FLOOR1 ?
+ floor1Ref : floor2Ref );
+
+ return;
+
+ } // end if
+
+ // elevator still moving
+ cout << "elevator moving "
+ << ( direction == UP ? "up" : "down" ) << endl;
+
+} // end function processPossibleArrival
+
+// determine whether elevator should move
+void Elevator::processPossibleDeparture()
+{
+ // this floor needs service?
+ bool currentFloorNeedsService =
+ currentFloor == Floor::FLOOR1 ?
+ floor1NeedsService : floor2NeedsService;
+
+ // other floor needs service?
+ bool otherFloorNeedsService =
+ currentFloor == Floor::FLOOR1 ?
+ floor2NeedsService : floor1NeedsService;
+
+ // service this floor (if needed)
+ if ( currentFloorNeedsService ) {
+ arriveAtFloor( currentFloor == Floor::FLOOR1 ?
+ floor1Ref : floor2Ref );
+
+ return;
+ }
+
+ // service other floor (if needed)
+ if ( otherFloorNeedsService )
+ prepareToLeave( true );
+
+} // end function processPossibleDeparture
+
+// arrive at a particular floor
+void Elevator::arriveAtFloor( Floor& arrivalFloor )
+{
+ moving = false; // reset state
+
+ cout << "elevator resets its button" << endl;
+ elevatorButton.resetButton();
+
+ bell.ringBell();
+
+ // notify floor that elevator has arrived
+ Person *floorPersonPtr = arrivalFloor.elevatorArrived();
+
+ door.openDoor(
+ passengerPtr, floorPersonPtr, arrivalFloor, *this );
+
+ // this floor needs service?
+ bool currentFloorNeedsService =
+ currentFloor == Floor::FLOOR1 ?
+ floor1NeedsService : floor2NeedsService;
+
+ // other floor needs service?
+ bool otherFloorNeedsService =
+ currentFloor == Floor::FLOOR1 ?
+ floor2NeedsService : floor1NeedsService;
+
+ // if this floor does not need service
+ // prepare to leave for the other floor
+ if ( !currentFloorNeedsService )
+ prepareToLeave( otherFloorNeedsService );
+
+ else // otherwise, reset service flag
+ currentFloor == Floor::FLOOR1 ?
+ floor1NeedsService = false: floor2NeedsService = false;
+
+} // end function arriveAtFloor
+
+// request service from elevator
+void Elevator::summonElevator( int floor )
+{
+ // set appropriate servicing flag
+ floor == Floor::FLOOR1 ?
+ floor1NeedsService = true : floor2NeedsService = true;
+
+} // end function summonElevator
+
+// accept a passenger
+void Elevator::passengerEnters( Person * const personPtr )
+{
+ // board passenger
+ passengerPtr = personPtr;
+
+ cout << "person " << passengerPtr->getID()
+ << " enters elevator from floor "
+ << currentFloor << endl;
+
+} // end function passengerEnters
+
+// notify elevator that passenger is exiting
+void Elevator::passengerExits()
+{
+ passengerPtr = 0;
+
+} // end function passengerExits
+
+// prepare to leave a floor
+void Elevator::prepareToLeave( bool leaving )
+{
+ // get reference to current floor
+ Floor &thisFloor =
+ currentFloor == Floor::FLOOR1 ? floor1Ref : floor2Ref;
+
+ // notify floor that elevator may be leaving
+ thisFloor.elevatorLeaving();
+
+ door.closeDoor( thisFloor );
+
+ if ( leaving ) // leave, if necessary
+ move();
+
+} // end function prepareToLeave
+
+// go to other floor
+void Elevator::move()
+{
+ moving = true; // change state
+
+ // schedule arrival time
+ arrivalTime = currentBuildingClockTime +
+ ELEVATOR_TRAVEL_TIME;
+
+ cout << "elevator begins moving "
+ << ( direction == DOWN ? "down " : "up " )
+ << "to floor "
+ << ( direction == DOWN ? '1' : '2' )
+ << " (arrives at time " << arrivalTime << ')'
+ << endl;
+
+} // end function move
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/elevator.h b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/elevator.h
new file mode 100644
index 0000000..ed69376
--- /dev/null
+++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/elevator.h
@@ -0,0 +1,75 @@
+// Fig. 7.41: elevator.h
+// Elevator class definition.
+#ifndef ELEVATOR_H
+#define ELEVATOR_H
+
+#include "elevatorButton.h"
+#include "door.h"
+#include "bell.h"
+
+class Floor; // forward declaration
+class Person; // forward declaration
+
+class Elevator {
+
+public:
+ Elevator( Floor &, Floor & ); // constructor
+ ~Elevator(); // destructor
+ void summonElevator( int ); // request to service floor
+ void prepareToLeave( bool ); // prepare to leave
+ void processTime( int ); // give time to elevator
+ void passengerEnters( Person * const ); // board a passenger
+ void passengerExits(); // exit a passenger
+
+ // public object accessible to client code with
+ // access to Elevator object
+ ElevatorButton elevatorButton;
+
+private:
+
+ // utility functions
+ void processPossibleArrival();
+ void processPossibleDeparture();
+ void arriveAtFloor( Floor & );
+ void move();
+
+ // static constants that represent time required to travel
+ // between floors and directions of the elevator
+ static const int ELEVATOR_TRAVEL_TIME;
+ static const int UP;
+ static const int DOWN;
+
+ // data members
+ int currentBuildingClockTime; // current time
+ bool moving; // elevator state
+ int direction; // current direction
+ int currentFloor; // current location
+ int arrivalTime; // time to arrive at a floor
+ bool floor1NeedsService; // floor1 service flag
+ bool floor2NeedsService; // floor2 service flag
+
+ Floor &floor1Ref; // reference to floor1
+ Floor &floor2Ref; // reference to floor2
+ Person *passengerPtr; // pointer to passenger
+
+ Door door; // door object
+ Bell bell; // bell object
+
+}; // end class Elevator
+
+#endif // ELEVATOR_H
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/elevatorButton.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/elevatorButton.cpp
new file mode 100644
index 0000000..c7b7117
--- /dev/null
+++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/elevatorButton.cpp
@@ -0,0 +1,49 @@
+// Fig. 9.36: elevatorButton.cpp:
+// Member-function definitions for class ElevatorButton.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include "elevatorButton.h" // ElevatorButton class definition
+#include "elevator.h" // Elevator class definition
+
+// constructor
+ElevatorButton::ElevatorButton( Elevator &elevatorHandle )
+ : Button( elevatorHandle )
+{
+ cout << "elevator button created" << endl;
+
+} // end ElevatorButton constructor
+
+// destructor
+ElevatorButton::~ElevatorButton()
+{
+ cout << "elevator button destroyed" << endl;
+
+} // end ~ElevatorButton destructor
+
+// press button and signal elevator to prepare to leave floor
+void ElevatorButton::pressButton()
+{
+ Button::pressButton();
+ cout << "elevator button tells elevator to prepare to leave"
+ << endl;
+ elevatorRef.prepareToLeave( true );
+
+} // end function pressButton
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/elevatorButton.h b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/elevatorButton.h
new file mode 100644
index 0000000..4567799
--- /dev/null
+++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/elevatorButton.h
@@ -0,0 +1,32 @@
+// Fig. 9.35: elevatorButton.h
+// ElevatorButton class definition.
+#ifndef ELEVATORBUTTON_H
+#define ELEVATORBUTTON_H
+
+#include "button.h" // Button class definition
+
+class ElevatorButton : public Button {
+
+public:
+ ElevatorButton( Elevator & ); // constructor
+ ~ElevatorButton(); // destructor
+ void pressButton(); // press the button
+
+}; // end class ElevatorButton
+
+#endif // ELEVATORBUTTON_H
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/floor.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/floor.cpp
new file mode 100644
index 0000000..c24564b
--- /dev/null
+++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/floor.cpp
@@ -0,0 +1,98 @@
+// Fig. 7.44: floor.cpp
+// Member-function definitions for class Floor.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include "floor.h" // Floor class definition
+#include "person.h" // Person class definition
+#include "elevator.h" // Elevator class definition
+#include "door.h" // Door class definition
+
+// static constants that represent the floor numbers
+const int Floor::FLOOR1 = 1;
+const int Floor::FLOOR2 = 2;
+
+// constructor
+Floor::Floor(int number, Elevator &elevatorHandle )
+ : floorButton( number, elevatorHandle ),
+ floorNumber( number ),
+ elevatorRef( elevatorHandle ),
+ occupantPtr ( 0 ),
+ light( floorNumber )
+{
+ cout << "floor " << floorNumber << " created" << endl;
+
+} // end Floor constructor
+
+// destructor
+Floor::~Floor()
+{
+ delete occupantPtr;
+ cout << "floor " << floorNumber << " destroyed" << endl;
+
+} // end ~Floor destructor
+
+// determine whether floor is occupied
+bool Floor::isOccupied() const
+{
+ return ( occupantPtr != 0 );
+
+} // end function isOccupied
+
+// return this floor's number
+int Floor::getNumber() const
+{
+ return floorNumber;
+
+} // end function getNumber
+
+// person arrives on floor
+void Floor::personArrives( Person * const personPtr )
+{
+ occupantPtr = personPtr;
+
+} // end function personArrives
+
+// notify floor that elevator has arrived
+Person *Floor::elevatorArrived()
+{
+ cout << "floor " << floorNumber
+ << " resets its button" << endl;
+
+ floorButton.resetButton();
+ light.turnOn();
+
+ return occupantPtr;
+
+} // end function elevatorArrived
+
+// tell floor that elevator is leaving
+void Floor::elevatorLeaving()
+{
+ light.turnOff();
+
+} // end function elevatorLeaving
+
+// notifies floor that person is leaving
+void Floor::personBoardingElevator()
+{
+ occupantPtr = 0; // person no longer on floor
+
+} // end function personBoardingElevator
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/floor.h b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/floor.h
new file mode 100644
index 0000000..5ded23e
--- /dev/null
+++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/floor.h
@@ -0,0 +1,63 @@
+// Fig. 7.43: floor.h
+// Floor class definition.
+#ifndef FLOOR_H
+#define FLOOR_H
+
+#include "floorButton.h"
+#include "light.h"
+
+class Elevator; // forward declaration
+class Person; // forward declaration
+
+class Floor {
+
+public:
+ Floor( int, Elevator & ); // constructor
+ ~Floor(); // destructor
+ bool isOccupied() const; // return true if floor occupied
+ int getNumber() const; // return floor's number
+
+ // pass a handle to new person coming on floor
+ void personArrives( Person * const );
+
+ // notify floor that elevator has arrived
+ Person *elevatorArrived();
+
+ // notify floor that elevator is leaving
+ void elevatorLeaving();
+
+ // notify floor that person is leaving floor
+ void personBoardingElevator();
+
+ // static constants representing floor numbers
+ static const int FLOOR1;
+ static const int FLOOR2;
+
+ // public FloorButton object accessible to
+ // any client code with access to a Floor
+ FloorButton floorButton;
+
+private:
+ const int floorNumber; // the floor's number
+ Elevator &elevatorRef; // reference to elevator
+ Person *occupantPtr; // pointer to person on floor
+ Light light; // light object
+
+}; // end class Floor
+
+#endif // FLOOR_H
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/floorButton.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/floorButton.cpp
new file mode 100644
index 0000000..0370b4e
--- /dev/null
+++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/floorButton.cpp
@@ -0,0 +1,54 @@
+// Fig. 9.38: floorButton.cpp
+// Member-function definitions for class FloorButton.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include "floorButton.h"
+#include "elevator.h"
+
+// constructor
+FloorButton::FloorButton( int floor, Elevator &elevatorHandle )
+ : Button( elevatorHandle ),
+ floorNumber( floor )
+{
+ cout << "floor " << floorNumber << " button created"
+ << endl;
+
+} // end FloorButton constructor
+
+// destructor
+FloorButton::~FloorButton()
+{
+ cout << "floor " << floorNumber << " button destroyed"
+ << endl;
+
+} // end ~FloorButton destructor
+
+// press the button
+void FloorButton::pressButton()
+{
+ Button::pressButton();
+ cout << "floor " << floorNumber
+ << " button summons elevator" << endl;
+
+ // call elevator to this floor
+ elevatorRef.summonElevator( floorNumber );
+
+} // end function pressButton
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/floorButton.h b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/floorButton.h
new file mode 100644
index 0000000..a0525f7
--- /dev/null
+++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/floorButton.h
@@ -0,0 +1,35 @@
+// Fig. 9.37: floorButton.h
+// FloorButton class definition.
+#ifndef FLOORBUTTON_H
+#define FLOORBUTTON_H
+
+#include "button.h" // Button class definition
+
+class FloorButton : public Button {
+
+public:
+ FloorButton( int, Elevator & ); // constructor
+ ~FloorButton(); // destructor
+ void pressButton(); // press the button
+
+private:
+ const int floorNumber; // button's floor number
+
+}; // end class FloorButton
+
+#endif // FLOORBUTTON_H
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/light.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/light.cpp
new file mode 100644
index 0000000..54f3204
--- /dev/null
+++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/light.cpp
@@ -0,0 +1,64 @@
+// Fig. 7.34: light.cpp
+// Member-function definitions for class Light.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include "light.h" // Light class definition
+
+// constructor
+Light::Light( int number )
+ : on( false ),
+ floorNumber( number )
+{
+ cout << "floor " << floorNumber << " light created" << endl;
+
+} // end Light constructor
+
+// destuctor
+Light::~Light()
+{
+ cout << "floor " << floorNumber
+ << " light destroyed" << endl;
+
+} // end ~Light destructor
+
+// turn light on
+void Light::turnOn()
+{
+ if ( !on ) { // if light not on, turn it on
+ on = true;
+ cout << "floor " << floorNumber
+ << " light turns on" << endl;
+
+ } // end if
+
+} // end function turnOn
+
+// turn light off
+void Light::turnOff()
+{
+ if ( on ) { // if light is on, turn it off
+ on = false;
+ cout << "floor " << floorNumber
+ << " light turns off" << endl;
+
+ } // end if
+
+} // end function turnOff
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/light.h b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/light.h
new file mode 100644
index 0000000..69c559c
--- /dev/null
+++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/light.h
@@ -0,0 +1,35 @@
+// Fig. 7.33: light.h
+// Light class definition.
+#ifndef LIGHT_H
+#define LIGHT_H
+
+class Light {
+
+public:
+ Light( int ); // constructor
+ ~Light(); // destructor
+ void turnOn(); // turns light on
+ void turnOff(); // turns light off
+
+private:
+ bool on; // true if on; false if off
+ const int floorNumber; // floor number that contains light
+
+}; // end class Light
+
+#endif // LIGHT_H
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/person.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/person.cpp
new file mode 100644
index 0000000..a3cfeb7
--- /dev/null
+++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/person.cpp
@@ -0,0 +1,91 @@
+// Fig. 7.46: person.cpp
+// Member-function definitions for class Person.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include "person.h" // Person class definition
+#include "floor.h" // Floor class definition
+#include "elevator.h" // Elevator class definition
+
+// initialize static member personCount
+int Person::personCount = 0;
+
+// constructor
+Person::Person( int destFloor )
+ : ID( ++personCount ),
+ destinationFloor( destFloor )
+{
+ // empty body
+
+} // end Person constructor
+
+// destructor
+Person::~Person()
+{
+ cout << "(person " << ID << " destructor invoked)" << endl;
+
+} // end ~Person destructor
+
+// return person's ID number
+int Person::getID() const
+{
+ return ID;
+
+} // end function getID
+
+// person walks onto a floor
+void Person::stepOntoFloor( Floor& floor )
+{
+ // notify floor person is coming
+ cout << "person " << ID << " steps onto floor "
+ << floor.getNumber() << endl;
+ floor.personArrives( this );
+
+ // press button on floor
+ cout << "person " << ID
+ << " presses floor button on floor "
+ << floor.getNumber() << endl;
+ floor.floorButton.pressButton();
+
+} // end function stepOntoFloor
+
+// person enters elevator
+void Person::enterElevator( Elevator &elevator, Floor &floor )
+{
+ floor.personBoardingElevator(); // person leaves floor
+
+ elevator.passengerEnters( this ); // person enters elevator
+
+ // press button on elevator
+ cout << "person " << ID
+ << " presses elevator button" << endl;
+ elevator.elevatorButton.pressButton();
+
+} // end function enterElevator
+
+// person exits elevator
+void Person::exitElevator(
+ const Floor &floor, Elevator &elevator ) const
+{
+ cout << "person " << ID << " exits elevator on floor "
+ << floor.getNumber() << endl;
+ elevator.passengerExits();
+
+} // end function exitElevator
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/person.h b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/person.h
new file mode 100644
index 0000000..64906a5
--- /dev/null
+++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/person.h
@@ -0,0 +1,42 @@
+// Fig. 7.45: person.h
+// Person class definition.
+#ifndef PERSON_H
+#define PERSON_H
+
+class Floor; // forward declaration
+class Elevator; // forward declaration
+
+class Person {
+
+public:
+ Person( int ); // constructor
+ ~Person(); // destructor
+ int getID() const; // returns person's ID
+
+ void stepOntoFloor( Floor & );
+ void enterElevator( Elevator &, Floor & );
+ void exitElevator( const Floor &, Elevator & ) const;
+
+private:
+ static int personCount; // total number of people
+ const int ID; // person's unique ID #
+ const int destinationFloor; // destination floor #
+
+}; // end class Person
+
+#endif // PERSON_H
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/scheduler.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/scheduler.cpp
new file mode 100644
index 0000000..ac9110c
--- /dev/null
+++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/scheduler.cpp
@@ -0,0 +1,133 @@
+// Fig. 7.30: scheduler.cpp
+// Member-function definitions for class Scheduler.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include <cstdlib>
+#include <ctime>
+
+#include "scheduler.h" // Scheduler class definition
+#include "floor.h" // Floor class definition
+#include "person.h" // Person class definition
+
+// constructor
+Scheduler::Scheduler( Floor &firstFloor, Floor &secondFloor )
+ : currentClockTime( 0 ),
+ floor1Ref( firstFloor ),
+ floor2Ref( secondFloor )
+{
+ srand( time( 0 ) ); // seed random number generator
+ cout << "scheduler created" << endl;
+
+ // schedule first arrivals for floor 1 and floor 2
+ scheduleTime( floor1Ref );
+ scheduleTime( floor2Ref );
+
+} // end Scheduler constructor
+
+// destructor
+Scheduler::~Scheduler()
+{
+ cout << "scheduler destroyed" << endl;
+
+} // end Scheduler destructor
+
+// schedule arrival on a floor
+void Scheduler::scheduleTime( const Floor &floor )
+{
+ int floorNumber = floor.getNumber();
+ int arrivalTime = currentClockTime + ( 5 + rand() % 16 );
+
+ floorNumber == Floor::FLOOR1 ?
+ floor1ArrivalTime = arrivalTime :
+ floor2ArrivalTime = arrivalTime;
+
+ cout << "(scheduler schedules next person for floor "
+ << floorNumber << " at time " << arrivalTime << ')'
+ << endl;
+
+} // end function scheduleTime
+
+// reschedule arrival on a floor
+void Scheduler::delayTime( const Floor &floor )
+{
+ int floorNumber = floor.getNumber();
+
+ int arrivalTime = ( floorNumber == Floor::FLOOR1 ) ?
+ ++floor1ArrivalTime : ++floor2ArrivalTime;
+
+ cout << "(scheduler delays next person for floor "
+ << floorNumber << " until time " << arrivalTime << ')'
+ << endl;
+
+} // end function delayTime
+
+// give time to scheduler
+void Scheduler::processTime( int time )
+{
+ currentClockTime = time; // record time
+
+ // handle arrivals on floor 1
+ handleArrivals( floor1Ref, currentClockTime );
+
+ // handle arrivals on floor 2
+ handleArrivals( floor2Ref, currentClockTime );
+
+} // end function processTime
+
+// create new person and place it on specified floor
+void Scheduler::createNewPerson( Floor &floor )
+{
+ int destinationFloor =
+ floor.getNumber() == Floor::FLOOR1 ?
+ Floor::FLOOR2 : Floor::FLOOR1;
+
+ // create new person
+ Person *newPersonPtr = new Person( destinationFloor );
+
+ cout << "scheduler creates person "
+ << newPersonPtr->getID() << endl;
+
+ // place person on proper floor
+ newPersonPtr->stepOntoFloor( floor );
+
+ scheduleTime( floor ); // schedule next arrival
+
+} // end function createNewPerson
+
+// handle arrivals for a specified floor
+void Scheduler::handleArrivals( Floor &floor, int time )
+{
+ int floorNumber = floor.getNumber();
+
+ int arrivalTime = ( floorNumber == Floor::FLOOR1 ) ?
+ floor1ArrivalTime : floor2ArrivalTime;
+
+ if ( arrivalTime == time ) {
+
+ if ( floor.isOccupied() ) // if floor occupied,
+ delayTime( floor ); // delay arrival
+
+ else // otherwise,
+ createNewPerson( floor ); // create new person
+
+ } // end outer if
+
+} // end function handleArrivals
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/
diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/scheduler.h b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/scheduler.h
new file mode 100644
index 0000000..6bb084c
--- /dev/null
+++ b/Bachelor/Prog2/Codebeispiele/1_ch09/elevatorinheritance/scheduler.h
@@ -0,0 +1,53 @@
+// Fig. 7.29: scheduler.h
+// Scheduler class definition.
+#ifndef SCHEDULER_H
+#define SCHEDULER_H
+
+class Floor; // forward declaration
+
+class Scheduler {
+
+public:
+ Scheduler( Floor &, Floor & ); // constructor
+ ~Scheduler(); // destructor
+ void processTime( int ); // set scheduler's time
+
+private:
+ // schedule arrival to a floor
+ void scheduleTime( const Floor & );
+
+ // delay arrival to a floor
+ void delayTime( const Floor & );
+
+ // create new person; place on floor
+ void createNewPerson( Floor & );
+
+ // handle person arrival on a floor
+ void handleArrivals( Floor &, int );
+
+ int currentClockTime;
+
+ Floor &floor1Ref;
+ Floor &floor2Ref;
+
+ int floor1ArrivalTime;
+ int floor2ArrivalTime;
+
+}; // end class Scheduler
+
+#endif // SCHEDULER_H
+
+/**************************************************************************
+ * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and Prentice *
+ * Hall. All Rights Reserved. *
+ * *
+ * DISCLAIMER: The authors and publisher of this book have used their *
+ * best efforts in preparing the book. These efforts include the *
+ * development, research, and testing of the theories and programs *
+ * to determine their effectiveness. The authors and publisher make *
+ * no warranty of any kind, expressed or implied, with regard to these *
+ * programs or to the documentation contained in these books. The authors *
+ * and publisher shall not be liable in any event for incidental or *
+ * consequential damages in connection with, or arising out of, the *
+ * furnishing, performance, or use of these programs. *
+ *************************************************************************/