Interactive Quiz for Chapter 10

Question
Your Answer Result/Explanation
10.1
Write a statement that appends s2 into s1 using the append function.
10.2
Write a statement that assigns the first 4 characters in s2 into s1 using the assign function.
10.3
Write an expression that returns a C-String from string s using the c_str() function.
10.4
Assume s is a string with value "abc", what is s.compare("abc")?
10.5
Write an expression that returns position of the first matching substring "abc" in string s.
10.6
Write an expression that returns a substring of three characters from s starting at index 1.
10.7
Write a statement that inserts string s2 into string s1 at index 2.
10.8
Write a statement that replaces 5 characters in string s1 starting at position 2 with string s2.
10.9
Write an expression that returns the first character from string s using the subscript operator.
10.10
Write an expression that returns the last character from string s using the subscript operator and the length function.
10.11
Suppose s is a string with value "abcdef", what is s after executing the statement s.replace(s.find("cd"), 3, "CD")?
10.12
What is the output of the following code?
  #include  
  using namespace std;

  class A
  {
  public:
    int i;
    static int j;
    A();
  };

  int A::j = 0;

  A::A()
  {
    i = 0;
    j++;
  }

  int main()
  {
    A a1;
    cout << a1.i;
    A a2;
    cout << " " << a2.j;
  }