Name: _______Key________

 

Quiz 8 (Week 9) Key

CS-150, Winter '02, Dr. C. S. Tritt

 

  1. What output would the following fragment of C++ source code produce?

 

   double x;

   int y;

   ifstream fin;

   fin.open("stuff.txt");

   while (fin >> x >> y)

      cout << "Result is: " << x*y << '\n';

   fin.close();

 

Assume the file stuff.txt contains:

 

1.3 4

3.4 2

 

Answer            Result is: 5.2

          Result is: 6.8

 

Integer answers –10

 

  1. Write a fragment of C++ code that uses a for loop to display a series of values from type const double value Y to type const double value Z by 0.5. For example if Y were 2.5 and Z were 4.0 the series 2.5  3.0  3.5  4.0 would be displayed.

 

Answer: for (double x = Y; x < Z; x = x + .5) cout << x << " ";

 

Attempting to increment a constant –15.