Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Suppose num1 and num2 are int variables and symbol is a char variable. Consider the following input: 12 34 / 56 = What value (if

Suppose num1 and num2 are int variables and symbol is a char variable. Consider the following input: 12 34 / 56 = What value (if any) is assigned to num1, num2, and symbol after each of the following statements executes?

(Use the same input for each statement. If any variable is undefined, just put an X in that box.) If a variable contains a space, write the word space.)

Code num1 num2 symbol a. cin >> num1 >> symbol >> num2;

b. cin >> symbol >> num1 >> num2;

c. cin >> num1; cin.get(symbol); cin >> num2;

d. cin >> num1 >> num2; cin.get(symbol);

e. cin.get(symbol); cin >> num1 >> num2;

Suppose x and y are int variables and z is a double variable. Assume the following input data: 6.56 12

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. If any variable is undefined, just put an X in that box.)

Code or Question x y z

a. cin >> x >> y >> z; Why is x not 6.56?

b. cin >> x >> z >> y;

c. cin >> z >> x >> y;

What problem happens with the given input, and why? Suppose x and y are int variables and symbol is a char variable. Assume the following input data: 12 34 * 56 78 24 $ 55 # 34 # & 12 34

What value (if any) is assigned to x, y, and symbol after each of the following statements executes? (Use the same input for each statement. If any variable is undefined, just put an X in that box.)

Code and Question(s) X Y symbol

a. cin >> x >> y; cin.ignore(100, ' '); cin >> symbol;

b. cin >> x; cin.ignore(100, '*'); cin >> y; cin.get(symbol);

c. cin.get(symbol); cin.ignore(100, '*'); cin >> x; cin.ignore(100, ' '); cin >> y;

d. cin.ignore(100, ' '); cin >> x >> symbol; cin.ignore(100, ' '); cin.ignore(100, '&'); cin >> y;

e. Briefly, and in English, what is the purpose of the cin.ignore(100, ' '); statements?

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?

Suppose x and y are int variables, z is a double variable, and ch is a char variable. Suppose the input statement is:

cin >> x >> y >> ch >> z;

What values, if any, are stored in x, y, z, and ch if the input is as shown in this table:

Input x y z ch

a. 12 34.56

b. 12 34A 92.6

c. 12 .34A 56

Suppose that num is an int variable and discard is a char variable. Assume the following input data: #34

What value (if any) is assigned to num and discard after each of the following statements executes? (Use the same input for each statement. If any variable is undefined, just put an X in that box.)

Code num discard

a. cin.get (discard); cin >> num;

b. discard = cin.peek(); cin >> num; Why did num get that value?

c. cin.get (discard); cin.putback (discard); cin >> discard; cin >> num;

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

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:

Input age name

a. 23 John Smith

b. 23 John Smith

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; } Note: I dont intend to run your program unless necessary, I just want to see the correct lines of code in the appropriate place. Please add brief explanatory comments to the lines of code you add.

Suppose that you have the following statements: ofstream outfile; double distance = 375; double speed = 58; double travelTime;

Write C++ statements to do the following:

-Open the file travel.txt using the variable outfile.

-Write the statement to format your output to two decimal places in fixed form.

-Write the values of the variables distance and speed into the recently opened output file.

-Calculate and write the travelTime into the output file. Which header files are needed to process the information in (a) to (d)?

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

Step: 3

blur-text-image

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

Practical Azure SQL Database For Modern Developers Building Applications In The Microsoft Cloud

Authors: Davide Mauri, Silvano Coriani, Anna Hoffma, Sanjay Mishra, Jovan Popovic

1st Edition

1484263693, 978-1484263693

More Books

Students also viewed these Databases questions