summaryrefslogtreecommitdiff
path: root/chapter2/throttle.cxx
diff options
context:
space:
mode:
authorFuwn <[email protected]>2024-04-07 23:18:32 -0700
committerFuwn <[email protected]>2024-04-07 23:18:32 -0700
commitc1b6ffe70bd281c6c230fd63fabcaac2aff47514 (patch)
treee8af3b1782a7cd0754590ed618fddc1bdb9b7385 /chapter2/throttle.cxx
downloaddscode-main.tar.xz
dscode-main.zip
feat: initial commitHEADmain
Diffstat (limited to 'chapter2/throttle.cxx')
-rw-r--r--chapter2/throttle.cxx35
1 files changed, 35 insertions, 0 deletions
diff --git a/chapter2/throttle.cxx b/chapter2/throttle.cxx
new file mode 100644
index 0000000..18b0b6a
--- /dev/null
+++ b/chapter2/throttle.cxx
@@ -0,0 +1,35 @@
+// FILE: throttle.cxx
+// CLASS IMPLEMENTED: throttle (See throttle.h for documentation.)
+
+#include <cassert> // Provides assert
+#include "throttle.h" // Provides the throttle class definition
+using namespace std; // Allows all Standard Library items to be used
+
+namespace main_savitch_2A
+{
+
+ throttle::throttle( )
+ { // A simple on-off throttle
+ top_position = 1;
+ position = 0;
+ }
+
+ throttle::throttle(int size)
+ // Library facilities used: cassert
+ {
+ assert(size > 0);
+ top_position = size;
+ position = 0;
+ }
+
+ void throttle::shift(int amount)
+ {
+ position += amount;
+
+ if (position < 0)
+ position = 0;
+ else if (position > top_position)
+ position = top_position;
+ }
+
+}