COM 1100 Foundations of Computer Science

Quiz 5 -- Tuesday, November 21st

Fall 2000 -- Professor Futrelle
College of Computer Science, Northeastern U., Boston, MA
This is a blue quiz. The people to your left and right should have a red quiz.

 

Print your name here____________________________________________________ ID#___________________

Please write your answers on the this sheet, and PRINT your name and ID number above. This quiz covers file I/O operations from Secs. 8.3 through 8.5, as well as the basics of arrays, from Secs. 9.1 and 9.2

Question 1.
Assuming the declaration ifstream inFile; rrite the conditional expression for a while loop that can simultaneously get a character into the character variable ch using get() and also check for end-of-file condition for inFile. HINT: The syntax of the open() and get() functions is similar.

Question 2.
Show how to use inFile (defined in Question 1) with the << or >> operator to read an integer into the integer variable n. (Choose the correct operator.)

Question 3.
What value does the function fail() return if a stream open fails?

Question 7.
What do the following statements do? For each part of the question below, a-f, start fresh with the array int ar[] = {1, 3, 8, 2, 17}.

  1. cout << ar[3] + ar[0];
  2. ar[2]++;
  3. ar[1] == ar[0] + ar[3];
  4. ar[2] /= 2;
  5. for sum = 7, evaluate sum += ar[4];
  6. cout << ar[1] << '*' << ar[3];
Question 8.
Given the array int ab[] = {10, 9, 8, 7, 6, 4, 3, 2, 1} show what the following statement prints.

  for(int i = 0; i < ab[2]; i += 2)
     cout << ab[i] << ' ';