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

Mark the following statements as true or false. a. The extraction operator >> skips all leading whitespace characters when searching for the next data in the input stream. b. In the statement cin >> x;, x must be a variable. c. The statement cin >> x >> y; requires the input values for x and y to appear on the same line. d. The statement cin >> num; is equivalent to the statement num >> cin;. e. You generate the newline character by pressing the Enter (return) key on the keyboard. f. The function ignore is used to skip certain input in a line.

Problem 2

Suppose x and y are int variables and ch is a char variable. Consider the following input: 5 28 36 What value (if any) is assigned to x, y, and ch after each of the following statements executes? (Use the same input for each statement.) a. cin >> x >> y >> ch; b. cin >> ch >> x >> y; c. cin >> x >> ch >> y; d. cin >> x >> y; cin.get(ch);

Problem 3

Suppose x and y are int variables and z is a double variable. Assume the following input data: 37 86.56 32 What value (if any) is assigned to x, y, and z after each of the following statements executes? (Use the same input for each statement.) a. cin >> x >> y >> z; b. cin >> x >> z >> y; c. cin >> z >> x >> y;

Problem 5

Given the input: 46 A 49 and the C++ code: int x = 10, y = 18; char z = '*'; cin >> x >> y >> z; cout << x << " " << y << " " << z << endl; What is the output?

Problem 8

Which header file must be included to use the function pow?

Problem 9

Suppose that name is a variable of type string. Write the input statement to read and store the input Brenda Clinton in name. (Assume that the input is from the standard input device.)

Problem 11

Suppose that age is an int variable and name is a string variable. What are the values of age and name after the following input statements execute: cin >> age; getline(cin, name); if the input is: a. 23 Lance Grant b. 23 Lance Grant

Problem 12

Suppose that age is an int variable, ch is a char variable, and name is a string variable. What are the values of age and name after the following input statements execute: cin >> age; cin.get(ch); getline(cin, name); if the input is: a. 23 Lance Grant b. 23 Lance Grant

Problem 13

The following program is supposed to read two numbers from a file named input.dat and write the sum of the numbers to a file named output.dat. However, it fails to do so. Rewrite the program so that it accomplishes what it is intended to do. (Also, include statements to close the files.) #include #include using namespace std; int main() { int num1, num2; ifstream infile; outfile.open("output.dat"); infile >> num1 >> num2; outfile << "Sum = " << num1 + num2 << endl; return 0; }

Problem 14

What may cause an input stream to enter the fail state? What happens when an input stream enters the fail state?

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