Skip to content

Latest commit

 

History

History
 
 

24_ch16_rq

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
As always, read and understand Chapter 16, then answer these questions
in "answers.txt". 

1.  All of the following are advantages of the std::string class over a
    C-style string EXCEPT: 

    A.  An object of type string is mutable.
    B.  An object of type string requires less memory than a C-style
    	string.
    C.  The string class is consistent with OOP.
    D.  The string class supports concatenation.

2.  Instead of printf, a C++ programmer would use

    A.  std::cout << 
    B.  std::cout >>
    C.  std::printf
    D.  std::print_string

3.  What is the return type of the stream insertion operator?

    A.  void
    B.  std::string
    C.  A reference to the type of stream being inserted into
    D.  A reference to the type of data being inserted into the stream

4.  If std::cin.good() is false, what do you need to do before you can
    read any more data from std::cin? 

    A.  std::cin.reset();
    B.  std::cin.no_error();
    C.  std::cin.set_good(true);
    D.  std::cin.clear();

5.  Which C++ stream is analogous to stderr?

    A.  std::cout
    B.  std::cin
    C.  std::cerr
    D.  None of these--you should still use stderr

6.  What does it mean to declare something as a "friend"?

    A.  Whatever a class declares as its friend has access to its
        private fields and methods.
    B.  Whatever a class declares as its friend can call const methods
        even in circumstances where it would otherwise not be
        permissible to do so.
    C.  Whatever a class declares as its friend can set special rules
        for when that class's destructors are invoked.
    D.  None of the above

7.  How many std::strings are destroyed during one invocation of the
    following function? 

    void f(std::string s1, std::string s2) {
      std::cout << s1.substr(3,5) << ":" << s2.substr(4,6) << "\n";
    }

    A.  0
    B.  2
    C.  4
    D.  6

8.  If you wanted to write data to a file in C++, the class you would
    use is _______.

    A.  std::cout
    B.  std::ifstream
    C.  std::ofstream
    D.  FILE *

9.  Using the above class, how could you could specify the name of the
    file to open?  

    A.  Call fopen and assign the returned result to the variable.
    B.  Pass the filename to the constructor.
    C.  Call the set_file_name method on the object.
    D.  None of the above

10. What does the class std::stringstream let you do?

    A.  Print only strings
    B.  Read in only strings
    C.  Format data into a string buffer, which can be retreived
    D.  String together multiple streams such that you can write to
        all of them at once with a single stream insertion operation