CSCI 150, Spring 2003

Home | | Course Schedule | | Assignments | | Lecture Notes

Laboratory 5
Due at the end of today's class

Problem 1.
Write a Pascal program, named initials.pas, that prints out the initial C. You should use two procedures. The first procedure, printSpaces(), should have one integer parameter that indicates the number of spaces to be printed. It should have one local variable to use as a counter in a for loop. This procedure should use a for loop to print the number of spaces specified by the parameter (use the Pascal procedure Write( ) to print spaces in a line). The second procedure, printLetters(), should take 2 parameters. One should be an integer parameter to indicate the number of characters printed and the second should be a character which is the letter to be printed. This procedure should print out the specified number of the given character. It will also need a local integer variable to be used as a counter in a for loop. A procedure, writeC() has been written for you. When called, this procedure calls printSpaces() and printLetters() to make a C.

You may use the program skeleton given below:

When you run your program it should print out the following:

 CCCCCC
C
C
C
C
C
 CCCCCC

Problem 2.
Write a program named gradeAvg.pas, to compute the average grade for a set of test scores. The program should prompt the user for the number of test scores to enter and read in that number. It should then call a function, GradeAverage(), which will return a real value. The GradeAverage() function will use a for loop to prompt the user to enter the specified number of test scores. As each score is entered, that score should be added to a running sum of the scores. After all the scores are entered (and their sum is complete) the function should return the average of the scores (the sum divided by the number of scores). GradeAverage() should have one integer parameter (the number of scores to be read in and averaged) and should return a real value (the average). It should have 3 local variables: an integer variable to serve as a counter for the for loop, a real variable to read in each score, and a second real variable to keep track of the sum of scores.

You may use the program skeleton given below:

A sample session for the problem might look like the following:

How many scores do you want to enter?
3
Enter test score: 90
Enter test score: 91
Enter test score: 91
The average score is   90.67

What To Turn In.
A printed listing of the programs for each problem. Be sure that your name is in the program prologue's comment section of each program. Don't forget to save a copy of each of your programs on your P:\ drive.