CS 1500 Class Lab Assignment #11 Read sections 8.5 and 9.1 in "Tapestry" before preparing this lab. Your job is to write a program that: 1. asks the user to specify a text file, 2. writes each string in the file backwards on the screen, on a line by itself. Here is sample run: ============================================================ Script started on Sat May 08 21:31:04 1999 tester@alcyone:(~/CS1500/Lab11) cat writBck.dat Washington [D.C.] is a city of Southern efficiency and Northern charm. -- John F. Kennedy tester@alcyone:(~/CS1500/Lab11) writeBckwds Please enter the filename: writBck.dat notgnihsaW ].C.D[ si a ytic fo nrehtuoS ycneiciffe dna nrehtroN .mrahc -- nhoJ .F ydenneK tester@alcyone:(~/CS1500/Lab11) exit script done on Sat May 08 21:31:32 1999 ============================================================ If you want to see a program that does a job similar to the program you are being asked to write for this lab, look at my_countw2.cc in this directory. In fact, it should be quite simple to take a copy of my_countw2.cc and transform it into a solution to this lab problem. The key ingredient that you need in order to solve this problem is a loop that prints the individual characters of a string backwards. Section 9.1 shows how to reference individual characters in a string. The file spreader.cc in this directory contains code that illustrates the kind of references your program will need to make. How does a program write a string backwards? It's simple to make a for-loop that initializes a loop-control variable to the last character-index in a string and decrements the variable down to zero. Inside the loop, place a statement that writes out the character in the string corresponding to the current value of the loop-control variable. GETTING IT RIGHT: Plan your lab program during the week. You don't have to write it out in totally correct C++ before the lab starts. However, you should at least try to write a specific step-by-step description of what your program will do. Write this plan so that it will be easy to translate into C++ when the time comes. Write some C++ statements in advance if you anticipate having difficulty with them. In lab, compare plans with your partner and execute a good compromise plan. Compile, test, and debug repeatedly until the program is working correctly. Use an editor to make a small text file for testinf the program. If you make an error in how you write the loop code, there is a possibility that your loop will become a "runaway" or "infinite" loop. If your program takes excessive time to finish, you can force it to abort by typing a control-c. SENDING IT IN: When finished make a script using this command: prompt> script lab11.script next cat your input file. In other words, if the input file you made for testing your program is called my_input then do the command prompt> cat my_input That way, the contents of your input file will be seen in the script. When I look at your script, I need to know what is in your input file so that I will be able to tell if your program got correct results. Next run the program. If the output is correct, then you don't need to test any more. After exiting the script, filter the script like this: prompt> cat lab11.script | col -b > temp prompt> mv temp lab11.script Next, check that the script is OK by doing this command: prompt> more lab11.script Press the space bar repeatedly to see more and more of the file, if necessary. If the script is OK, then e-mail it to me with this command: prompt> mail -v -s "lab11 script" john@ishi.csustan.edu < lab11.script PLEASE: The -s "lab11 script" part of the command above is very important to me. Reproduce it exactly. Check that the source file is OK by doing: prompt> more writBckwds.cc Above, you have to replace "writBckwds.cc" with whatever the name of your source file is. If the source file is OK then mail a copy of the source file with a command like this: prompt> mail -v -s "lab11 source" john@ishi.csustan.edu < writBckwds.cc Of course, you need to replace "writBckwds.cc" with the name of your source file if it is different.