diff options
| author | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
|---|---|---|
| committer | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
| commit | 33613a85afc4b1481367fbe92a17ee59c240250b (patch) | |
| tree | 670b842326116b376b505ec2263878912fca97e2 /Bachelor/Prog2/Codebeispiele/1_ch09 | |
| download | Studium-master.tar.gz Studium-master.tar.bz2 | |
Diffstat (limited to 'Bachelor/Prog2/Codebeispiele/1_ch09')
57 files changed, 3437 insertions, 0 deletions
diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_10_11/CircleTest/circle2.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_10_11/CircleTest/circle2.cpp new file mode 100644 index 0000000..3f7084f --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_10_11/CircleTest/circle2.cpp @@ -0,0 +1,74 @@ +// Fig. 9.11: circle2.cpp
+// Circle2 class member-function definitions.
+#include <iostream>
+
+using std::cout;
+
+#include "circle2.h" // Circle2 class definition
+
+// default constructor
+Circle2::Circle2( int xValue, int yValue, double radiusValue )
+{
+ x = xValue;
+ y = yValue;
+ setRadius( radiusValue );
+
+} // end Circle2 constructor
+
+// set radius
+void Circle2::setRadius( double radiusValue )
+{
+ radius = ( radiusValue < 0.0 ? 0.0 : radiusValue );
+
+} // end function setRadius
+
+// return radius
+double Circle2::getRadius() const
+{
+ return radius;
+
+} // end function getRadius
+
+// calculate and return diameter
+double Circle2::getDiameter() const
+{
+ return 2 * radius;
+
+} // end function getDiameter
+
+// calculate and return circumference
+double Circle2::getCircumference() const
+{
+ return 3.14159 * getDiameter();
+
+} // end function getCircumference
+
+// calculate and return area
+double Circle2::getArea() const
+{
+ return 3.14159 * radius * radius;
+
+} // end function getArea
+
+// output Circle2 object
+void Circle2::print() const
+{
+ cout << "Center = [" << x << ", " << y << ']'
+ << "; Radius = " << radius;
+
+} // end function print
+
+/**************************************************************************
+ * (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. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_10_11/CircleTest/circle2.h b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_10_11/CircleTest/circle2.h new file mode 100644 index 0000000..0fd592d --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_10_11/CircleTest/circle2.h @@ -0,0 +1,44 @@ +// Fig. 9.10: circle2.h
+// Circle2 class contains x-y coordinate pair and radius.
+#ifndef CIRCLE2_H
+#define CIRCLE2_H
+
+#include "point.h" // Point class definition
+
+class Circle2 : public Point {
+
+public:
+
+ // default constructor
+ Circle2( int = 0, int = 0, double = 0.0 );
+
+ void setRadius( double ); // set radius
+ double getRadius() const; // return radius
+
+ double getDiameter() const; // return diameter
+ double getCircumference() const; // return circumference
+ double getArea() const; // return area
+
+ void print() const; // output Circle2 object
+
+private:
+ double radius; // Circle2's radius
+
+}; // end class Circle2
+
+#endif
+
+/**************************************************************************
+ * (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. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_10_11/CircleTest/point.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_10_11/CircleTest/point.cpp new file mode 100644 index 0000000..38261da --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_10_11/CircleTest/point.cpp @@ -0,0 +1,65 @@ +// Fig. 9.5: point.cpp
+// Point class member-function definitions.
+#include <iostream>
+
+using std::cout;
+
+#include "point.h" // Point class definition
+
+// default constructor
+Point::Point( int xValue, int yValue )
+{
+ x = xValue;
+ y = yValue;
+
+} // end Point constructor
+
+// set x in coordinate pair
+void Point::setX( int xValue )
+{
+ x = xValue; // no need for validation
+
+} // end function setX
+
+// return x from coordinate pair
+int Point::getX() const
+{
+ return x;
+
+} // end function getX
+
+// set y in coordinate pair
+void Point::setY( int yValue )
+{
+ y = yValue; // no need for validation
+
+} // end function setY
+
+// return y from coordinate pair
+int Point::getY() const
+{
+ return y;
+
+} // end function getY
+
+// output Point object
+void Point::print() const
+{
+ cout << '[' << x << ", " << y << ']';
+
+} // end function print
+
+/**************************************************************************
+ * (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. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_10_11/CircleTest/point.h b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_10_11/CircleTest/point.h new file mode 100644 index 0000000..7593775 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_10_11/CircleTest/point.h @@ -0,0 +1,40 @@ +// Fig. 9.4: point.h
+// Point class definition represents an x-y coordinate pair.
+#ifndef POINT_H
+#define POINT_H
+
+class Point {
+
+public:
+ Point( int = 0, int = 0 ); // default constructor
+
+ void setX( int ); // set x in coordinate pair
+ int getX() const; // return x from coordinate pair
+
+ void setY( int ); // set y in coordinate pair
+ int getY() const; // return y from coordinate pair
+
+ void print() const; // output Point object
+
+private:
+ int x; // x part of coordinate pair
+ int y; // y part of coordinate pair
+
+}; // end class Point
+
+#endif
+
+/**************************************************************************
+ * (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. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_12_16/CircleTest3/circle3.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_12_16/CircleTest3/circle3.cpp new file mode 100644 index 0000000..24a1f67 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_12_16/CircleTest3/circle3.cpp @@ -0,0 +1,74 @@ +// Fig. 9.15: circle3.cpp
+// Circle3 class member-function definitions.
+#include <iostream>
+
+using std::cout;
+
+#include "circle3.h" // Circle3 class definition
+
+// default constructor
+Circle3::Circle3( int xValue, int yValue, double radiusValue )
+{
+ x = xValue;
+ y = yValue;
+ setRadius( radiusValue );
+
+} // end Circle3 constructor
+
+// set radius
+void Circle3::setRadius( double radiusValue )
+{
+ radius = ( radiusValue < 0.0 ? 0.0 : radiusValue );
+
+} // end function setRadius
+
+// return radius
+double Circle3::getRadius() const
+{
+ return radius;
+
+} // end function getRadius
+
+// calculate and return diameter
+double Circle3::getDiameter() const
+{
+ return 2 * radius;
+
+} // end function getDiameter
+
+// calculate and return circumference
+double Circle3::getCircumference() const
+{
+ return 3.14159 * getDiameter();
+
+} // end function getCircumference
+
+// calculate and return area
+double Circle3::getArea() const
+{
+ return 3.14159 * radius * radius;
+
+} // end function getArea
+
+// output Circle3 object
+void Circle3::print() const
+{
+ cout << "Center = [" << x << ", " << y << ']'
+ << "; Radius = " << radius;
+
+} // end function print
+
+/**************************************************************************
+ * (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. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_12_16/CircleTest3/circle3.h b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_12_16/CircleTest3/circle3.h new file mode 100644 index 0000000..137a2bd --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_12_16/CircleTest3/circle3.h @@ -0,0 +1,44 @@ +// Fig. 9.14: circle3.h
+// Circle3 class contains x-y coordinate pair and radius.
+#ifndef CIRCLE3_H
+#define CIRCLE3_H
+
+#include "point2.h" // Point2 class definition
+
+class Circle3 : public Point2 {
+
+public:
+
+ // default constructor
+ Circle3( int = 0, int = 0, double = 0.0 );
+
+ void setRadius( double ); // set radius
+ double getRadius() const; // return radius
+
+ double getDiameter() const; // return diameter
+ double getCircumference() const; // return circumference
+ double getArea() const; // return area
+
+ void print() const; // output Circle3 object
+
+private:
+ double radius; // Circle3's radius
+
+}; // end class Circle3
+
+#endif
+
+/**************************************************************************
+ * (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. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_12_16/CircleTest3/circletest3.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_12_16/CircleTest3/circletest3.cpp new file mode 100644 index 0000000..6f3a598 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_12_16/CircleTest3/circletest3.cpp @@ -0,0 +1,63 @@ +// Fig. 9.16: circletest3.cpp
+// Testing class Circle3.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+using std::fixed;
+
+#include <iomanip>
+
+using std::setprecision;
+
+#include "circle3.h" // Circle3 class definition
+
+int main()
+{
+ Circle3 circle( 37, 43, 2.5 ); // instantiate Circle3 object
+
+ // display point coordinates
+ cout << "X coordinate is " << circle.getX()
+ << "\nY coordinate is " << circle.getY()
+ << "\nRadius is " << circle.getRadius();
+
+ circle.setX( 2 ); // set new x-coordinate
+ circle.setY( 2 ); // set new y-coordinate
+ circle.setRadius( 4.25 ); // set new radius
+
+ // display new point value
+ cout << "\n\nThe new location and radius of circle are\n";
+ circle.print();
+
+ // display floating-point values with 2 digits of precision
+ cout << fixed << setprecision( 2 );
+
+ // display Circle3's diameter
+ cout << "\nDiameter is " << circle.getDiameter();
+
+ // display Circle3's circumference
+ cout << "\nCircumference is " << circle.getCircumference();
+
+ // display Circle3's area
+ cout << "\nArea is " << circle.getArea();
+
+ cout << endl;
+
+ return 0; // indicates successful termination
+
+} // 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. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_12_16/CircleTest3/point2.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_12_16/CircleTest3/point2.cpp new file mode 100644 index 0000000..27b014a --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_12_16/CircleTest3/point2.cpp @@ -0,0 +1,65 @@ +// Fig. 9.13: point2.cpp
+// Point2 class member-function definitions.
+#include <iostream>
+
+using std::cout;
+
+#include "point2.h" // Point2 class definition
+
+// default constructor
+Point2::Point2( int xValue, int yValue )
+{
+ x = xValue;
+ y = yValue;
+
+} // end Point2 constructor
+
+// set x in coordinate pair
+void Point2::setX( int xValue )
+{
+ x = xValue; // no need for validation
+
+} // end function setX
+
+// return x from coordinate pair
+int Point2::getX() const
+{
+ return x;
+
+} // end function getX
+
+// set y in coordinate pair
+void Point2::setY( int yValue )
+{
+ y = yValue; // no need for validation
+
+} // end function setY
+
+// return y from coordinate pair
+int Point2::getY() const
+{
+ return y;
+
+} // end function getY
+
+// output Point2 object
+void Point2::print() const
+{
+ cout << '[' << x << ", " << y << ']';
+
+} // end function print
+
+/**************************************************************************
+ * (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/Fig09_12_16/CircleTest3/point2.h b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_12_16/CircleTest3/point2.h new file mode 100644 index 0000000..5b81781 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_12_16/CircleTest3/point2.h @@ -0,0 +1,40 @@ +// Fig. 9.12: point2.h
+// Point2 class definition represents an x-y coordinate pair.
+#ifndef POINT2_H
+#define POINT2_H
+
+class Point2 {
+
+public:
+ Point2( int = 0, int = 0 ); // default constructor
+
+ void setX( int ); // set x in coordinate pair
+ int getX() const; // return x from coordinate pair
+
+ void setY( int ); // set y in coordinate pair
+ int getY() const; // return y from coordinate pair
+
+ void print() const; // output Point2 object
+
+protected:
+ int x; // x part of coordinate pair
+ int y; // y part of coordinate pair
+
+}; // end class Point2
+
+#endif
+
+/**************************************************************************
+ * (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. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_25_29/ConstructorsAndDestructors/circle5.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_25_29/ConstructorsAndDestructors/circle5.cpp new file mode 100644 index 0000000..d37278f --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_25_29/ConstructorsAndDestructors/circle5.cpp @@ -0,0 +1,88 @@ +// Fig. 9.28: circle5.cpp
+// Circle5 class member-function definitions.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include "circle5.h" // Circle5 class definition
+
+// default constructor
+Circle5::Circle5( int xValue, int yValue, double radiusValue )
+ : Point4( xValue, yValue ) // call base-class constructor
+{
+ setRadius( radiusValue );
+
+ cout << "Circle5 constructor: ";
+ print();
+ cout << endl;
+
+} // end Circle5 constructor
+
+// destructor
+Circle5::~Circle5()
+{
+ cout << "Circle5 destructor: ";
+ print();
+ cout << endl;
+
+} // end Circle5 destructor
+
+// set radius
+void Circle5::setRadius( double radiusValue )
+{
+ radius = ( radiusValue < 0.0 ? 0.0 : radiusValue );
+
+} // end function setRadius
+
+// return radius
+double Circle5::getRadius() const
+{
+ return radius;
+
+} // end function getRadius
+
+// calculate and return diameter
+double Circle5::getDiameter() const
+{
+ return 2 * getRadius();
+
+} // end function getDiameter
+
+// calculate and return circumference
+double Circle5::getCircumference() const
+{
+ return 3.14159 * getDiameter();
+
+} // end function getCircumference
+
+// calculate and return area
+double Circle5::getArea() const
+{
+ return 3.14159 * getRadius() * getRadius();
+
+} // end function getArea
+
+// output Circle5 object
+void Circle5::print() const
+{
+ cout << "Center = ";
+ Point4::print(); // invoke Point4's print function
+ cout << "; Radius = " << getRadius();
+
+} // end function print
+
+/**************************************************************************
+ * (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. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_25_29/ConstructorsAndDestructors/circle5.h b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_25_29/ConstructorsAndDestructors/circle5.h new file mode 100644 index 0000000..e2d8e78 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_25_29/ConstructorsAndDestructors/circle5.h @@ -0,0 +1,45 @@ +// Fig. 9.27: circle5.h
+// Circle5 class contains x-y coordinate pair and radius.
+#ifndef CIRCLE5_H
+#define CIRCLE5_H
+
+#include "point4.h" // Point4 class definition
+
+class Circle5 : public Point4 {
+
+public:
+
+ // default constructor
+ Circle5( int = 0, int = 0, double = 0.0 );
+
+ ~Circle5(); // destructor
+ void setRadius( double ); // set radius
+ double getRadius() const; // return radius
+
+ double getDiameter() const; // return diameter
+ double getCircumference() const; // return circumference
+ double getArea() const; // return area
+
+ void print() const; // output Circle5 object
+
+private:
+ double radius; // Circle5's radius
+
+}; // end class Circle5
+
+#endif
+
+/**************************************************************************
+ * (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/Fig09_25_29/ConstructorsAndDestructors/fig09_29.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_25_29/ConstructorsAndDestructors/fig09_29.cpp new file mode 100644 index 0000000..634348a --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_25_29/ConstructorsAndDestructors/fig09_29.cpp @@ -0,0 +1,44 @@ +// Fig. 9.29: fig09_29.cpp
+// Display order in which base-class and derived-class
+// constructors are called.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include "circle5.h" // Circle5 class definition
+
+int main()
+{
+ { // begin new scope
+
+ Point4 point( 11, 22 );
+
+ } // end scope
+
+ cout << endl;
+ Circle5 circle1( 72, 29, 4.5 );
+
+ cout << endl;
+ Circle5 circle2( 5, 5, 10 );
+
+ cout << endl;
+
+ return 0; // indicates successful termination
+
+} // 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. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_25_29/ConstructorsAndDestructors/point4.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_25_29/ConstructorsAndDestructors/point4.cpp new file mode 100644 index 0000000..8538b6e --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_25_29/ConstructorsAndDestructors/point4.cpp @@ -0,0 +1,77 @@ +// Fig. 9.26: point4.cpp
+// Point4 class member-function definitions.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include "point4.h" // Point4 class definition
+
+// default constructor
+Point4::Point4( int xValue, int yValue )
+ : x( xValue ), y( yValue )
+{
+ cout << "Point4 constructor: ";
+ print();
+ cout << endl;
+
+} // end Point4 constructor
+
+// destructor
+Point4::~Point4()
+{
+ cout << "Point4 destructor: ";
+ print();
+ cout << endl;
+
+} // end Point4 destructor
+
+// set x in coordinate pair
+void Point4::setX( int xValue )
+{
+ x = xValue; // no need for validation
+
+} // end function setX
+
+// return x from coordinate pair
+int Point4::getX() const
+{
+ return x;
+
+} // end function getX
+
+// set y in coordinate pair
+void Point4::setY( int yValue )
+{
+ y = yValue; // no need for validation
+
+} // end function setY
+
+// return y from coordinate pair
+int Point4::getY() const
+{
+ return y;
+
+} // end function getY
+
+// output Point4 object
+void Point4::print() const
+{
+ cout << '[' << getX() << ", " << getY() << ']';
+
+} // end function print
+
+/**************************************************************************
+ * (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. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_25_29/ConstructorsAndDestructors/point4.h b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_25_29/ConstructorsAndDestructors/point4.h new file mode 100644 index 0000000..bcb87c3 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/Fig09_25_29/ConstructorsAndDestructors/point4.h @@ -0,0 +1,41 @@ +// Fig. 9.25: point4.h
+// Point4 class definition represents an x-y coordinate pair.
+#ifndef POINT4_H
+#define POINT4_H
+
+class Point4 {
+
+public:
+ Point4( int = 0, int = 0 ); // default constructor
+ ~Point4(); // destructor
+
+ void setX( int ); // set x in coordinate pair
+ int getX() const; // return x from coordinate pair
+
+ void setY( int ); // set y in coordinate pair
+ int getY() const; // return y from coordinate pair
+
+ void print() const; // output Point3 object
+
+private:
+ int x; // x part of coordinate pair
+ int y; // y part of coordinate pair
+
+}; // end class Point4
+
+#endif
+
+/**************************************************************************
+ * (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/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 ¤tFloor,
+ 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 ¤tFloor )
+{
+ 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. *
+ *************************************************************************/
diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_04_06/PointTest/point.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_04_06/PointTest/point.cpp new file mode 100644 index 0000000..38261da --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_04_06/PointTest/point.cpp @@ -0,0 +1,65 @@ +// Fig. 9.5: point.cpp
+// Point class member-function definitions.
+#include <iostream>
+
+using std::cout;
+
+#include "point.h" // Point class definition
+
+// default constructor
+Point::Point( int xValue, int yValue )
+{
+ x = xValue;
+ y = yValue;
+
+} // end Point constructor
+
+// set x in coordinate pair
+void Point::setX( int xValue )
+{
+ x = xValue; // no need for validation
+
+} // end function setX
+
+// return x from coordinate pair
+int Point::getX() const
+{
+ return x;
+
+} // end function getX
+
+// set y in coordinate pair
+void Point::setY( int yValue )
+{
+ y = yValue; // no need for validation
+
+} // end function setY
+
+// return y from coordinate pair
+int Point::getY() const
+{
+ return y;
+
+} // end function getY
+
+// output Point object
+void Point::print() const
+{
+ cout << '[' << x << ", " << y << ']';
+
+} // end function print
+
+/**************************************************************************
+ * (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. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_04_06/PointTest/point.h b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_04_06/PointTest/point.h new file mode 100644 index 0000000..7593775 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_04_06/PointTest/point.h @@ -0,0 +1,40 @@ +// Fig. 9.4: point.h
+// Point class definition represents an x-y coordinate pair.
+#ifndef POINT_H
+#define POINT_H
+
+class Point {
+
+public:
+ Point( int = 0, int = 0 ); // default constructor
+
+ void setX( int ); // set x in coordinate pair
+ int getX() const; // return x from coordinate pair
+
+ void setY( int ); // set y in coordinate pair
+ int getY() const; // return y from coordinate pair
+
+ void print() const; // output Point object
+
+private:
+ int x; // x part of coordinate pair
+ int y; // y part of coordinate pair
+
+}; // end class Point
+
+#endif
+
+/**************************************************************************
+ * (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. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_04_06/PointTest/pointtest.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_04_06/PointTest/pointtest.cpp new file mode 100644 index 0000000..3ca57bf --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_04_06/PointTest/pointtest.cpp @@ -0,0 +1,43 @@ +// Fig. 9.6: pointtest.cpp
+// Testing class Point.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+
+#include "point.h" // Point class definition
+
+int main()
+{
+ Point point( 72, 115 ); // instantiate Point object
+
+ // display point coordinates
+ cout << "X coordinate is " << point.getX()
+ << "\nY coordinate is " << point.getY();
+
+ point.setX( 10 ); // set x-coordinate
+ point.setY( 10 ); // set y-coordinate
+
+ // display new point value
+ cout << "\n\nThe new location of point is ";
+ point.print();
+ cout << endl;
+
+ return 0; // indicates successful termination
+
+} // 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. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_07_09/CircleTest/circle.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_07_09/CircleTest/circle.cpp new file mode 100644 index 0000000..0a32f7d --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_07_09/CircleTest/circle.cpp @@ -0,0 +1,102 @@ +// Fig. 9.8: circle.cpp
+// Circle class member-function definitions.
+#include <iostream>
+
+using std::cout;
+
+#include "circle.h" // Circle class definition
+
+// default constructor
+Circle::Circle( int xValue, int yValue, double radiusValue )
+{
+ x = xValue;
+ y = yValue;
+ setRadius( radiusValue );
+
+} // end Circle constructor
+
+// set x in coordinate pair
+void Circle::setX( int xValue )
+{
+ x = xValue; // no need for validation
+
+} // end function setX
+
+// return x from coordinate pair
+int Circle::getX() const
+{
+ return x;
+
+} // end function getX
+
+// set y in coordinate pair
+void Circle::setY( int yValue )
+{
+ y = yValue; // no need for validation
+
+} // end function setY
+
+// return y from coordinate pair
+int Circle::getY() const
+{
+ return y;
+
+} // end function getY
+
+// set radius
+void Circle::setRadius( double radiusValue )
+{
+ radius = ( radiusValue < 0.0 ? 0.0 : radiusValue );
+
+} // end function setRadius
+
+// return radius
+double Circle::getRadius() const
+{
+ return radius;
+
+} // end function getRadius
+
+// calculate and return diameter
+double Circle::getDiameter() const
+{
+ return 2 * radius;
+
+} // end function getDiameter
+
+// calculate and return circumference
+double Circle::getCircumference() const
+{
+ return 3.14159 * getDiameter();
+
+} // end function getCircumference
+
+// calculate and return area
+double Circle::getArea() const
+{
+ return 3.14159 * radius * radius;
+
+} // end function getArea
+
+// output Circle object
+void Circle::print() const
+{
+ cout << "Center = [" << x << ", " << y << ']'
+ << "; Radius = " << radius;
+
+} // end function print
+
+/**************************************************************************
+ * (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. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_07_09/CircleTest/circle.h b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_07_09/CircleTest/circle.h new file mode 100644 index 0000000..4ee5c3e --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_07_09/CircleTest/circle.h @@ -0,0 +1,50 @@ +// Fig. 9.7: circle.h
+// Circle class contains x-y coordinate pair and radius.
+#ifndef CIRCLE_H
+#define CIRCLE_H
+
+class Circle {
+
+public:
+
+ // default constructor
+ Circle( int = 0, int = 0, double = 0.0 );
+
+ void setX( int ); // set x in coordinate pair
+ int getX() const; // return x from coordinate pair
+
+ void setY( int ); // set y in coordinate pair
+ int getY() const; // return y from coordinate pair
+
+ void setRadius( double ); // set radius
+ double getRadius() const; // return radius
+
+ double getDiameter() const; // return diameter
+ double getCircumference() const; // return circumference
+ double getArea() const; // return area
+
+ void print() const; // output Circle object
+
+private:
+ int x; // x-coordinate of Circle's center
+ int y; // y-coordinate of Circle's center
+ double radius; // Circle's radius
+
+}; // end class Circle
+
+#endif
+
+/**************************************************************************
+ * (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/fig09_07_09/CircleTest/circletest.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_07_09/CircleTest/circletest.cpp new file mode 100644 index 0000000..f71c455 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_07_09/CircleTest/circletest.cpp @@ -0,0 +1,63 @@ +// Fig. 9.9: circletest.cpp
+// Testing class Circle.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+using std::fixed;
+
+#include <iomanip>
+
+using std::setprecision;
+
+#include "circle.h" // Circle class definition
+
+int main()
+{
+ Circle circle( 37, 43, 2.5 ); // instantiate Circle object
+
+ // display point coordinates
+ cout << "X coordinate is " << circle.getX()
+ << "\nY coordinate is " << circle.getY()
+ << "\nRadius is " << circle.getRadius();
+
+ circle.setX( 2 ); // set new x-coordinate
+ circle.setY( 2 ); // set new y-coordinate
+ circle.setRadius( 4.25 ); // set new radius
+
+ // display new point value
+ cout << "\n\nThe new location and radius of circle are\n";
+ circle.print();
+
+ // display floating-point values with 2 digits of precision
+ cout << fixed << setprecision( 2 );
+
+ // display Circle's diameter
+ cout << "\nDiameter is " << circle.getDiameter();
+
+ // display Circle's circumference
+ cout << "\nCircumference is " << circle.getCircumference();
+
+ // display Circle's area
+ cout << "\nArea is " << circle.getArea();
+
+ cout << endl;
+
+ return 0; // indicates successful termination
+
+} // 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/fig09_17_21/CircleTest4/circle4.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_17_21/CircleTest4/circle4.cpp new file mode 100644 index 0000000..3e043c3 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_17_21/CircleTest4/circle4.cpp @@ -0,0 +1,74 @@ +// Fig. 9.20: circle4.cpp
+// Circle4 class member-function definitions.
+#include <iostream>
+
+using std::cout;
+
+#include "circle4.h" // Circle4 class definition
+
+// default constructor
+Circle4::Circle4( int xValue, int yValue, double radiusValue )
+ : Point3( xValue, yValue ) // call base-class constructor
+{
+ setRadius( radiusValue );
+
+} // end Circle4 constructor
+
+// set radius
+void Circle4::setRadius( double radiusValue )
+{
+ radius = ( radiusValue < 0.0 ? 0.0 : radiusValue );
+
+} // end function setRadius
+
+// return radius
+double Circle4::getRadius() const
+{
+ return radius;
+
+} // end function getRadius
+
+// calculate and return diameter
+double Circle4::getDiameter() const
+{
+ return 2 * getRadius();
+
+} // end function getDiameter
+
+// calculate and return circumference
+double Circle4::getCircumference() const
+{
+ return 3.14159 * getDiameter();
+
+} // end function getCircumference
+
+// calculate and return area
+double Circle4::getArea() const
+{
+ return 3.14159 * getRadius() * getRadius();
+
+} // end function getArea
+
+// output Circle4 object
+void Circle4::print() const
+{
+ cout << "Center = ";
+ Point3::print(); // invoke Point3's print function
+ cout << "; Radius = " << getRadius();
+
+} // end function print
+
+/**************************************************************************
+ * (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. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_17_21/CircleTest4/circle4.h b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_17_21/CircleTest4/circle4.h new file mode 100644 index 0000000..46f0f58 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_17_21/CircleTest4/circle4.h @@ -0,0 +1,44 @@ +// Fig. 9.19: circle4.h
+// Circle4 class contains x-y coordinate pair and radius.
+#ifndef CIRCLE4_H
+#define CIRCLE4_H
+
+#include "point3.h" // Point3 class definition
+
+class Circle4 : public Point3 {
+
+public:
+
+ // default constructor
+ Circle4( int = 0, int = 0, double = 0.0 );
+
+ void setRadius( double ); // set radius
+ double getRadius() const; // return radius
+
+ double getDiameter() const; // return diameter
+ double getCircumference() const; // return circumference
+ double getArea() const; // return area
+
+ void print() const; // output Circle4 object
+
+private:
+ double radius; // Circle4's radius
+
+}; // end class Circle4
+
+#endif
+
+/**************************************************************************
+ * (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. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_17_21/CircleTest4/circletest4.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_17_21/CircleTest4/circletest4.cpp new file mode 100644 index 0000000..c82f30f --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_17_21/CircleTest4/circletest4.cpp @@ -0,0 +1,63 @@ +// Fig. 9.21: circletest4.cpp
+// Testing class Circle4.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+using std::fixed;
+
+#include <iomanip>
+
+using std::setprecision;
+
+#include "circle4.h" // Circle4 class definition
+
+int main()
+{
+ Circle4 circle( 37, 43, 2.5 ); // instantiate Circle4 object
+
+ // display point coordinates
+ cout << "X coordinate is " << circle.getX()
+ << "\nY coordinate is " << circle.getY()
+ << "\nRadius is " << circle.getRadius();
+
+ circle.setX( 2 ); // set new x-coordinate
+ circle.setY( 2 ); // set new y-coordinate
+ circle.setRadius( 4.25 ); // set new radius
+
+ // display new circle value
+ cout << "\n\nThe new location and radius of circle are\n";
+ circle.print();
+
+ // display floating-point values with 2 digits of precision
+ cout << fixed << setprecision( 2 );
+
+ // display Circle4's diameter
+ cout << "\nDiameter is " << circle.getDiameter();
+
+ // display Circle4's circumference
+ cout << "\nCircumference is " << circle.getCircumference();
+
+ // display Circle4's area
+ cout << "\nArea is " << circle.getArea();
+
+ cout << endl;
+
+ return 0; // indicates successful termination
+
+} // 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. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_17_21/CircleTest4/point3.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_17_21/CircleTest4/point3.cpp new file mode 100644 index 0000000..ac4f642 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_17_21/CircleTest4/point3.cpp @@ -0,0 +1,65 @@ +// Fig. 9.18: point3.cpp
+// Point3 class member-function definitions.
+#include <iostream>
+
+using std::cout;
+
+#include "point3.h" // Point3 class definition
+
+// default constructor
+Point3::Point3( int xValue, int yValue )
+ : x( xValue ), y( yValue )
+{
+ // empty body
+
+} // end Point3 constructor
+
+// set x in coordinate pair
+void Point3::setX( int xValue )
+{
+ x = xValue; // no need for validation
+
+} // end function setX
+
+// return x from coordinate pair
+int Point3::getX() const
+{
+ return x;
+
+} // end function getX
+
+// set y in coordinate pair
+void Point3::setY( int yValue )
+{
+ y = yValue; // no need for validation
+
+} // end function setY
+
+// return y from coordinate pair
+int Point3::getY() const
+{
+ return y;
+
+} // end function getY
+
+// output Point3 object
+void Point3::print() const
+{
+ cout << '[' << getX() << ", " << getY() << ']';
+
+} // end function print
+
+/**************************************************************************
+ * (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. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_17_21/CircleTest4/point3.h b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_17_21/CircleTest4/point3.h new file mode 100644 index 0000000..028f105 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_17_21/CircleTest4/point3.h @@ -0,0 +1,40 @@ +// Fig. 9.17: point3.h
+// Point3 class definition represents an x-y coordinate pair.
+#ifndef POINT3_H
+#define POINT3_H
+
+class Point3 {
+
+public:
+ Point3( int = 0, int = 0 ); // default constructor
+
+ void setX( int ); // set x in coordinate pair
+ int getX() const; // return x from coordinate pair
+
+ void setY( int ); // set y in coordinate pair
+ int getY() const; // return y from coordinate pair
+
+ void print() const; // output Point3 object
+
+private:
+ int x; // x part of coordinate pair
+ int y; // y part of coordinate pair
+
+}; // end class Point3
+
+#endif
+
+/**************************************************************************
+ * (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. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/circle4.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/circle4.cpp new file mode 100644 index 0000000..3e043c3 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/circle4.cpp @@ -0,0 +1,74 @@ +// Fig. 9.20: circle4.cpp
+// Circle4 class member-function definitions.
+#include <iostream>
+
+using std::cout;
+
+#include "circle4.h" // Circle4 class definition
+
+// default constructor
+Circle4::Circle4( int xValue, int yValue, double radiusValue )
+ : Point3( xValue, yValue ) // call base-class constructor
+{
+ setRadius( radiusValue );
+
+} // end Circle4 constructor
+
+// set radius
+void Circle4::setRadius( double radiusValue )
+{
+ radius = ( radiusValue < 0.0 ? 0.0 : radiusValue );
+
+} // end function setRadius
+
+// return radius
+double Circle4::getRadius() const
+{
+ return radius;
+
+} // end function getRadius
+
+// calculate and return diameter
+double Circle4::getDiameter() const
+{
+ return 2 * getRadius();
+
+} // end function getDiameter
+
+// calculate and return circumference
+double Circle4::getCircumference() const
+{
+ return 3.14159 * getDiameter();
+
+} // end function getCircumference
+
+// calculate and return area
+double Circle4::getArea() const
+{
+ return 3.14159 * getRadius() * getRadius();
+
+} // end function getArea
+
+// output Circle4 object
+void Circle4::print() const
+{
+ cout << "Center = ";
+ Point3::print(); // invoke Point3's print function
+ cout << "; Radius = " << getRadius();
+
+} // end function print
+
+/**************************************************************************
+ * (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. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/circle4.h b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/circle4.h new file mode 100644 index 0000000..46f0f58 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/circle4.h @@ -0,0 +1,44 @@ +// Fig. 9.19: circle4.h
+// Circle4 class contains x-y coordinate pair and radius.
+#ifndef CIRCLE4_H
+#define CIRCLE4_H
+
+#include "point3.h" // Point3 class definition
+
+class Circle4 : public Point3 {
+
+public:
+
+ // default constructor
+ Circle4( int = 0, int = 0, double = 0.0 );
+
+ void setRadius( double ); // set radius
+ double getRadius() const; // return radius
+
+ double getDiameter() const; // return diameter
+ double getCircumference() const; // return circumference
+ double getArea() const; // return area
+
+ void print() const; // output Circle4 object
+
+private:
+ double radius; // Circle4's radius
+
+}; // end class Circle4
+
+#endif
+
+/**************************************************************************
+ * (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. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/cylinder.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/cylinder.cpp new file mode 100644 index 0000000..d0047db --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/cylinder.cpp @@ -0,0 +1,68 @@ +// Fig. 9.23: cylinder.cpp
+// Cylinder class inherits from class Circle4.
+#include <iostream>
+
+using std::cout;
+
+#include "cylinder.h" // Cylinder class definition
+
+// default constructor
+Cylinder::Cylinder( int xValue, int yValue, double radiusValue,
+ double heightValue )
+ : Circle4( xValue, yValue, radiusValue )
+{
+ setHeight( heightValue );
+
+} // end Cylinder constructor
+
+// set Cylinder's height
+void Cylinder::setHeight( double heightValue )
+{
+ height = ( heightValue < 0.0 ? 0.0 : heightValue );
+
+} // end function setHeight
+
+// get Cylinder's height
+double Cylinder::getHeight() const
+{
+ return height;
+
+} // end function getHeight
+
+// redefine Circle4 function getArea to calculate Cylinder area
+double Cylinder::getArea() const
+{
+ return 2 * Circle4::getArea() +
+ getCircumference() * getHeight();
+
+} // end function getArea
+
+// calculate Cylinder volume
+double Cylinder::getVolume() const
+{
+ return Circle4::getArea() * getHeight();
+
+} // end function getVolume
+
+// output Cylinder object
+void Cylinder::print() const
+{
+ Circle4::print();
+ cout << "; Height = " << getHeight();
+
+} // end function print
+
+/**************************************************************************
+ * (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/fig09_22_24/CylinderTest/cylinder.h b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/cylinder.h new file mode 100644 index 0000000..461feb8 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/cylinder.h @@ -0,0 +1,42 @@ +// Fig. 9.22: cylinder.h
+// Cylinder class inherits from class Circle4.
+#ifndef CYLINDER_H
+#define CYLINDER_H
+
+#include "circle4.h" // Circle4 class definition
+
+class Cylinder : public Circle4 {
+
+public:
+
+ // default constructor
+ Cylinder( int = 0, int = 0, double = 0.0, double = 0.0 );
+
+ void setHeight( double ); // set Cylinder's height
+ double getHeight() const; // return Cylinder's height
+
+ double getArea() const; // return Cylinder's area
+ double getVolume() const; // return Cylinder's volume
+ void print() const; // output Cylinder
+
+private:
+ double height; // Cylinder's height
+
+}; // end class Cylinder
+
+#endif
+
+/**************************************************************************
+ * (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. *
+ *************************************************************************/
\ No newline at end of file diff --git a/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/cylindertest.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/cylindertest.cpp new file mode 100644 index 0000000..8fb49b9 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/cylindertest.cpp @@ -0,0 +1,70 @@ +// Fig. 9.24: cylindertest.cpp
+// Testing class Cylinder.
+#include <iostream>
+
+using std::cout;
+using std::endl;
+using std::fixed;
+
+#include <iomanip>
+
+using std::setprecision;
+
+#include "cylinder.h" // Cylinder class definition
+
+int main()
+{
+ // instantiate Cylinder object
+ Cylinder cylinder( 12, 23, 2.5, 5.7 );
+
+ // display point coordinates
+ cout << "X coordinate is " << cylinder.getX()
+ << "\nY coordinate is " << cylinder.getY()
+ << "\nRadius is " << cylinder.getRadius()
+ << "\nHeight is " << cylinder.getHeight();
+
+ cylinder.setX( 2 ); // set new x-coordinate
+ cylinder.setY( 2 ); // set new y-coordinate
+ cylinder.setRadius( 4.25 ); // set new radius
+ cylinder.setHeight( 10 ); // set new height
+
+ // display new cylinder value
+ cout << "\n\nThe new location and radius of circle are\n";
+ cylinder.print();
+
+ // display floating-point values with 2 digits of precision
+ cout << fixed << setprecision( 2 );
+
+ // display cylinder's diameter
+ cout << "\n\nDiameter is " << cylinder.getDiameter();
+
+ // display cylinder's circumference
+ cout << "\nCircumference is "
+ << cylinder.getCircumference();
+
+ // display cylinder's area
+ cout << "\nArea is " << cylinder.getArea();
+
+ // display cylinder's volume
+ cout << "\nVolume is " << cylinder.getVolume();
+
+ cout << endl;
+
+ return 0; // indicates successful termination
+
+} // 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/fig09_22_24/CylinderTest/point3.cpp b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/point3.cpp new file mode 100644 index 0000000..70af44a --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/point3.cpp @@ -0,0 +1,65 @@ +// Fig. 9.18: point3.cpp
+// Point3 class member-function definitions.
+#include <iostream>
+
+using std::cout;
+
+#include "point3.h" // Point3 class definition
+
+// default constructor
+Point3::Point3( int xValue, int yValue )
+ : x( xValue ), y( yValue )
+{
+ // empty body
+
+} // end Point3 constructor
+
+// set x in coordinate pair
+void Point3::setX( int xValue )
+{
+ x = xValue; // no need for validation
+
+} // end function setX
+
+// return x from coordinate pair
+int Point3::getX() const
+{
+ return x;
+
+} // end function getX
+
+// set y in coordinate pair
+void Point3::setY( int yValue )
+{
+ y = yValue; // no need for validation
+
+} // end function setY
+
+// return y from coordinate pair
+int Point3::getY() const
+{
+ return y;
+
+} // end function getY
+
+// output Point3 object
+void Point3::print() const
+{
+ cout << '[' << getX() << ", " << getY() << ']';
+
+} // end function print
+
+/**************************************************************************
+ * (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/fig09_22_24/CylinderTest/point3.h b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/point3.h new file mode 100644 index 0000000..028f105 --- /dev/null +++ b/Bachelor/Prog2/Codebeispiele/1_ch09/fig09_22_24/CylinderTest/point3.h @@ -0,0 +1,40 @@ +// Fig. 9.17: point3.h
+// Point3 class definition represents an x-y coordinate pair.
+#ifndef POINT3_H
+#define POINT3_H
+
+class Point3 {
+
+public:
+ Point3( int = 0, int = 0 ); // default constructor
+
+ void setX( int ); // set x in coordinate pair
+ int getX() const; // return x from coordinate pair
+
+ void setY( int ); // set y in coordinate pair
+ int getY() const; // return y from coordinate pair
+
+ void print() const; // output Point3 object
+
+private:
+ int x; // x part of coordinate pair
+ int y; // y part of coordinate pair
+
+}; // end class Point3
+
+#endif
+
+/**************************************************************************
+ * (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. *
+ *************************************************************************/
\ No newline at end of file |
