CprS 157 Schedule
CprS 157 Class 3
CprS 157 Class 5

Input, File I/O, Software Design
Chapter 4 - Class 4

Reading Some Sample Programs

// Canvas program
// This program computes the dimensions and costs of materials
// to build a painting canvas of given dimensions. The user is
// asked to enter the length and width of the painting and the
// costs of the wood (per inch) and canvas (per square foot)

// Walk program
// This program computes the mileage (rounded to tenths of a mile)
// for each of four distances between points in a city, given
// the measurements on a map with a scale whose value is also
// input. This version of the program takes its input from a data file.

Program canvas.cpp demonstrates how to request input data from the user. It prompts the user for the dimensions of a painting to be framed and the unit costs of the canvas and framing materials to be used, and then computes the total cost of the painting.

 Program walk2.cpp demonstrates how to take input data from an input file and write output data to an output file. Note that the data file MUST be in the same folder as the active project file, or the system will not find it. There are other ways to arrange things, but this recommended scheme of always putting our data files into the active project folder will help to simplify these routine file operations. The output file will be written into the project folder as well. BEWARE: Any pre-existing file in that folder with the same name as the output file will be silently and quite thoroughly overwritten.

Programming Exercises

  Solve these exercises in class, to your own satisfaction. Demonstrate your solutions to the instructor or to the class TA. We can save a few particularly instructive examples in the folder "Student Work" on the Academic Computing file server for future reference.

Homework For Chapter 4

  Write clear and correct solutions to these programming problems, and drop an electronic copy of your work into the CS157 drop box before the beginning of our next class. Personalize the results of your efforts by using our standard file-naming conventions.