Question: In C++ modify the code as much as possible to use vectors instead of arrays. Is the output different? 1. void swap(int &a, int &b)

In C++ modify the code as much as possible to use vectors instead of arrays. Is the output different?

1.

void swap(int &a, int &b) { int hold; hold = a; a = b; b = hold; }

int main() {

int x[5] = {14, 3, 9}; // what is the value of x[3]?

swap(x[0], x[2]);

swap(x[1], x[3]);

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

cout << x[i] << ", ";

}

2.

void dostuff(char a[], char b[]);

int main() {

char s1[] = "PAPOA";

char s2[] = "WEHLO";

dostuff(s1, s2);

cout << s1;

}

void dostuff(char a[], char b[]) {

a[0] = 'Y';

a[2] = b[2];

a[4] = b[4];

}

3.

const int ROWS=2, COLS=3;

int a[ROWS][COLS] = { {2, 4, 6}, {7, 5, 3} };

for(int i=0; i

for(int j=0; j

cout << a[i][j] << ", ";

cout << 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!