summaryrefslogtreecommitdiff
path: root/chapter2/throttle.h
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.h
downloaddscode-c1b6ffe70bd281c6c230fd63fabcaac2aff47514.tar.xz
dscode-c1b6ffe70bd281c6c230fd63fabcaac2aff47514.zip
feat: initial commitHEADmain
Diffstat (limited to 'chapter2/throttle.h')
-rw-r--r--chapter2/throttle.h58
1 files changed, 58 insertions, 0 deletions
diff --git a/chapter2/throttle.h b/chapter2/throttle.h
new file mode 100644
index 0000000..8707b37
--- /dev/null
+++ b/chapter2/throttle.h
@@ -0,0 +1,58 @@
+// FILE: throttle.h
+// CLASS PROVIDED: throttle (part of the namespace main_savitch_chapter2)
+//
+// CONSTRUCTORS for the throttle class:
+// throttle( )
+// Postcondition: The throttle has one position above the shut_off position,
+// and it is currently shut off.
+//
+// throttle(int size)
+// Precondition: size > 0.
+// Postcondition: The throttle has size positions above the shut_off
+// position, and it is currently shut off.
+//
+// MODIFICATION MEMBER FUNCTIONS for the throttle class:
+// void shut_off( )
+// Postcondition: The throttle has been turned off.
+//
+// void shift(int amount)
+// Postcondition: The throttle's position has been moved by
+// amount (but not below 0 or above the top position).
+//
+// CONSTANT MEMBER FUNCTIONS for the throttle class:
+// double flow( ) const
+// Postcondition: The value returned is the current flow as a
+// proportion of the maximum flow.
+//
+// bool is_on( ) const
+// Postcondition: If the throttle's flow is above 0 then
+// the function returns true; otherwise it returns false.
+//
+// VALUE SEMANTICS for the throttle class: (See discussion on page 51.)
+// Assignments and the copy constructor may be used with throttle objects.
+
+#ifndef MAIN_SAVITCH_THROTTLE
+#define MAIN_SAVITCH_THROTTLE
+
+namespace main_savitch_2A
+{
+ class throttle
+ {
+ public:
+ // CONSTRUCTORS
+ throttle( );
+ throttle(int size);
+ // MODIFICATION MEMBER FUNCTIONS
+ void shut_off( ) { position = 0; }
+ void shift(int amount);
+ // CONSTANT MEMBER FUNCTIONS
+ double flow( ) const { return position / double(top_position); }
+ bool is_on( ) const { return (position > 0); }
+ private:
+ int top_position;
+ int position;
+ };
+
+}
+
+#endif