Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Problem 1

State whether the following are true or false. If the answer is false , explain why. a. The default case is required in the switch selection statement. b. The break statement is required in the default case of a switch selection statement to exit the switch properly. c. The expression \((x>y 88 ay\) is true or the expression \(a

Problem 3

Find the error(s) in each of the following code segments and explain how to correct it (them). a. \(x=1 ;\) while \((x<10)\) \(x++;\) \\} b. for \((y=.1 ; y !=1 . \theta ; y+=.1)\) cout \(<

Problem 4

Find the error(s) in each of the following: a. For \((x=100, x>=1, x++)\) cout \(<1 ; x+2) \\ \text { cout }<

Problem 5

Write a program that uses a for statement to sum a sequence of integers. Assume that the first integer read specifies the number of values remaining to be entered. Your program should read only one value per input statement. A typical input sequence might be 5100200300400500 where the 5 indicates that the subsequent 5 values are to be summed.

Problem 6

Write a program that uses a for statement to calculate and print the average of several integers. Assume the last value read is the sentinel 9999 A typical input sequence might be 10811799999 indicating that the program should calculate the average of all the values preceding 9999

Problem 7

include 4 using std::cout; 5 using std::cin; 6 using … # What does the following program do? 1 // Exercise 5.7: ex05_07.cpp 2 // What does this program print? 3 #include 4 using std::cout; 5 using std::cin; 6 using std::endl; 7 8 int main() 9 { 10 int x; // declare x 11 int y; // declare y 12 13 // prompt user for input 14 cout << "Enter two integers in the range 1-20: "; 15 cin >> x >> y; // read values for x and y 16 17 for ( int i = 1; i <= y; i++ ) // count from 1 to y 18 { 19 for ( int j = 1; j <= x; j++ ) // count from 1 to x 20 cout << '@'; // output @ 21 22 cout << endl; // begin new line 23 } // end outer for 24 25 return 0; // indicate successful termination 26 } // end main

Problem 8

Write a program that uses a for statement to find the smallest of several integers. Assume that the first value read specifies the number of values remaining and that the first number is not one of the integers to compare.

Problem 9

Write a program that uses a for statement to calculate and print the product of the odd integers from 1 to 15.

Problem 12

Write a program that uses for statements to print the following patterns separately, one below the other. Use for loops to generate the patterns. All asterisks \((*)\) should be printed by a single statement of the form cout \(<<\stackrel{*^{\prime}}{*}\) (this causes the asterisks to print side by side). [Hint: The last two patterns require that each line begin with an appropriate number of blanks. Extra credit: Combine your code from the four separate problems into a single program that prints all four patterns side by side by making clever use of nested for loops.]

Problem 14

A mail order house sells five different products whose retail prices are: product \(1 \$ 2.98,\) product \(2 \$ 4.50,\) product \(3 \$ 9.98,\) product \(4 \$ 4.49\) and product \(5 \$ 6.87 .\) Write a program that reads a series of pairs of numbers as follows: a. product number b. quantity sold Your program should use a switch statement to determine the retail price for each product. Your program should calculate and display the total retail value of all products sold. Use a sentinel-controlled loop to determine when the program should stop looping and display the final results.

Access millions of textbook solutions in one place

  • Access over 3 million high quality textbook solutions
  • Access our popular flashcard, quiz, mock-exam and notes features
  • Access our smart AI features to upgrade your learning
Get Vaia Premium now
Access millions of textbook solutions in one place

Recommended explanations on Computer Science Textbooks