CMIS 240 Week 1 Read Chapter 1 this week. It's an easy chapter because it's mostly "cultural" material about software engineering. It's got the phases of the software lifecycle: specification, design, testing. It's what's done for large, real software projects in the real world. There's not much hard technical material in this chapter. While all the material is useful, some is more useful than others, especially for this course and the level that you're at and the programs you'll write for this class. So concentrate on the following sections or sub-sections: Ideaware Goals of Quality Software Program Design Compile-time Errors Run-time Errors Stream input and output Preconditions and postconditions Fig. 1-4 Summary Exercise 17 ------------------------------------------------------------------------- Here's a quick review of file I/O. The book talks about stream failure on page 22. fileIO.cpp in Chapter1/ is a typical example, reading from a file of ints. Compile the program, use the created data file as the input file. Note that a data file can be any name (e.g. a DOS-like "extension" is meaningless to C++). ----------------- fileIO.txt is a test file for the program. Note that the format is deliberately wacky to show that whitespace is irrelevant; it's skipped over. The sum should be 382 ----------- 23 45 1 67 56 23 45 89 33 ----------- ------------------------------------------------------------------------- enum.cpp is a small program that demos enum. enum is not terribly important nor difficult. If it weren't used by the authors we could ignore it. If you're unfamiliar with it, experiment with enum.cpp in Chapter1/ and read the few pages about it in the 140 book. ------------------------------------------------------------------------- args.cpp is a small program that demos command line arguments. It's quite useful to be able to run a program and pass it values from the command line. The values can supplement or replace interactive input. rand.cpp illustrates random numbers. Notice it can run off its command line arguments, or go interactive if there are no command line arguments. With command history (available in Unix shells and NTs cmd, and in W9x/DOS by putting doskey in your autoexec.bat) up arrow key recalls previous commands which can be edited and re-run. Much faster than re-running programs from within the IDE. But wait, there's more. The output of a program can be redirected to a file with the > operator. Say you've compiled the rand.cpp to rand.exe (on Unix the .exe is redundant). Execute the rand command. Here I'm using $ as the prompt, yours may differ. $ rand 10 100 61 9 17 64 16 50 50 81 21 91 $ rand 10 100 >rands_10_100 here, redirect the output to file rands_10_100 $ You've created a file of random numbers. --------------------------------------------- Homework #1 Due: 9 FEb Modify and complete the fraction program of Chapter 1. You can start with the EX4.CPP that's in Chapter1/. Modify it so it looks like the program on page 41. Use the ComType enum. Define the GetCommand, GetValues, and Operate functions. You'll also need Add, Sub, Multiply, and Divide functions, and GCF and Simplify functions (which I've provided, see below). To give you some review and practice with arrays, declare in main an array of FractionType to store the computed results. Have a "current size" variable for the array. Pass the element at the current size of the array to the Operate function as its reference argument. At the end of the program output all the results in the array by calling the modified PrintResults function and passing to it the array of FractionType and its current size. (Remove the call to PrintResult that is in the loop and place it after the loop. Replace the call in the loop to a cout statement that displays the result.) This is a 140-level program. It's a warm-up and review for the 240 level material which starts in Chapter 2. The author seems to have a fondness for not using the return value of a function. The GetCommand and Operate functions could be done a little differently than the author, they could return the command and result, respectively, as the return value of the function, instead of as a reference argument. You can do either way. GetCommand must ensure that a valid operation is specified (i.e. it must have an error checking loop). Also, don't let the user input 0 for a denominator. Computing the greatest common factor of two fractions isn't easy, so I've put that function in the class web site, in Chapter1/ directory. I've also written an Add function. Use it as a model for the other operation functions. There's also a simplify function. I've also placed executables for DOS-Windows and Linux as fraction_dos.exe and fraction_linux.exe. Download the appropriate one for your system and run it. Post any errors you find in it to the class BBS to embarrass your instructor. Post your one source code file in the Assignment area of Tycho as an attachment to avoid tycho's reformatting of your source code. Never post executable files or .o or .obj kind of binary files.