CSCI 150, Spring 2003

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

Review sheet for 1st midterm

Topics for Exam1:
This sheet is intended to help you prepare for the first midterm exam in this course. The exam will primarily focus on chapters 1-3 of the text book and all the lectures and labs through today, Monday 2/17/03. You should study your class notes, handouts, homeworks and labs. Solutions to the homeworks and labs can be found at the course website: http://mathcs.holycross.edu/~csci150. The readings include the following: Ch 1, pp 1 - 33, Ch 2, pp 41 -71, Ch 3, pp 81 - 115.

The following topics have been covered in the first part of the course. Each of the following topics may appear on the exam.

1.  Introduction to Computer Science
	Imperative vs. Declarative knowledge
	Definition of an Algorithm
	Decision Trees
2.  Pascal programs
	General form of Pascal program
	Input and Output (readln(), read(), writeln(), write())
	Variables
		Variable types (integer, string, real, char)
		Rules for naming variables
		Assigning values to variables
4.  Programming Decision Trees
	General form of conditional statement
	Using if ... then....else if ....then ....else
	Booleans
	Logical Expressions
		Relational operators (<, >, etc.)
		Logical operators (and, or, not)
5.  Text manipulation
	Concatenating strings
	Finding the length of a string
	Copying a substring from a string
6.  Arithmetic expressions
	Precedence rules for +, - , * , /
7.  Loops
	while loops
	count-controlled loops
	for loops
8.  Arrays
	Declaring an array
	Assigning values to an array
	Using for loops with arrays

Practice Problems
The following problems are intended to help you study for the exam.

1)Given these boolean variables:
x = true, y = false, z = true

What is the value (true/false) of each of the following?

i)  x and (y or z)


ii) (not x) or  (not(y and z))


iii) y or (x and not z)


2)Write a program that does the following:
Prompt the user to input a number.
Input the number from the keyboard
If the number is less than 100, write:
	XX is a low number.
where XX refers to the number inputted by the user.
Otherwise, write:
	XX is a high number.




3)  Compute the value of the following expressions:
a)  6 / 3 * 2



b) (17 - 11) / 3 + 3



c) Add parentheses to part b so that the addition is performed
before the division.



d) What is the value of c) ?



4) a) What is the value of sum after the execution of the following code?

	sum := 0;
	for counter := 1 to 4 do
	begin
		sum := sum + 2 * counter;
	end;

5) What is the output of the following code fragment (mySentence and partial are both strings)?

	mySentence := 'It was a dark and stormy night';
	partial := copy(mySentence, 8, 6);
	writeln(partial);


6) What is wrong with the following fragments of Pascal?


7)  Consider the following while loop:
	sum := 0;
	count := 5;
	while count <= 10 do
	begin
		sum := sum + count;
		count := count + 1;
	end;

a) Fill in the following table for the values of count and sum each time through the loop (there may be more rows than you need in the table):

b)Write a for loop that does the equivalent of the above loop.

 

 

  8. Consider the following pascal code:

     program z3;
     var
        sum,i: integer;
     begin
        sum := 0;
        for i :=1 to 4 do
           begin
              sum := sum + i;
           end;
        writeln(sum);
     end.
What is value of sum printed on the screen?

 

 

  9. Fill in/write the necessary code for the following decision tree.

program catCheck (input, output);
var								
	answer : string; 				
begin						

	{Your code goes here}





end.  {end of main program catCheck}

10. Fill in the necessary code to fill in the depositList array with deposit amounts entered by the user. You should keep track of the sum of all the deposits made, so that the print statement at the end of the program makes sense. You can assume there are exactly 1000 deposits made.

program deposit;
type
	realArray : array [1..1000] of real;
var
	loop   : integer;
	sum    : real;
	depositList : realArray

begin
	sum := 0;














	writeln ('The sum of the deposits: $', sum:5:2);
end;