Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

Can you please help me answer this six questions? 1 )Suppose that the input is 3 4 6 7 2 -1. What is the output

Can you please help me answer this six questions?

1)Suppose that the input is 3 4 6 7 2 -1. What is the output of the following code? (2, 3) int num; int sum; cin >> num; sum = num; while (num != -1) { sum = sum + 2 * num; cin >> num; } cout << "Sum = " << sum << endl;

2)Suppose that the input is 10 -6 12 -5 -4 0. What is the output of the following code? (2, 3) int num; int sum = 0; cin >> num; while (num != 0) { if (num > 0) sum = sum + num; else sum = sum - num; cin >> num; } cout << "Sum = " << sum << endl;

3)Suppose that the input is: 58 23 46 75 98 150 12 176 145 -999 What is the output of the following program? (2, 3) #include using namespace std;

int main() { int num; int count = 0; cin >> num; while (num != -999) { count++; cout << num % count << " "; cin >> num; } cout << endl; return 0; }

4)What type of loop, such as counter-control or sentinel-control, will you use in each of the following situations? (3) a. Sum the following series: 1 + (2 / 1) + (3 / 2) + (4 / 3) + (5 / 4) + ... + (10 / 9) b. Sumthe following numbers, except the last number: 17, 32, 62, 48, 58, -1 c. A file contains an employees salary. Update the employees salary.

5)The following program contains errors that prevent it from compiling and/ or running. Correct all such errors. (4) #include using namespace sdt; const int SECRET = 111.25; int main () { int num1, num2: double x, y; cout >> "Enter two integers: "" cin << num1 << num2; cout >> endl; for (count = 1 count > Secret; ++count) { x = (num1 + num2) / 2.0; y = (num1 - num2) % 2.0; num1 := num1 + num2; num2 := num2 * (count - SECRET - 1) } cout << num1 << " " << num2 << " << x % 5 << " " << (y % 7) << end; return; }

6) To learn how nested for loops work, do a walk-through of the following program segments and determine, in each case, the exact output. (4, 7) a. int i, j; for (i = 1; i <= 5; i++) { for (j = 1; j <= 5; j++) cout << setw(3) << i; cout << endl; } b. int i, j; for (i = 1; i <= 5; i++) { for (j = (i + 1); j <= 5; j++) cout << setw(5) << j; cout << endl; } c. int i, j; for (i = 1; i <= 5; i++) { for (j = 1; j <= i; j++) cout << setw(3) << j; cout << endl; } d. const int M = 10; const int N = 10; int i, j; for (i = 1; i <= M; i++) { for (j = 1; j <= N; j++) cout << setw(3) << M * (i - 1) + j; cout << endl; } e. int i, j; for (i = 1; i <= 9; i++) { for (j = 1; j <= (9 - i); j++) cout << " "; for (j = 1; j <= i; j++) cout << setw(1) << j; for (j = (i - 1); j >= 1; j--) cout << setw(1) << j; cout << endl; }

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_2

Step: 3

blur-text-image_3

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

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students explore these related Databases questions