Question
c++ // Program Scope demonstrates scope rules and lifetime // classes. #include #include using namespace std; int counter; int sum = 0; int number; ifstream
c++
// 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++;
}
}
Data
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 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 staticStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started