CSE 15: Introduction to Computer Science
Assignment #5 (Software Engineering and Control Structures)

In The Universal Computer, do exercises 4.15, 4.17, 4.18, 4.20, 4.32, 4.33, 4.39, 4.42, 4.49, and 4.50.
In A Multimedia Introduction to C++, do exercises 13.2, 13.3, 13.8(b,c,f,h),13.10,13.16(b,d,f),13.20(a,b),13.23 (see Y:\lib\gcc\lookout\ch13ifloop\grades.cc on the LAN), 13.28, 13.37, 13.38, 13.43, 13.52, and 13.56.
The exercises are also given below.

Also, use a debugger to diagnose and correct the bugs in loopbugs.cc. The umcpp multimedia asks you to debug this program at the end of the section on "loop bugs" (you can use the Find button to go to this section). Add comments to the code explaining the nature of each bug you find and how you correct it and hand in your corrected version with comments. You may use debugger: the gdb debugger that comes with LOOKOUT (press F8 to start it up) or the debugger that comes with Visual C++, or Borland C++ 5.02, all available on campus. Add a comment at the top of the program mentioning which debugger you used.

Finally, you will start working on your term project, The Game of Life. It's described in The Universal Computer in exercise 2.55 on page 50. You can try the game on the web at http://www.tech.org/~stuart/life/life.html. Note that there is a link to the rules for the game. Essentially there are three rules:
1) A living cell dies of loneliness if there are too few (0 or 1) living neighbors or too many (4 or more) living neighbors.
2) A living cell survives if there are two or three living neighbors.
3) A dead cell comes to life (is born) if there are three living neighbors.
For your term project, the input and output will be text based, i.e., using different character to distinguish empty and live cells. (A challenging possible final extra credit project will be to reimplement the game in Flash with a graphical look.) The user can select from a few different initial configurations (as in the aforementioned web site, but not necessarily the same ones) or let the program randomly initialize the configuration. The game will let the user see one generation at a time, skip n generations, or quit a simulation.

For this assignment, you will do your analysis for the project, by writing up a requirements specification and use cases.

You will also implement a program based on the core logic of the game: Given nine variables representing a 3x3 grid of nine cells (a middle cell and eight surrounding cells), determine and display a message indicating whether the middle cell will live or die, or whether a dead cell will comes to life, in the next generation. Develop a test plan that checks for several different scenarios (hint: a use case should set up your test plan), then write a while loop that changes your nine variables and runs each of your scenarios, displaying different output based on different variable values. Make sure this program is well-commented and explains its output clearly. (In subsequent assignments, you will develop a UML design document, then pseudocode for this problem, implement parts of the program, and finally implement the whole program in C++). Notes: you are not implementing the complete game yet, just the core logic. For now, the nine cells are nine variables, not an array (we'll learn about arrays later this semester). The loop runs just one generation, in different ways--assign different values to the nine variables at the beginning of each iteration of the loop testing the logic.

For this project, you must work in pairs. You may continue working with the partner from your previous assignment, or you may find another partner, but your partner should have the same access to the CIMEL collaboration tools (if you didn't have access for the last assignment, you will have it for this one). If you have any difficulty finding a partner, or have concerns about how well your partner is collobarating please let the TA, Tian Lin (til2@lehigh.edu), know as soon as possible. Work on the the analysis and program in pairs and put the name of both partners in your submission--one partner may submit the work and you will both get the same grade for the assignment. Note: you may also work on the loopbugs.cc program in pairs (if so, hand in one program with the names of both partners), and you may discuss other exercises with your partner, but you must work out and submit your own work for all other exercises.

Extra credit: 4.43, 13.58.

Due: Monday, 10/20, anytime before midnight.  

Prof. Blank

Exercise 4.15: Why does operation getCode in class ByteCodes return a String? Hint: what are the elements of a String and what do these elements represent in Knobby’s World?

Exercise 4.17: As you learned in the previous chapter, a scanner or tokenizer identifies the tokens of a program. How would you add a scanner to the above class diagram?

Exercise 4.18: What kind of relationship does the diagram show between Editor and UI?

Exercise 4.20: Knobby can also turn left. Where should this capability go in the class diagram? What attribute would it affect?

Exercise 4.32: How can a decomposition approach help you make better use of a debugger? Hint: where should you set a breakpoint?

Exercise 4.33: In terms of the waterfall model, when should developers plan testing? Why?

Exercise 4.42: Why might pair programming be a good idea for students? When and why might it not work well? What commitments would students need to make to make pair programming work?

Exercise 4.49 (social/ethical): Suppose Real World Software, thinking they could knock off this ATM problem in a short time, uses a hacking approach to implement the ATM system for First Virtual Bank. When RWS delivers the software, it does not quite perform according to FVB’s requirements; moreover, it is poorly documented and its structure hard to understand. RWS points out that FVB’s requirements did not specifically mention anything about design or implementation documentation; they simply provided a short description and agreed on a bottom-line for delivery. What do you think is the responsibility of the software supplier and that of the client in this case?

Exercise 4.50 (social/ethical): A student is having difficulty getting a program to work, so he or she goes to the instructor for help. The instructor sees that there are no comments in the code indicating what the student had in mind, so the instructor refuses to help debug the program until the student rewrites it with comments including preliminary analysis and pseudocode design. The student points out, desperately, that the assignment is due the next morning. Do you think the instructor is justified in not giving immediate help? Why or why not?

Exercise 13.2: What is the behavior of the following (poorly indented) program fragment? Explain your answer by discussing output produced by two or three sample sets of input values.
int j,k;
cin >> j >> k;
if (j == k)
if (j == 1)
cout << "alpha";
else
cout << "beta";
cout << "omega";

Exercise 13.3: Reformat the code fragment in the previous exercise to correspond more closely to the actual output.

Exercise 13.8: What is the truth value of the following C++ expressions? Explain why.
b) 3 == '3' d) 3 * 7 f) sqrt(3) h) 2 != floor(2.3)

Exercise 13.10: Construct a table for the exclusive sense of or (“xor”).

Exercise 13.16: Write C++ boolean expressions to express the following conditions:
b) both j and k are positive
d) -3 < z < 3
f) ch is an uppercase letter

Exercise 13.20: Given x=2, y=3, z=5, what are the values of the following boolean expressions?
a)!x || y
b)!x && y || z

Exercise 13.23: The course grade program in figure 13.8 does not perform error checking. Rewrite the program to include error checking on user input. If a user inputs an invalid number, print an error message to the screen. Hint: What changes in the structure of the program will this require?

Exercise 13.28: Occasionally, an infinite loop is just what one wants. Can you think of a few examples of programs that you use that run an infinite loop? Hint: you interact with one soon after you turn on a computer.

Exercise 13.37: What logical error would occur if you changed the test in the above code fragment from < (less than) to == (equality)?

Exercise 13.38: What logical error would occur if you forgot to increment the counter above?

Exercise 13.52: Is a sentinel value a variant or an invariant? What’s a good way to represent a sentinel in C++?

Exercise 13.56: Write a program that counts the number of lines in a text file. (Use class InFile in the Lookout class library, after studying Y:\lib\gcc\lookout\ch13ifloop\FileTest.cc. on the LAN.)