Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

D7 Discussion (Covers Chapter 5) Wnite A0 300 Wrd -to explain Code writer e t t

ID: 3600915 • Letter: D

Question

D7 Discussion (Covers Chapter 5) Wnite A0 300 Wrd -to explain Code writer e t t ) Discussion Topics: . Provide your own short C++ code example that uses a while loop. Be sure to test and explain your code. Provide your own short C++ code example that uses a do-while loop. Be sure to test and explain your code. Provide your own short C++ code example that uses a for loop. Be sure to test and explain your code. Provide your own short C++ code example that uses the concepts of files of your choice.

Explanation / Answer

For Loop

A for loop is a loop that needs to execute a specific number of times specified the programmer.

The output is

In the above code a variable a is initialized to value 10 and then looped through a is incremented by 1 until 15 is reached and the loop exits as the condition fails and prints the outputs till a=14

do while loop

Output

In the above code a variable a is initialized to value 10 and then looped through and a is incremented by 1 until a=15 is reached and the loop exits as the condition fails and prints the outputs till a=14.When the condition fails the loop exits. The difference is that do while loop is executed atleast once even if the condition is false.

while loops

OUTPUT

Here in above code as we can see i is initialized to 10 and then incremented each time the loop runs and prints the value of i until i=17 and the condition fails and the loop exits.

Files

The above code declares an array of char named data and then we open a file in write mode by using ofstream . Then we can write to file in the same manner as we write to the screen using cout.Then the files gets a string from the user and output it to the file.

Please give a thumbs up if any doubt leave a comment.