String Class

1

Which method do we use to append more than one character at a time?

A. append
B. operator+=
C. data
D. both a & b

2

What is the output of this program?

1.
   #include 
2.
   #include 
3.
   using namespace std;
4.
   int main ()
5.
   {
6.
       string str ("Ubuntu");
7.
       cout << str.capacity();
8.
       cout << str.max_size();
9.
       return 0;
10.
   }
A. 61073741820
B. 51073741820
C. 6 and max size depends on compiler
D. none of the mentioned

3

What is the output of this program?

1.
    #include 
2.
    #include 
3.
    using namespace std;
4.
    int main ()
5.
    {
6.
        string str ("Microsoft");
7.
        for (size_t i = 0; i < str.length();)
8.
        {
9.
            cout << str.at(i-1);
10.
        }
11.
        return 0;
12.
    }
A. M
B. Microsoft
C. Micro
D. runtime error

4

What is the output of this program?

1.
    #include 
2.
    #include 
3.
    using namespace std;
4.
    int main ()
5.
    {
6.
        string str ("steve jobs is legend");
7.
        string::iterator it;
8.
        str.erase (str.begin()+ 5, str.end()-7);
9.
        cout << str << endl;      
10.
        return 0;
11.
    }
A. jobs is
B. steve legend
C. steve
D. none of the mentioned

5

What is the output of this program?

1.
   #include 
2.
   #include 
3.
   using namespace std;
4.
   int main ()
5.
   {
6.
       string str ("nobody does like this");
7.
       string key ("nobody");
8.
       size_t f;
9.
       f = str.rfind(key);
10.
       if (f != string::npos)
11.
           str.replace (f, key.length(), "everybody");
12.
       cout << str << endl;
13.
       return 0;
14.
   }
A. nobody does like this
B. nobody
C. everybody
D. everybody does like this