CSCI 150, Spring 2003
Home | | Course Schedule | | Assignments | | Lecture NotesLaboratory 5
Problem 1.
You may use the program skeleton given below:
When you run your program it should print out the following:
Problem 2.
You may use the program skeleton given below:
A sample session for the problem might look like the following:
What To Turn In.
Due at the end of today's class
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.
{ your name and program description goes here. }
program initials;
{your definition for printSpaces procedure goes here }
{your definition for the printLetters procedure goes here
}
procedure writeC;
begin
printSpaces(1);
printLetters(6, 'C');
writeln();
printLetters(1, 'C');
writeln();
printLetters(1, 'C');
writeln();
printLetters(1, 'C');
writeln();
printLetters(1, 'C');
writeln();
printLetters(1, 'C');
writeln();
printSpaces(1);
printLetters(6, 'C');
writeln();
end; { end of procedure, writeC }
begin
writeC;
end. {end of main program initials}
CCCCCC
C
C
C
C
C
CCCCCC
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.
{ your name and program description goes here. }
program gradeAvg;
{your definition for GradeAverage function goes here}
var
numScores: integer;
average: real;
begin
writeln('How many scores do you want to enter?');
readln(numScores);
average := GradeAverage(numScores);
writeln('The average score is ', average:10:2);
end.
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
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.