CprS 157 Schedule
CprS 157 Class 1
CprS 157 Class 3

Syntax and Semantics
Chapter 2 - Class 2


Reading Some Sample Programs

// SquareCube program
// This program computes the square and cube of 27

// PrintName program
// This program prints a name in two different formats

// FormLetter program
// This program prints a form letter for a promotional contest.
// It uses the four parts of a name to build name strings in four
// different formats to be used in personalizing the letter

Program squareCube.cpp illustrates the use of functions in C++. Locate the declarations, definitions and invocations of the functions that it contains. What is the purpose of each? Programs printName.cpp and formLetter.cpp illustrate several operations on strings.

Programming Exercises

  Solve these exercises in class, to your own satisfaction. Demonstrate your solutions to the instructor or to the class TA. There is nothing to hand in from this activity.

Homework For Chapter 2

  And here is the first programming project of the new season: Write a program which outputs a grading form suitable for use with programming projects. How appropriate! This assignment has to do with formatting output, and it should consolidate much of what you know about writing, compiling, and executing C++ programs in the CodeWarrior programming environment. Name your program using our customary file-naming conventions, and drop a copy of it into the CprS 157 Drop Box on the Academic Computing file server. Enjoy!