From c1b6ffe70bd281c6c230fd63fabcaac2aff47514 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Sun, 7 Apr 2024 23:18:32 -0700 Subject: feat: initial commit --- chapter2/demo2.cxx | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 chapter2/demo2.cxx (limited to 'chapter2/demo2.cxx') diff --git a/chapter2/demo2.cxx b/chapter2/demo2.cxx new file mode 100644 index 0000000..89f4bb6 --- /dev/null +++ b/chapter2/demo2.cxx @@ -0,0 +1,31 @@ +// FILE: demo2.cxx +// This small demonstration shows how the revised throttle class is used. +#include // Provides cout and cin +#include // Provides EXIT_SUCCESS +#include "throttle.h" // Provides the throttle class +using namespace std; // Allows all Standard Library items to be used +using main_savitch_2A::throttle; + +const int DEMO_SIZE = 5; // Number of positions in a demonstration throttle + +int main( ) +{ + throttle sample(DEMO_SIZE); // A throttle to use for our demonstration + int user_input; // The position that we set the throttle to + + // Set the sample throttle to a position indicated by the user. + cout << "I have a throttle with " << DEMO_SIZE << " positions." << endl; + cout << "Where would you like to set the throttle?" << endl; + cout << "Please type a number from 0 to " << DEMO_SIZE << ": "; + cin >> user_input; + sample.shift(user_input); + + // Shift the throttle down to zero, printing the flow along the way. + while (sample.is_on( )) + { + cout << "The flow is now " << sample.flow( ) << endl; + sample.shift(-1); + } + cout << "The flow is now off" << endl; + return EXIT_SUCCESS; +} -- cgit v1.2.3