Name: ______Key_________
Quiz 3 (Week 4)
CS-150, Fall ‘02, Dr. C. S. Tritt
Each question is worth the same amount.
int myValue = 12345;
cout << "The
value is " << setw(8) << myValue << "
eggs.\n";
Answr: The value is 12345 eggs.
double aValue = 12.345;
cout << "The
value is ";
cout << setw(6)
<< setprecision(2) << aValue;
cout <<
"ft/s.\n";
Answr: The value is 12ft/s.
Extra space after 12 okay. Answering … 12.34 … okay. Commenting on missing semicolons would have been + 5 bonus (but nobody did).
Answr: cout << "$" << setw(7) << fixed << setprecision(2) << orderCost << endl;
“$” and endl optional. Missing “fixed” okay – may have already been set. Missing “setw” okay – but does help align decimal points.
… int count = 1; double factor = 2.5; count = count + 1; // count will be 2 here. if (count <= 1) factor
= factor + 1.0; // not executed. else factor
= factor – 1.0; // factor becomes 1.5 here. count = count + 1; // count becomes 3 here. factor = factor * 2.0; // factor doubled to 3.0
here. …
Answr: 3.0 (wrong values generally -20)