C++ Unit 3 Quiz Review

Ace your homework & exams now with Quizwiz!

The function, pow(x, 5.0), requires this header file.

cmath

Write a short description of each of the following functions: cos exp fmod log log10 pow sin sqrt tan

cos - Returns the cosine of the argument. The argument should be expressed in radians, return type is doubles exp - Computes exponential function of base e to the power of x, return type are doubles fmod - The remainder of the first argument divided by the second argument. Works like a modulus operator, but the arguments are doubles, return type are also doubles. (The modulus operator works only with integers.) NOTE: Be careful to not divide by zero. log - Returns the natural logarithm of the argument, the return type and the argument are doubles. log10 - Returns the base 10 logarithm, the return type and argument are doubles. sin - Returns the sine of the argument, when expressed in radians. Return type are doubles. pow - Raises the first argument to the second argument. Arguments and return types are doubles. sqrt - Returns the square root of the argument. The return type and argument are doubles. tan - Returns the tangent of the argument when expressed in radians. The return type and the argument are doubles.

This stream manipulator forces cout to print the digits in fixed-point notation.

fixed

________ reads a line of input, including leading and embedded spaces, and stores it in a string object.

getline

In any program that uses the cin object, you must include the ________.

iostream header file

This manipulator causes the field to be left-justified with padding spaces printed to the right.

left

Which statement is equivalent to the following? number += 1;

number = number + 1;

When a variable is assigned a number that is too large for its data type, it:

overflows

When converting some algebraic expressions to C++, you may need to insert ________ that do not appear in the algebraic expression.

parenthesis

This manipulator is used to establish a field width for the value immediately following it.

setw

When this operator is used with string operands it concatenates them, or joins them together.

+

Assume that x is an int variable. What value is assigned to x after the following assignment statement is executed? x = -3 + 4 % 6 / 5;

-3

What is the value stored at x, given the statements: int x; x = 3 / static_cast<int>(4.5 + 6.4);

0

What will the value of x be after the following statements execute? int x = 0; int y = 5; int z = 4; x = y + z * 2;

13

What will the value of result be after the following statement executes? result = 6 - 3 * 2 + 7 - 10 / 2 ;

2

What is the value of average after the following code executes? double average; average = 1.0 + 2.0 + 3.0 / 3.0;

4.0

Which statement is equivalent to the following? x = x * 2;

x *= 2;

Assume the variables angle1 and angle2 hold angles stored in radians. Write a statement that adds the sine of angle1 and cosine of angle2 and stores the result in the variable x.

x = sin(angle1) + cos(angle2);

In the following C++ statement, what will be executed first according to the order of precedence? result = 6 - 3 * 2 + 7 - 10 / 2 ;

3 * 2

Which line in the following program will cause a compiler error? 1 #include <iostream> 2 using namespace std; 3 4 int main() 5 { 6 const int MY_VAL; 7 MY_VAL = 77; 8 cout << MY_VAL << endl; 9 return 0; 10 }

6 and 7

What operator follows the cout object?

<<

What header file must be included in programs using cin?:

<iostream>

What operator follows the cin object?

>>

The following program will run, but the user will have difficulty understanding what to do. How would you improve the program? // This program multiplies two numbers and displays the result. #include <iostream> using namespace std; int main () { double first, second, product; cin >> first >> second; product = first * second; cout << product; return 0; }

Include one or more cout statements explaining what values the user should enter.

TRUE or FALSE: cin requires the user to press the [Enter] key when finished entering data.

TRUE

When the final value of an expression is assigned to a variable, it will be converted to:

The data type of the variable

The what causes a program to wait until information is typed at the keyboard and the Enter key is pressed.

cin object

A program has the following variable definitions: long miles; int feet; float inches; Write one cin statement that reads a value into each of these variables.

cin << miles << feet << inches;

You want the user to enter the length, width, and height from the keyboard. Which cin statement is correctly written?

cin >> length >> width >> height;

The total number of digits that appear before and after the decimal point is sometimes referred to as:

significant digits AND precision

Write a statement that calculates the cosecant of the angle stored in the variable a, and stores it in the variable y

y = 1/(sin(a));

Write a statement that will find the fifth root of the variable x and store the result in the variable y.

y = pow (x, .20);

#include <iostream> using namespace std; int main () { double pounds, kilograms; // Write code here that prompts the user // to enter his or her weight and reads // the input into the pounds variable. // The following line does the conversion. kilograms = pounds / 2.2; // Write code here that displays the user's weight // in kilograms. return 0; }

#include <iostream> using namespace std; int main () { double pounds, kilograms; // Gather user input cout << " Enter your weight " << endl; cin >> pounds; // Calculate Kilograms kilograms = pounds / 2.2; // Output Display Weight in Kilograms cout << " Your weight in kilograms is " << kilograms << endl; return 0; }

You can use these to override the rules of operator precedence in a mathematical expression.

(Parentheses)

Assume value is an integer variable. If the user enters 3.14 in response to the following programming statement, what will be stored in value? cin >> value

3

What is the value of number after the following statements execute? int number = 10; number += 5; number -= 2; number *= 3;

39


Related study sets

CH. 31 Assessment and Management of Patients With Vascular Disorders and Problems of Peripheral Circulation

View Set

AP BIO UNIT 2 review for AP test

View Set

Intro to Business Exam 2 Quiz Study Guide

View Set

History Quiz #3 - Reconstruction

View Set

CHAPTER 14: Integrated Marketing Communications

View Set

Chapter 6 Theory and Number Crunching Questions

View Set