Saint Louis University |
Computer Science 146
|
Dept. of Math & Computer Science |
Topic: Part II warmup
Due:
11:59pm Monday, February 17
Related Reading: Pages 19-28 of case study
Please make sure you adhere to the policies on academic integrity.
With this assignment, we begin what is described as "part II" in the associated reading. We will be using our own revision of the source code originally provided with the AP case study (in particular, we will be using the standard C++ string and vector classes, rather than the custom "apstring" and "apvector" classes used in the original case study).
If you are working on turing, you may get your own copy of the required source code for part II of the case study by directly copying our version with the following command (note well the period at the period at the end of the command):
cp -Rp /Public/goldwasser/146/partII .This will cause a new folder named partII to appear in your working directory including all files that you need for this assignment. Note: if you have a C++ compiler on your personal computer and wish to work directly on that computer, the necessary files may be downloaded here as partII.zip.
For convenience, our distribution includes a makefile that will allow you to (re)build the project using the command make. This produces an executable named fishsim that can be executed with the command:
./fishsimFor convenience, we have added another feature not discussed in the reading, allowing you to execute your program using a data file with a name other than the default fish.dat. This is done by providing the data file name as a command line argument when executing the program, as in
./fishsim other.datThis way, you can keep several different data files stored in your account, and more easily switch between them when running the program.
You are to go through pages 19-28 of the case study, answering most exercises, and performing all interactive experiments described. Specifically, you are to provide responses to:
Questions 1, 2, and 3 on page 20.
Reply to the "Stop and help" and "Stop and predict" prompts on page 22. For the "stop and predict" question, you do not yet need to create data files for the proposed environemnts. Just describe what environment you would set up to test some of your hypotheses.
Answer the three questions on page 24, labeled as "Stop and predict", "stop and help", and another "stop and help".
Do all questions on page 28, however with the following modifications:
For Question #3 on this page, use a
For Question #6 on this page, rather than prompt the user for the position of each fish, randomly generate initial positions for the desired number of fish. Implement this program in a file named makerandom.cpp.
The easiest way to write to a file in C++ is by using the ofstream class (stands for "output file stream"), which can be loaded by including the <fstream> library. You can pick the file name when declaring an object of that type, as
ofstream fout("sample.txt"); // creates 'fout' variableafter which you may use the fout object with a syntax very similar to what you use for cout, except that the output will go to the file rather than the console.
Note that the makefile will not know about this program. Assuming that you use our existing RandGen class, you can compile this new program with the following command
g++ -o makerandom makerandom.cpp randgen.cpp
Your assignment should be submitted electronically (details on the submission process). This should include your summary prose document, as well as any modified versions of source code. In particular, submit the updated version of fishsim.cpp after modification 3 on page 20, and the new makerandom.cpp application.