Name:___________________________________                                                   Quiz3

 

 

1.Trace the following program given the data file: data.txt containing:

 

3

4

5

6

0

17

18

 

2. Ttrace it with the data file containing:

14

16

21

23

0

0

3

 

#include<iostream>

#include<fstream>

using namespace std;

int main()

{

      bool correct = true;

      int num1;

      ifstream infile;

      infile.open("data.txt");

      infile>>num1;

      while(correct && num1 < 100)

      {

            cout<<num1<<endl;

            cout<<"continuing...";

            if (!num1) correct = false;

            infile>>num1;

      }

cout<<num1;

return 0;

}

 

3.  Write a function prototype, header and body (definition) for a function named checkrange.  The function accepts three numbers and returns true if the first number is in the range specified by the last two numbers.  For example, if the function receives the numbers 4  6 and 10, it returns false because 4 is not in the range 6 – 10.  However, if the function receives the numbers 7 2 and 11, the function returns true because 7 is between 2 and 11.

Do not assume that the second and third numbers are in any particular order.

 

 

4. Write the C++ statements that will print the following:

 

   

  9---------

   8--------

    7-------

     6------

      5-----

       4----

        3---

         2--

          1-

           BLAST OFF!!!

 

Make sure that you use a loop (preferably nested ones) .

 

 

5.   What is the output of the following program?

#include<iostream>

using namespace std;

const double SCALE = 6.0;

void function1(int, double&);

int main()

{

  int miles=90;

  double inches = 15;

 

  cout<<miles<<"   "<<inches;

  cout<<'\t'<<"are the two numbers\n";

  function1(miles,inches);

  cout<<inches<<"  "<<inches<<endl;

  function1(10,inches);

  cout<<miles<<"  "<<inches<<endl;

}

void function1(int x,double& y)

{

      x++;

    cout<<"Scaling by "<<SCALE<<endl;

      y = y * SCALE;

}