Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++. Control Structures // Program Bugs demonstrates bugs in loops and switches. #include #include using namespace std; int main () { ifstream inData; int value;

C++. Control Structures
// Program Bugs demonstrates bugs in loops and switches.
#include
#include
using namespace std;
int main ()
{
ifstream inData;
int value;
bool fileFound;
inData.open("bug.dat");
if (inData)
fileFound = true;
else
fileFound = false;
switch (fileFound)
{
case false : cout
case true :
// do-while loop
{
int counter = 1;
int sum = 0;
do
{
inData >> value;
sum = sum + value;
} while (counter
cout
}
// for loop
{
int sum = 0;
for (int counter = 1; counter
{
inData >> value;
sum = sum + value;
counter++;
}
cout
}
break;
}
return 0;
}
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
image text in transcribed
image text in transcribed
Exercise 1: Program Bugs is supposed to sum the first ten values on a file and the second tern values on a file. The second ten values are a duplicate of the first ten, so the answers should be the same. The program checks to be sure that the file has been found and halts execution if the flle is not found. Program Buge compiles, but says that the file cannot be found and then the screen freezes. Can you find the problem? Describe it. Exercise 2: Correct the problem and rerun the program. The le cannot be found, but now the program halts correctly. Correct the name of the fle and rerun the program. Exercise 3: What-the screen freezes again? Back to the drawing board. Describe the next error you find. Correct the program and run it again

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Nested Relations And Complex Objects In Databases Lncs 361

Authors: Serge Abiteboul ,Patrick C. Fischer ,Hans-Jorg Schek

1st Edition

3540511717, 978-3540511717

More Books

Students also viewed these Databases questions

Question

10:16 AM Sun Jan 29 Answered: 1 week ago

Answered: 1 week ago

Question

What lessons in intervention design, does this case represent?

Answered: 1 week ago