I am using C++ programming in codeblocks for this assignement. Thank you for the
ID: 3688544 • Letter: I
Question
I am using C++ programming in codeblocks for this assignement. Thank you for the help!
1. You were told that when you are using the for-loop, you should determine the initial value of the loop control variable, the condition and the update depending on the logic of your program. What will happen if: a. You forget to initialize your loop control variable. b. You forget to include your condition. c. You forget to include the update rule.
2. What are the 3 types of loops available in C++? Determine the ones that are pre-test loops as well as post-test loops.
3. Which loop is guaranteed to execute at least one time ?
4. How many times will the following loop run? char x; do { cout << “Enter your input. Correct choices are A, B, and C: “ << endl; cin >> x; switch ( x ) { case ‘A’: …. case ‘B’: …. case ‘C’: …. } } while(x != ‘A’ || x != ‘B’ || x != ‘C’);
5. Create a multiplication table using a nested for-loop that the outer loop goes from 1 to 10 and the inner loop goes from 1 to 10 as well. Inside the inner loop you display the result of the multiplication of the two loop counters. (HINT: ACTIVITY IN CLASS)
6. Write a program that reads several integers from a file called inputFile. The program shows the sum and average of all these integers. Write the program in two different ways: a. Assume that there are exactly 10 data in the files on 10 different rows. Simulate it and make sure the program works. b. Assume that you do not know the number of data in files and all you know is the last number is -999. (HINT: Make a count variable to count the number of integers).
Explanation / Answer
Question: 2 The three types of loops are as given below:
1. While Loop
2. Do-While Loop
3. For Loop
Here While loop as well as For loop is pre-test loop because here condition is checked first the block of statement is executed.
Do-While Loop is post test loop, here block of statement is executed at least one. And condition is checked later.
Question 3.
Do-While Loop is the loop which guaranteed to execute at least one time. Its also the post-test loop.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.