Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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;
}
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
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

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

Advances In Databases And Information Systems 25th European Conference Adbis 2021 Tartu Estonia August 24 26 2021 Proceedings Lncs 12843

Authors: Ladjel Bellatreche ,Marlon Dumas ,Panagiotis Karras ,Raimundas Matulevicius

1st Edition

3030824713, 978-3030824716

More Books

Students also viewed these Databases questions