There is an argument I've observed several times.
Most likely he meant 10 statements, i.e. 10 semicolons. This is usually the same as lines, but it raises several points:
The language allows multiple statements without new lines
The language permits mostly free use of white-space
The language permits mostly free use of comments
Do macros count? Intuitively it seems they should, but n a header file would the include guards count? How about conditional compilation statements, pragmas, constants and header file includes
What exactly then is a line?
"Lines" is a tad vague from a programmers perspective, your coding style could significantly affect the number of lines of text you type.
If you're brave enough, and don't mind failing the course, challenge him on the precise use of "lines" and do it in 5 lines of text like so:
1 2 3 4 5
|
#include <iostream>
#include <string>
#include <bitset>
#include <limits>
std::string str_to_bin( std::string str ){ using bits = std::bitset< std::numeric_limits< unsigned char >::digits > ; std::string result ; for( unsigned char c : str ) result += bits(c).to_string() ; return result ; } int main(){ std::string str ; std::cout << "enter a message: " ; std::getline( std::cin, str ) ; std::cout << str_to_bin(str) << '\n' ;}
|
Please never style your code like this for real, only when you're trying to be a pedantic wise ass. |