
Chapter 9: Prelab Assignment
Scope, Lifetime, and More on Functions | 207
Name __________________________________________ Date _______________________
Section _________________________________________
Read program Scope carefully and then complete Exercises 1 through 6.
// Program Scope demonstrates scope rules and lifetime
// classes.
#include <iostream>
#include <fstream>
using namespace std;
int counter;
int sum = 0;
int number;
ifstream inNums;
void SumNumbers(ifstream& inFile, int& answer);
// Sums the numbers on inFile.
int main ()
{
inNums.open("numeric.dat");
{
int sum = 0;
SumNumbers(inNums, sum);
cout << "Output from first call to SumNumbers" << endl; ...