Question: C++ // Program Scope demonstrates scope rules and lifetime // classes. #include #include using namespace std; int counter; int sum = 0; int number; ifstream

C++  C++ // Program Scope demonstrates scope rules and lifetime // classes.
// Program Scope demonstrates scope rules and lifetime
// classes.
#include
#include
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
cout
}
SumNumbers(inNums, sum);
cout
cout
return 0;
}
//****************************************************
void SumNumbers(ifstream& inFile, int& answer)
{
static int counter = 1;
while (counter
{
inFile >> number;
answer = answer + number;
counter++;
}
}
355
346
32
-1
-4
-1066
1066
1935
2001
0
Exereise 1: Run program Scope to check your answers. Were your answers cornect? If not explain what you did wrong. Exercise 2: counter, aun number, ns, and Sunluabers Exercise 3 int main return-0 void.Sunlunbera(ifstreami-inFile inti-aawer 210 Chapeer Exercise 4: Block 1 has no local identifiers Block 2 has local identifier sun which hides global identifier eu Block 3 has ee local identifiers: inFile, annet, and couhteE Exercise 5: Aotamatie local variable: sun local to automatic variables. All of the parameters are also Exercise 6: Static local variable: counter Gocal to 31. All loball variables are static

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!