diff options
| author | Fuwn <[email protected]> | 2024-04-07 23:18:32 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-04-07 23:18:32 -0700 |
| commit | c1b6ffe70bd281c6c230fd63fabcaac2aff47514 (patch) | |
| tree | e8af3b1782a7cd0754590ed618fddc1bdb9b7385 /chapter14/blob.cxx | |
| download | dscode-main.tar.xz dscode-main.zip | |
Diffstat (limited to 'chapter14/blob.cxx')
| -rw-r--r-- | chapter14/blob.cxx | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/chapter14/blob.cxx b/chapter14/blob.cxx new file mode 100644 index 0000000..e2c09a3 --- /dev/null +++ b/chapter14/blob.cxx @@ -0,0 +1,32 @@ +// FILE: blob.cxx
+// This small demonstration shows how the organism class is used.
+#include <cstdlib> // Provides EXIT_SUCCESS
+#include <iostream> // Provides cout and cin
+#include "organism.h" // Provides the organism class
+
+int main( )
+{
+ main_savitch_14::organism blob(20.0, 100000.0);
+ int week;
+
+ // Untroubled by conscience or intellect, the Blob grows for three weeks.
+ for (week = 1; week <= 3; ++week)
+ {
+ blob.simulate_week( );
+ cout << "Week " << week << ":" << " the Blob is ";
+ cout << blob.get_size( ) << " ounces." << endl;
+ }
+
+ // Steve McQueen reverses the growth rate to -80000 ounces per week.
+ blob.assign_rate(-80000.0);
+ while (blob.is_alive( ))
+ {
+ blob.simulate_week( );
+ cout << "Week " << week << ":" << " the Blob is ";
+ cout << blob.get_size( ) << " ounces." << endl;
+ ++week;
+ }
+
+ cout << "The Blob (or its son) shall return." << endl;
+ return EXIT_SUCCESS;
+}
|