Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The output of the following c++ code is suppose to look like: 2 [2, 3, 10, 10, 5] but I'm not sure what the problem

The output of the following c++ code is suppose to look like:

2 [2, 3, 10, 10, 5]

but I'm not sure what the problem is.

Once the code is correct, please convert it into MIPS assembly language

----------------------------------------------------------------------------------------------------------------------------------

#include

using namespace std;

int replace(int,int,int,int[]);

int main() {

int a[5]; //declare an array

a[0]=2; //array int

a[1]=3;

a[2]=4;

a[3]=4;

a[4]=5;

cout << a[0] << endl; //show initial values

replace(4,10,5,a); //replace all instances of "4" in the

// array with "10"

//array length is 5, and passing array a

cout << a << endl; //show new values

}

int replace (int existing, int newitem, int size, int a[])

{

int i;

for (i=0; i < size; i++)

{

if (a[i]==existing)

a[i] = newitem;

}

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

6.15 Identify psychological risk factors in coronary heart disease.

Answered: 1 week ago