CS 46A Lab 3, Editing

Problems

Name:
CS46A Instructor:

1. Open the Lab3 workspace. To do this, select "Open Workspace" from the File menu, then search for Lab3.dsw. Open the advice.txt file in the Text files project. It contains an odd little piece of advice. Create a new source file called advice.cpp, and paste the contents of advice.txt into this file. What do you observe? Can you explain?

 

 

 

2. Open the peg1.txt file in the Text files project. Create two more text files called peg2 and peg3. Hide the output and workspace windows, then select "Tile Vertically" from the Window menu.

Peg1.txt contains a four-layer pyramid. Each layer is made out of letters. The A layer is made out of "A"s, the B layer is made out of "B"s, etc. Your goal is to use cut and paste to move the pyramid, one layer at a time, into the file called peg2.txt. You may use peg3.txt as a temporary store for layers, but, wherever the layers are deposited, they must always be in alphabetical order. In other words, peg3.txt may contain the A and D layers, but the A layer must be on top of the D layer.

Obtain a printout of peg2.txt showing the pyramid.

Briefly describe the algorithm you used to transfer the pyramid.

 

 

 

3. Select Waldo from the "Set Active Project" submenu of the Project menu. Build and run the Waldo project. To do this, select "Execute Waldo.exe" from the Build menu. A dialog box may warn you "This file does not exist. Do you want to build it?" Push the Yes button. The program isn't very stunning, visually. A DOS console window pops up with the text: "Press any key to continue." Press any key. Waldo.exe generates a large text file called waldo.txt. Open this file in MSDS. How many occurrences of the name "Waldo" can you find in this file? (Ignore case.)

# of Waldos =

How many names can you find just like Waldo's except the last character can be anything. (For example: "Walda". Again, ignore case.) Hint: use the regular expression option on the Replace dialog box. How are regular expressions different from literal strings?

# of Wald*s =

Insert newline characters before and after each occurrence of "Waldo". Replace each newline character, except for those you just inserted, with a pair of newline characters. Obtain and submit a printout of this file.