Question: C++ // Program Loops demonstrates various looping structures. #include #include using namespace std; int main () { ifstream inData; int value; inData.open(Loop.dat); { // while

C++
// Program Loops demonstrates various looping structures.
#include
#include
using namespace std;
int main ()
{
ifstream inData;
int value;
inData.open("Loop.dat");
{ // while loop
int counter = 1;
int sum = 0;
while (counter
{
inData >> value;
sum = sum + value;
counter++;
}
cout
}
{ // do-while loop
int counter = 1;
int sum = 0;
do
{
inData >> value;
sum = sum + value;
counter++;
} while (counter
cout
}
{ // for loop
int sum = 0;
for (int counter = 1; counter
{
inData >> value;
sum = sum + value;
}
cout
}
return 0;
}
Check
10
20
30
40
10
20
30
40
10
20
30
40
----------------------------------------------------------------------------------------------------------
// Program Switches demonstrates the use of the Switch
// statement.
#include
using namespace std;
int main ()
{
char letter;
int first;
int second;
int answer;
cout
cin >> letter;
while (letter != 'Q')
Check
There are lots of symbols in this file: ..;;??
.,.,.,?:::
___________________________________________________________________
// Program CountMarks counts punctuation marks in a file.
#include
#include
using namespace std;
int main ()
{
ifstream inData;
char symbol;
int periodCt = 0;
int commaCt = 0;
int questionCt = 0;
int colonCt = 0;
int semicolonCt = 0;
inData.open("switch.dat");
/* FILL IN */
return 0;
}
 C++ // Program Loops demonstrates various looping structures. #include #include using
namespace std; int main () { ifstream inData; int value; inData.open("Loop.dat"); {
// while loop int counter = 1; int sum = 0; while
(counter { inData >> value; sum = sum + value; counter++; }
cout } { // do-while loop int counter = 1; int sum
Exercise 1: If file loop. dat contains the following values, what is printed? 10 20 30 40 10 20 30 40 10 20 30 40 Exercise 2: Which of these loops are pretest loops? Which are posttest loops? Examine program Switches and answer Exercises 3 and 4

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!