Ch 3 Checkpoint Questions

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

The following program skeleton asks for an angle in degrees and converts it to radians. The formatting of the final output is left to you. #include <iostream> #include <iomanip> using namespace std; int main( ) { const double PI = 3.14159; double degrees, radians; cout << "Enter an angle in degrees and I will convert it \n"; cout << "to radians for you: "; cin >> degrees; radians = degrees * PI / 180; // Displaying the value in radians left justified, in fixed //point notation, with 4 places of precision, in a field //5 spaces wide, making sure the decimal point is always //displayed. return 0; }

#include <iostream> #include <iomanip> using namespace std; int main() { const double PI = 3.14159; double degrees, radians; cout << "Enter an angle in degrees and I will convert it\n"; cout << "to radians for you: "; cin >> degrees; radians = degrees * PI / 180; cout << degrees << " degrees is equal to "; cout << setw(5) << left << fixed << showpoint << setprecision(4) << radians << " radians.\n"; return 0; }

The following program will not compile because the lines have been mixed up. #include <iomanip> } cout << person << endl; string person = "Wolfgang Smith"; int main() cout << person << endl; { #include <iostream> return 0; cout << left; using namespace std; cout << setw(20); cout << right; When the lines are properly arranged the program should display the following: Wolfgang Smith Wolfgang Smith Rearrange the lines in the correct order. Test the program by entering it on the computer, compiling it, and running it.

#include <iostream> #include <string> using namespace std; int main() { string person = "Wolfgang Smith"; cout << right; cout << setw(20); cout << person << endl; cout << left; cout << person << endl; return 0; }

What will he following program display? #include <iostream> using namespace std; int main() { int unus, duo, tres; unus = duo = tres; unus += 4; duo *= 2; tres -= 2; unus /= 3; duo += tres; cout << unus << endl; cout << duo << endl; cout << tres << endl; return 0; }

3 11 1

Assume the following variable definitions: int a = 5, b = 12; double x = 3.4, z = 9.1; What are the values of the following expressions? A) b / a B) x * a C) static_cast<double>(b / a) D) static_cast<double>(b) / a E) b /static_ cast<double>(a) F)static_ cast<double>(b) / static_ cast<double>(a) G) b / static_ cast<int>(x) H) static_ cast<int>(x) * static_ cast<int>(z) I) static_ cast<int>(x * z) J) static_cast<double>(static_ cast<int>(x) * static_ cast<int> (z) )

A) 2 B) 17.0 C) 2.0 D) 2.4 E) 2.4 F) 2.4 G) 4 H) 27 I) 30 J) 27.0

Write cout statements with stream manipulators that perform the following: A) Display the number 34.789 in a field of nine spaces with two decimal places of precision. B) Display the number 7.0 in a field of five spaces with three decimal places of percision. The decimal point and any trailing zeroes should be displayed. C) Display the number 5.789e+12 in fixed point notation. D) Display the number 67 left justified in a field of seven spaces.

A) cout << setw(9) << fixed << setprecision(2) << 34.789; B) cout << setw(5) << fixed << setprecision(3) << 7.0; C) cout << fixed << 5.789e12; D) cout << left << setw(7) << 67;

Write statements using combined assignment operators to perform the following: A) Add 6 to x B) Subtract 4 from amount. C) Multiply y by 4. D) Divide total by 27. E) Store in x the remainder of x divided by 7. F) Add y *5 to x. G) Subtract discount times 4 from total. H) Multiply increase by salesRep times 5. I) Divide profit by shares minus 1000.

A) x += 6; B) amount −= 4; C) y *= 4; D) total /= 27; E) x %= 7; F) x += (y * 5); G) total −= (discount * 4); H) increase *= (salesRep * 5); I) profit /= (shares − 1000);

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; A) 3.14 B) 3 C) 0 D) Nothing. An error message is displayed.

B. 3

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;

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

cos: Returns the cosine of the argument. exp: Returns the exponential function of the argument. fmod: Returns the remainder of the first argument divided by the second argument. log: Returns the natural logarithm of the argument. log10: Returns the base-10 logarithm of the argument. pow: Returns the value of the first argument raised to the power of the second argument. sin: Returns the sine of the argument. sqrt: Returns the square root of the argument. tan: Returns the tangent of the argument.

What header file must be included in programs using cin?

iostream

Write a multiple assignment that assigns 0 to the variables total, subtotal, tax, and shipping.

total = subtotal = tax = shipping = 0;

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

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

The cosecant of the angle a is (1/sin a) 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 C++ expressions for the following algebraic expressions: y = 6x a = 2b + 4c y = x^2 g = x +2 / z^2 y = x^2 / z^2

y = 6 * x; a = 2 * b + 4 * c; y = x * x; or y = pow(x, 2.0); g = (x + 2) / (z * z); or g = (x + 2.0) / pow(z, 2.0); y = (x * x) / (z * z); or y = pow(x, 2.0) / pow (z, 2.0);

To find the cube root (the third root) of a number, raise it to the power of (1/3). To find the fourth root of a number, raise it to the power (1/4). Write a statement that will find the fifth root of the variable x and store the result in the variable y.

y = pow(x, 0.2); // 0.2 is equal to 1/5


Kaugnay na mga set ng pag-aaral

Edapt Nursing Application: Water and Wellness

View Set

CH. 62 Management of Patients With Cerebrovascular Disorders

View Set

CYBR 4323 (Privitera) - Chapter 26: Standard Client-Server Protocols

View Set

CYBR2.TestOut 12.6.4(SY0-601) (59)

View Set

Connections Between Texts in Fiction

View Set