1

We have a stickie on top of a lot of the forums with good websites/books, etc. I figured I'd share one I just discovered. I decided to test my C++ knowledge and so I took this quiz and didn't do too hot. But I don't feel too bad and if you take the quiz and look at the answers , I imagine you won't either when you fail. I think it's like golf. The lower your score, the better your actual knowledge.

Anyway, we have a prominent thread for good sources, but I thought it would be interesting to share BAD ones to never refer anyone to, so I'll start with the one above, assuming the rest of it is anything like the quiz I took.

http://www.academictutorials.com

Votes + Comments
This made me laugh.. sort of :)
5
Contributors
10
Replies
11
Views
9 Years
Discussion Span
Last Post by VernonDozier
Featured Replies
0

The answers to three questions are just flat out wrong

4. Which line has all reserved words ?
if, else, for, while do, switch, continue, break

while do is not a reserved word.

8. Select the correct definition for a string variable.

Both 1 and 4 are correct answers.

11. Select the correct function definition (NOT prototype) from the list below.

double pow(double num, int pow); is wrong because its a function prototype

13. Write a for loop that counts from 0 to 5.

for (c = 0; c <= 5; c++) that counts from 0 to 6, not 0 to 5.

14. What does the statement #include do ?

All answers are wrong.

And the most outregous question of all

15. Which of the following converts an integer "value" to its ASCII equivalent ?

atoi() does just the opposite of what they say it does.

0

The most outrageous is a tough one. There are so many to choose from, but I nominate this one instead. Number 17:

17. Which one of the choices would produce the following output ?
cout << "Hello" << "World";
cout << "Hello \n World";
cout << "Hello World\n";
cin >> "Hello World";

"Correct" answer is in red. Correct answer to WHAT is unclear because the "following output" that is to produced is never actually listed. But whatever it was, I feel pretty sure that the above line wouldn't produce it.

Number 7 has two correct answers and numbers 18 and 20 are wrong too. It's scary that people trying to learn from a tutorial will come across this site after a Yahoo search, which was exactly how I found it (can't remember what I was searching for, but I decided to go elsewhere for answers after taking this test).

0

>>Number 7 has two correct answers
No -- 5.9875e17 can only be stored in a double -- floats are too small.

Ah, yes, you are correct. I had done a little program last night to check it and it seemed to work (I though the program would crash if I gave it a number a float it couldn't handle, but it apparently just rounds it off as best it can and keeps on chugging). Just did a more extensive test and it definitely can't hold it. I guess by that time I was pre-disposed to thinking any answer given by the quiz couldn't possibly be right, so my test wasn't that rigorous, but this answer was right. Shucks.

Good catch.

0

>>Number 7 has two correct answers
No -- 5.9875e17 can only be stored in a double -- floats are too small.

My understanding is the range of a float is +/- 3.4e+/-38, with 7 digits precision. The number above would comfortably fit in that range.

0

My understanding is the range of a float is +/- 3.4e+/-38, with 7 digits precision. The number above would comfortably fit in that range.

The value in question is outside that range (-5 is smaller than -3), which is why I can't be stored in a float without data truncation. Some compilers, such as VC++ 2008 Express, will produce truncation warnings when attempting to store -5.9875e17 in a float.

0

for (c = 0; c <= 5; c++) that counts from 0 to 6, not 0 to 5.

Depends, if you write it like this, it displays "012345", but c has the value 6 once its out the loop.

#include <iostream>
using namespace std;

int main() {
   int c;
   for (c = 0; c <= 5; c++) {
      cout << c;
   }
   cout << ' ' << c;
}

This gives the following output:

012345 6

I guess the quesion is only talking about what c is while its actually inside the loop ;)

0

The value in question is outside that range (-5 is smaller than -3), which is why I can't be stored in a float without data truncation. Some compilers, such as VC++ 2008 Express, will produce truncation warnings when attempting to store -5.9875e17 in a float.

I see the truncation warning at compile time in VC++2005 - but that's not got anything to do with the specific value being out of range. Any literal floating point value is treated as a double, unless you indicate it's a float with a terminating 'f'. I see that a floating point value that cannot be expressed accurately (within the precision) will get the truncation warning.

So, to perhaps split some hairs, the value in question is within the range of a float, but cannot be accurately stored in a float (even though it has less than 7 significant digits). It gets fuzzy at the 6th digit.

I don't see what "-5 smaller than -3" refers to in this context.

0

I see the truncation warning at compile time in VC++2005 - but that's not got anything to do with the specific value being out of range. Any literal floating point value is treated as a double, unless you indicate it's a float with a terminating 'f'. I see that a floating point value that cannot be expressed accurately (within the precision) will get the truncation warning.

So, to perhaps split some hairs, the value in question is within the range of a float, but cannot be accurately stored in a float (even though it has less than 7 significant digits). It gets fuzzy at the 6th digit.

I don't see what "-5 smaller than -3" refers to in this context.

I ran this program:

#include <iostream>
using namespace std;

int main ()
{
    double a = 5.9875e17;
    double b = 5.9875e17;
    float  c = 5.9875e17;
    cout << "a - b = " << a - b << endl;
    cout << "a - c = " << a - c << endl;
    cin.get ();
    return 0;
}

and I got these results:

a - b = 0
a - c = 1.66978e+010

so it looks like there is round-off error with the float, but not the double? Otherwise the subtraction would be equal to exactly 0, as it is when subtracting the doubles?

Also, looks like question 19 is wrong too:

for (int a = 1; a <= 1; a++) cout << a++; cout << a;

a in red is out of scope by this time, so it won't compile.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.