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 red quiz. The people to your left and right should have a blue 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; write out the two instructions to 1: Open a file called file1.txt and 2: Use getline() to read the first line of the file into the string variable inString.

Question 2.
What is the data type designator for an output file stream? (one-word answer)

Question 3.
Show a use of the right I/O manipulator in an output statement and describe and show what it does.

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

  1. cout << ar[2] + ar[1];
  2. ar[4]++;
  3. ar[3] == ar[1] + ar[2];
  4. ar[3] *= 2;
  5. for sum =7, evaluate sum += ar[4];
  6. cout << ar[1] << '*' << ar[3];
Question 8.
Given the array int aa[] = {3,5,7,9,11,13,15,17,19,21} show what the following statement prints.

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