Quiz
Posted: Fri Dec 04, 2009 3:56 pm
I will post several snippets of code in C++. Most of the problems here have nothing to do with the actual language being used and this is not a syntax/be-sure-everything-was-declared set of questions.
The floating-point numbers are completely arbitrary and have no meaning in this quiz. The integral numbers can be assumed significant to the solutions.
Each of these snippets is wrong.
Your objective is to rewrite them so that they are correct.
Anyone may try (if your attempts are serious), however only the most advanced of coders will actually find the correct answers.
In order to relax your minds, I will tell you not to waste your time looking at the subtle details such as using :: scoping on global functions or using UL after numbers to indicate their signs and sizes.
Additionally, you can assume the types of values based on prefixes.
f = float.
st = size_t.
i = int.
d = double.
ul = unsigned long.
#1: Solved first by troublesh00ter.
#2: Solved first by CoMPMStR.
#3: Solved first by CoMPMStR.
#4: Solved first by CoMPMStR.
#5: Solved first by CoMPMStR.
#6: Solved first by CoMPMStR.
#7: Solved first by CoMPMStR.
L. Spiro
The floating-point numbers are completely arbitrary and have no meaning in this quiz. The integral numbers can be assumed significant to the solutions.
Each of these snippets is wrong.
Your objective is to rewrite them so that they are correct.
Anyone may try (if your attempts are serious), however only the most advanced of coders will actually find the correct answers.
In order to relax your minds, I will tell you not to waste your time looking at the subtle details such as using :: scoping on global functions or using UL after numbers to indicate their signs and sizes.
Additionally, you can assume the types of values based on prefixes.
f = float.
st = size_t.
i = int.
d = double.
ul = unsigned long.
#1: Solved first by troublesh00ter.
- Code: Select all
CUtils::CallFunction( fX / 16.0f, fY / 16.0f );
#2: Solved first by CoMPMStR.
- Code: Select all
vVec.x = ::cos( fA );
vVec.y = -::sin( fA );
vVec.z = ::sin( fA );
#3: Solved first by CoMPMStR.
- Code: Select all
for ( int I = static_cast<int>(vVector.size() - 1UL); I >= 0; --I ) {
// Do whatever.
}
#4: Solved first by CoMPMStR.
- Code: Select all
// Our objective here is ONLY to get the maximum value in a vector of unsigned longs.
unsigned long ulMax = 0UL;
for ( size_t I = 0UL; I < vVector.size(); ++I ) {
ulMax = std::max( ulMax, vVector[I] );
}
#5: Solved first by CoMPMStR.
- Code: Select all
++ulSwitch;
ulSwitch %= 2UL;
#6: Solved first by CoMPMStR.
- Code: Select all
ulX = ulIndex % 16UL;
ulY = ulIndex / 16UL;
#7: Solved first by CoMPMStR.
- Code: Select all
for ( int I = 0; I < iTotal; ++I ) {
// Do something.
}
L. Spiro