[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!