The second tutorial is now complete, as of 12:07 AM Sun 3/14/2004. The promised two more example programs have been added.
CS 111 Assignment 4
Warning: This assignment must be handed in to your lab instructor on or before its on-time due date and will NOT be accepted late, at all, because it will be gone over in the following recitation. It is a paper-only assignment, not requiring you to compile or run your programs (though you are encouraged to compile and run them if you have enough time). For information about the due dates and the different kinds of homework assignments, please see Homework policies and due dates.
Below are tutorials and example programs. Please make printouts of these and bring them with you to both lecture and recitation. However, please do NOT print them out in an on-campus lab. (On-campus printers are to be used only for your homework, i.e. for files YOU wrote.) If you do not have a computer at home, with a printer, ask a friend or classmate to print out copies of the following files for you.
So that you can play with the example programs, create a directory named hw04 inside your homework directory on forbin. Change your present working directory to hw04 and then copy into it the example files for this homework assignment, by typing, at the "forbin>" prompt:
cp ~nixon/cs111/hw04/* .
Please do NOT copy these files into your home directory, to avoid cluttering your home directory. If you inadvertantly copied them into your home directory, move them out using the mv command. Be very careful about deleting anything in your home directory, and especially to avoid inadvertantly deleting your hidden files (.login, .cshrc, .profile, etc.).
Play with the example programs when reading the tutorials for this assignment. When you are finished reading the tutorial, it is recommended that you then delete the example files, or at least most of them, in order to save disk space.
Here are Answers to most of the practice problems.
Write another version of this same program which can process all the numbers in a text file without needing the first number to indicate the number of numbers in the rest of the file. Use a while loop. Create several input text files to test it.
Write two versions of this program, one of which takes the name of the input text file as a command-line argument, and the other of which prompts the user to enter the input filename.
Later, some information will be posted here on how to right-justify a floating-point number and force it to be displayed to two decimal places, You are urged to begin work on other aspects of this problem earlier and return to it later to fix the appearance of the output.
'e' appeared at these positions: 1 5 6
Note that the position of the first character is to be denoted "1", which is off by one from its position in the actual array.
'e' appeared at 2 other positions besides the end.
The detection of letters should be case-insensitive, e.g. both 'e' and 'E' should count as ths same character.
801749724 3901.63 Anwar Abdul 648759757 26876.49 Brown Joel 185029754 596.13 Carducci Giovani 906314873 2150.84 Martinez Maria 857905495 684501.37 Smith Jane Lee 742978169 8495.10 Warren Jerry 108358763 39105.28 Zhu Weng Heng
Write program atm.cpp which does the following:
Also, if and whenever the program needs to quit for any reason (including the user entering 'Q' at the menu prompt, or the user finishing a 'D' or 'W' transaction, or an error such as a non-numeric entry for the account number), the program should save the contents of the arrays to bankNew.txt before quitting. (The only exceptions is that if there was an error reading the input file, or if the file bankNew.txt cannot be created, then in those cases the program should not try to save the data to that file, because it can't.)
Your program should work with both of the following input data files:
Please note that this will be the longest program you've written so far. Do NOT try to write the entire program all at once and then complie and run it. If you do that, the program will be a nightmare to debug. Instead, write it piecemeal.
As a first step, write a program which just (1) reads the data from the input file into the three arrays and then (2) saves the contents of the three arrays to bankNew.txt. Make sure this runs properly before you do anything else.
Even this simpler program should be written piecemeal, several lines at a time, compiling after every several lines. So that these intermediat programs will be more likely to compile, pay attention to block structure. Whenever you type an opening curly brace, immediately type the corresponding closing curly brace, then type the lines that go in between.
In the output file, you will need to right-justify a column of floatin-point numbers (representing money amounts) and force them to be printed to two decimal places. Below is information on how to do this:
outputstream << setw(width) << setprecision(2)
<< setiosflags(ios::fixed)
<< variable_name << endl;
where outputstream is either cout or an ofstream object, and variable_name is a floating-point variable.
For an example, see the Answer to practice problem 3.
When you have finished writing a program which just reads the data from a file and then just writes it to bankNew.txt and you have verified that it runs correctly, you should then try to figure out a reasonable way to break down the remainder of the assignment into parts, so that you can write, compile, and run the program one new part at a time.
Note: The script file is not available yet. It will be available later.
Run the script file hw04.sh to make sure your programs work correctly and that they have the correct filenames. The script file hw04.sh can be copied into your present working directory as follows:
cp ~nixon/cs111/hw04/hw04.sh .
Then, create a tar file as you did for earlier assignments. The tar file must have a filename in exactly the following format:
lastname_accountname_4.tar
replacing lastname with your actual last name (spelled as the Registrar's Office spells it, as on your tuition bill or bursar's receipt) in lower-case letters only (not capital letters), and replacing accountname with your actual forbin account name. The "3" indicates Assignment 3.
The tar file must contain the following source code file, and only this file:
The tar file must be submitted to your instructor at the appropriate E-mail address, as listed on the instructor E-mail address page.
To recitation/lab on the due date, bring a stapled-together printout of the following source code file, which you wrote:
Back to: