Thread: I just got back from an exam...

  1. #1
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613

    I just got back from an exam...

    I did ok, but it was a weird exam. The two questions where I have the most difficulty in understanding my scoring are:

    The statement:
    cin >> someInt;
    can be interchanged with
    someInt >> cin;
    [] True
    [x] False

    (paraphrasing) Writing code in a clean and consistent style is important to
    a) the compiler
    b) the person writing the program
    c) other people reading the source
    d) b and c

    I missed points on both and I was positive I wouldn't. I suppose you could argue my answer for both. But the instructor hasn't covered bitwise operations (and won't for the rest of class). And well, I just thought d was a reasonable answer for the other.

    ... Stupid world.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    The first one is indeed FALSE, there is no other valid option. Shifting onto cin will give you a compiler error if cin is the console input stream, and if its an integer, it's as commutative as 2/5 is the same as 5/2 - that is, not at all.

    The second question is slightly less clear-cut, but I would have said that c is the predominant (assuming we are discussing this from the goal of being a PROFESSIONAL programmer rather than someone sitting in the attic writing code for him/herself), but b is also important, as we are all human and recognising the code later is much easier if it was written in a consistant and clear manner.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    I would also agree with both your answers. What I would do is try the cin thing, and take the specific error to your teacher.

    For the other one - you can't PROVE it, but any answer other than D is ridiculous. The compiler ignores whitespace, so A can't be it. The only reason D wouldn't be the correct answer is if you're trying to obfuscate it, and that's me TRYING to be ridiculous.

  4. #4
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    That's terrible!

    My SE exam had a similar wtf, "With the concept of Agile programming, what do the following acronyms stand for?". "AIGOAKSAJDKJAD" and like "ASJKDAJSKLDJASKLJD" (not what they were) ... they were seriously that long and I've never heard of them in my life. Granted it's not the same thing, but anyway

    Is arguing really worth your 2 marks? Probably not. Although if you approach it in a smart way you could get them removed from the exam (ie everyone gets a mark).

    Perhaps question 1 means, "will it compile in place of cin >> someInt"?

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    What I would do is go to the professor and say, "I don't understand how this works - because I tried it and I got an error. How do you get it to work and why would you do that?"

  6. #6
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Those should be the right answers.
    What were the alleged "right" answers, and why?
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  7. #7
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    Our tests are graded by a cold, unfeeling machine so my only recourse is through the professor and hope that she can do something. If you're interested in reading the email I sent to her, this is the body:

    [Professor], I can prove that I was marked unfairly on at least three questions after the midterm and possibly a fourth.

    11.
    The input statement
    cin >> someInt;
    could also be written as
    someInt << cin;
    A) True
    B) False

    As you can see from my answer key I chose false. A simple test program proves that this isn't compilable if cin is a stream.

    Code:
    #include <iostream>
    using namespace std;
    int main ()
    {
    int someInt;
    
    cin >> someInt;
    someInt << cin;
    
    return 0;
    }
    
    Compiling...
    foo.cpp
    c:\documents and settings\jck\my documents\itcs2530\example\example\foo.cpp(8) : error C2784: 
    'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,unsigned char)' : could not
     deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'int'
    If cin isn't a stream, then we are discussing bitwise operations, which are not commutive.

    27.
    Given the two lines of input data
    ABC
    DEF
    what value is read into ch by the following code? (str is of type string, and ch is of type char.)
    cin >> str;
    cin >> ch;
    A) 'B'
    B) ' \n'
    C) 'C'
    D) 'D'
    E) none of the above

    As you can see from my answer key, I chose D and the following code proves my answer correct.
    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    int main ()
    {
    string str;
    char ch;
    
    cin >> str;
    cin >> ch;
    
    cout << "str = " << str << endl;
    cout << "ch = " << ch << endl;
    return 0;
    }
    This is another answer that is suspect:


    37.
    Formatting a program in a consistent, readable style is valuable to
    A) the person who writes the program.
    B) other people who need to understand and work with the program.
    C) the C++ compiler.
    D) a and b above
    E) a, b, and c above

    I chose D and was marked wrong, but the answer doesn't seem quite as clear-cut.


    35.
    If x is a float variable containing a positive value, which of the following statements outputs the value of x, rounded to the nearest integer?
    A) cout << int(x);
    B) cout << int(x) + 0.5;
    C) cout << int(x + 0.5);
    D) cout << float(x + 0.5);
    E) cout << x + int(0.5);

    I chose C, the correct answer is marked as A, but my answer is correct in practice.
    Code:
    #include <iostream>
    using namespace std;
    int main ()
    {
    float x = 0.6667F;
    cout << "int( x ) = " << int( x ) << endl; // prints as 0
    cout << "int( x + 0.5 ) = " << int( x + 0.5 ) << endl; // prints as 1
    return 0;
    }
    As these points make a substantial difference in my midterm score, I would like points back where you agree with my demonstrations. Thank you so much for your cooperation and understanding!
    We'll see how far that gets me. I'm making my professor sound worse than she is... *shrug*

    I didn't really think this thread through btw I just felt like raging.

  8. #8
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Those are very well argued responses I think - they don't sound rude at all.

  9. #9
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    It sounds like the computer marking machine messed up... or whoever did the answers doesn't know what's going on.

  10. #10
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by zacs7
    My SE exam had a similar wtf, "With the concept of Agile programming, what do the following acronyms stand for?". "AIGOAKSAJDKJAD" and like "ASJKDAJSKLDJASKLJD" (not what they were) ... they were seriously that long and I've never heard of them in my life. Granted it's not the same thing, but anyway
    That would have been fun for a bonus question though
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  11. #11
    Registered User
    Join Date
    Aug 2008
    Location
    Belgrade, Serbia
    Posts
    163
    Quote Originally Posted by zacs7
    My SE exam had a similar wtf, "With the concept of Agile programming, what do the following acronyms stand for?". "AIGOAKSAJDKJAD" and like "ASJKDAJSKLDJASKLJD" (not what they were) ... they were seriously that long and I've never heard of them in my life. Granted it's not the same thing, but anyway
    So did you found out what those mean?
    Vanity of vanities, saith the Preacher, vanity of vanities; all is vanity.
    What profit hath a man of all his labour which he taketh under the sun?
    All the rivers run into the sea; yet the sea is not full; unto the place from whence the rivers come, thither they return again.
    For in much wisdom is much grief: and he that increaseth knowledge increaseth sorrow.

  12. #12
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    > So did you found out what those mean?
    Nope. And I don't see any point in knowing

  13. #13
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Quote Originally Posted by citizen View Post
    We'll see how far that gets me. I'm making my professor sound worse than she is... *shrug*
    I'm not sure how, citizen.
    Your professor clearly needs a refresh course in C++ programming, which is a pervasive problem around the globe judging from so many other examples we see on these boards and other places.

    On another account, why do you feel 37 is not clear-cut? I cannot see any other option that D. The compiler doesn't care about your coding style in the least.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  14. #14
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Mario F. View Post
    I'm not sure how, citizen.
    Your professor clearly needs a refresh course in C++ programming, which is a pervasive problem around the globe judging from so many other examples we see on these boards and other places.

    On another account, why do you feel 37 is not clear-cut? I cannot see any other option that D. The compiler doesn't care about your coding style in the least.
    I agree that C is not the correct answer, but I presume the considered correct answer could be A or B rather than A + B (= D). Although I think D is the right answer.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  15. #15
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Mario F.
    Your professor clearly needs a refresh course in C++ programming, which is a pervasive problem around the globe judging from so many other examples we see on these boards and other places.
    I would reserve judgment until the reply. It could well be just a bunch of data entry mistakes.

    Quote Originally Posted by Mario F.
    On another account, why do you feel 37 is not clear-cut? I cannot see any other option that D. The compiler doesn't care about your coding style in the least.
    It arguably could just be B since some people can actually read the garbage they spew out
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C programming exercises, exam notes, questions...etc
    By BlackOps in forum C Programming
    Replies: 0
    Last Post: 07-11-2009, 08:54 AM
  2. new problem with class
    By jrb47 in forum C++ Programming
    Replies: 0
    Last Post: 12-01-2006, 08:39 AM
  3. UInt to CString and back
    By xlnk in forum Windows Programming
    Replies: 6
    Last Post: 08-27-2003, 03:08 PM
  4. Some woman back ended my car today, and back hurts
    By Terrance in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 08-20-2003, 12:42 AM
  5. I am back
    By NANO in forum C++ Programming
    Replies: 0
    Last Post: 06-24-2002, 11:00 AM