1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
o-na [289]
3 years ago
12

A) Fix any errors to get the following program to run in your environment. B) Document each line of code with comments and descr

ibe any changes you had to make to the original code to get it to work. C) Write a summary of what your final version of the program does.
You may also add white space or reorder the code to suit your own style as long as the intended function does not change.

#include
using namespace std;

void m(int, int []);
void p(const int list[], int arraySize)
{
list[0] = 100;
}

int main()
{
int x = 1;
int y[10];
y[0] = 1;

m(x, y);

cout << "x is " << x << endl;
cout << "y[0] is " << y[0] << endl;

return 0;
}

void m(int number, int numbers[])
{
number = 1001;
numbers[0] = 5555;
}
Engineering
1 answer:
Bingel [31]3 years ago
4 0

Answer:

Answer is explained below

Explanation:

<u>Part A -: </u>

<u> </u>

<u>Error statement -: </u>

/*

prog.cpp: In function ‘void p(const int*, int)’:

prog.cpp:7:15: error: assignment of read-only location ‘* list’

list[0] = 100;

*/

There is one error in the code in following part

void p( const int list[], int arraySize)

{

list[0] = 100;

}

you are passing list as constant but changing it inside the function that is not allowed. if you pass any argument as const then you can't change it inside the function. so remove const from function argument solve the error.

<u>Part B -: </u>

change made

void p( int list[], int arraySize)

{

list[0] = 100;

}

<u>Executable fully commented code -: </u>

#include <iostream> // importing the iostream library

using namespace std;

void m(int, int []); // Function declearation of m

void p( int list[], int arraySize) // definition of Function p

{

list[0] = 100; // making value of first element of list as 100

}

int main()

{

int x = 1; // initilizing x with 1

int y[10]; // y is a array of 10 elements

y[0] = 1; // first element of y array is 1

m(x, y); // call m function

// printing the desired result

cout << "x is " << x << endl;

cout << "y[0] is " << y[0] << endl;

return 0;

}

void m(int number, int numbers[]) // Function definition of m

{

number = 1001; // value of number is 1001 locally

numbers[0] = 5555; // making value of first element of numbers array 5555

}

Part C :-

In program we initilize x with value 1 and create an array y of 10 elements.

we initilize the y[0] with 1\

then we call function m. In function m ,first argument is value of x and second argument is the pointer to the first element of array y.

so value of x is changed locally in function m and change is not reflected in main function.

but value of y[0] is changed to 5555 because of pass by refrence.

So we are getting the following result :-

x is 1

y[0] is 5555

You might be interested in
All of these are true about steel EXCEPT that:
natta225 [31]

Answer:B) heat tends to strengthen high-strength steel.

Explanation: You are right it is B

3 0
2 years ago
A metal plate of 400 mm in length, 200mm in width and 30 mm in depth is to be machined by orthogonal cutting using a tool of wid
dmitriy555 [2]

Complete Question:

A metal plate of 400 mm in length, 200mm in width and 30 mm in depth is to be machined by orthogonal cutting using a tool of width 5mm and a depth of cut of 0.5 mm. Estimate the minimum time required to reduce the depth of the plate by 20 mm if the tool moves at 400 mm per second.

Answer:

T_{min} = 26 mins 40 secs

Explanation:

Reduction in depth, Δd = 20 mm

Depth of cut, d_c = 0.5 mm

Number of passes necessary for this reduction, n = \frac{\triangle d}{d_c}

n = 20/0.5

n = 40 passes

Tool width, w = 5 mm

Width of metal plate, W = 200 mm

For a reduction in the depth per pass, tool will travel W/w = 200/5 = 40 times

Speed of tool, v = 100 mm/s

Time/pass = \frac{40*400}{400} \\Time/pass = 40 sec

minimum time required to reduce the depth of the plate by 20 mm:

T_{min} = number of passes * Time/pass

T_{min} = n * Time/pass

T_{min} = 40 * 40

T_{min} =  1600 = 26 mins 40 secs

3 0
4 years ago
Read 2 more answers
1. A flywheel is suspended by resting the inside of the rim on a horizontal knife edge so that the wheel can swing in a vertical
sammy [17]

Answer: A fly wheel having a mass of 30kg was allowed to swing as pendulum about a knife edge at inner side of the rim as shown in figure.

Explanation:

8 0
3 years ago
Steel balls 12 mm in diameter are annealed by heating to 1150 K and then slowly cooling to 400 K in an air environment for which
luda_lava [24]

Answer:

It will take the steel 425.925sec to cool from 1150k to 400k

Explanation:

Detailed explanation and calculation is shown in the image

6 0
3 years ago
What is the most likely cause a brake light staying on?
Monica [59]
The answer is either a or b
8 0
3 years ago
Other questions:
  • You are designing a system for a real-time application in which specific deadlines must be met. Finishing the computation faster
    10·1 answer
  • Explain the purpose of the checkpoint mechanism. How often should checkpoints be performed?How does the frequency of checkpoints
    6·1 answer
  • 4. A person is standing 4 miles east from his house. He travels 2 miles east. a. Calculate the initial displacement. b. Calculat
    13·1 answer
  • Energy is generated uniformly in a 6 cm thick wall. The steady-state temperature distribution
    11·1 answer
  • Asolid rectangular rodhas a length of 90mm, made of steel material (E =207,000 MPa, Syield= 300 MPa), the cross section of the r
    14·1 answer
  • Which of these is shown in the photo below?
    8·1 answer
  • Create a story with nuclear engineer (not so long and not so short)
    13·1 answer
  • 762 321 7635<br><br> Password: Qzz9Vg<br><br> zoom
    13·2 answers
  • it creates parts from thin plastic sheets as opposed to plastic pellets. is it 1. Pickling 2. Thermoforming 3. Extrusion​
    13·2 answers
  • To properly purge water from the fuel system of an aircraft equipped with fuel tank sumps and a fuel strainer quick drain, it is
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!