Question: 1. [10 marks] Suppose that s1 and s2 are given as follows: string s1(Hello C++ programming ); string s2(CSE 202); Assume that each expression is

1. [10 marks] Suppose that s1 and s2 are given as follows: string s1("Hello C++ programming "); string s2("CSE 202"); Assume that each expression is independent. What are the result of the following statements?

a) s1.append(s2); cout << s1;

b) cout << s1.at(0);

c) cout << s2.length();

d) cout << s1.substr(6);

e) cout << s1.substr(6, 3);

f) cout << s1.find("C++");

g) cout << (s1 > s2);

h) s1.replace(6, 3, "Java"); cout << s1;

i) s1.assign("Hello World"); cout << s1;

j) s1 = s2; ; cout << s1;

2. [5 marks] Show the printout of the following code:

int x = 100; int y = 200;

int* p_x = &x;

(*p_x)++;

cout << x << endl;

cout << *p_x << endl;

p_x = &y;

(*p_x)++;

cout << y << endl;

cout << *p_x << endl;

3. [5 marks] Show the printout of the following code:

char c[6] = {'a', 'b', 'c', 'd', 'e', 'f'};

for (int i = 0; i < 6; i++)

{

cout << *(c + i) << endl;

}

4. [5 marks] Show the printout of the following code:

int a[] = {11, 12, 13, 14, 15};

int* p = a;

for (int i = 0; i < 5; i++)

{

cout << *(a + i) << ",";

cout << *(p + i) << ",";

cout << p[i] << endl;

}

5. [5 marks] Show the printout of the following code:

string* p_s = new string("abcdefg");

string s("ABCDE");

cout << (*p_s) << endl;

cout << p_s->substr(3,3) << endl;

cout << p_s->length() << endl;

delete p_s; p_s = & s;

cout << p_s->substr(3) << endl;

cout << p_s->length() << endl;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!