CprS 157 Schedule
CprS 157 Class 9
CprS 157 Class 11

Functions and Scope
Chapter 8 - Class 10

Reading Some Sample Programs

// ConvertDates program
// This program reads dates in American form from an input file and
// writes them to an output file in American, British, and ISO form.
// No data validation is done on the input file

// Starship program
// This program computes the total weight and center of gravity
// of a Beechcraft Starship-1, given the number of crew members
// and passengers, weight of closet and baggage compartment cargo,
// and gallons of fuel loaded. It assumes that each person
// weighs 170 pounds, and that the fuel weighs 6.7 pounds per
// gallon. Thus, the output is approximate and should be hand-
// checked if the Starship is loaded near its limits

// FuelMomentDriver program
// This program provides an environment for testing the
// FuelMoment function in isolation from the Starship program

Program starship illustrates how to use value-returning functions to help structure and modularize a complex calculation. It will help the pilot of a Beechcraft Starship to properly configure her aircraft by calculating the center of gravity of the airplane, when given input information about the crew, passengers, cargo and fuel on board.

Programming Exercises

  Solve these exercises in class, to your own satisfaction. If called for, create the appropriate data files and test your program on your data. Demonstrate your solutions to the instructor or to the class TA. There is nothing to hand in from this activity.

Homework For Chapter 8

  How many days until your birthday? ... until your graduation? You are soon going to know all of that! Today's programming project involves writing a program which calculates how many days elapse between any two dates which are input to the program. Pay special attention to the use of value-returning functions in structuring your computation. You will have to think carefully about datatypes and about how you might want the dates to be input to your program. Strive for clarity and elegance in your code and program interface. Cheers!