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
PLEASE HELP, THANK YOU
Elena L [17]

Answer:

6,3,2,5,1,4 because they jst are

Explanation:

3 0
3 years ago
WHAT IS MEANT BY BJT AND FUNCTION OF BJT
Andrej [43]

Answer:

A Bipolar Junction Transistor, or BJT, is a solid-state device in which the current flow between two terminals (the collector and the emitter) is controlled by the amount of current that flows through a third terminal (the base).

The main basic function of a BJT is to amplify current it will allow BJTs are used as amplifiers or switches to produce wide applicability in electronic equipment include mobile phones, industrial control, television, and radio transmitters. There are two different types of BJTs are available, they are NPN and PNP.

8 0
3 years ago
Find the largest number. The process of finding the maximum value (i.e., the largest of a group of values) is used frequently in
salantis [7]

Answer:

See Explanation

Explanation:

Required

- Pseudocode to determine the largest of 10 numbers

- C# program to determine the largest of 10 numbers

The pseudocode and program makes use of a 1 dimensional array to accept input for the 10 numbers;

The largest of the 10 numbers is then saved in variable Largest and printed afterwards.

Pseudocode (Number lines are used for indentation to illustrate the program flow)

1. Start:

2. Declare Number as 1 dimensional array of 10 integers

3. Initialize: counter = 0

4. Do:

4.1 Display “Enter Number ”+(counter + 1)

4.2 Accept input for Number[counter]

4.3 While counter < 10

5. Initialize: Largest = Number[0]

6. Loop: i = 0 to 10

6.1 if Largest < Number[i] Then

6.2 Largest = Number[i]

6.3 End Loop:

7. Display “The largest input is “+Largest

8. Stop

C# Program (Console)

Comments are used for explanatory purpose

using System;

namespace ConsoleApplication1

{

   class Program

   {

       static void Main(string[] args)

       {

           int[] Number = new int[10];  // Declare array of 10 elements

           //Accept Input

           int counter = 0;

           while(counter<10)

           {

               Console.WriteLine("Enter Number " + (counter + 1)+": ");

               string var = Console.ReadLine();

               Number[counter] = Convert.ToInt32(var);

               counter++;                  

           }

           //Initialize largest to first element of the array

           int Largest = Number[0];

           //Determine Largest

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

           {

               if(Largest < Number[i])

               {

                   Largest = Number[i];

               }

           }

           //Print Largest

           Console.WriteLine("The largest input is "+ Largest);

           Console.ReadLine();

       }

   }

}

8 0
3 years ago
A parallel circuit has a resistance of 280 and an inductive reactance of 360 02. What's this circuit's impedance?
Doss [256]

Answer:

540 W

Explanation:

4 0
3 years ago
A dipstick is (a direct,an indirect) measurement device
icang [17]
Direct because it’s going right in the spot it needs to be in
3 0
4 years ago
Other questions:
  • The probability density function of the time to failure of an electronic component in a copier (in hours) is f(x) = (e^-x/1076)/
    6·1 answer
  • A Carnot machine operates with 25% efficiency, whose heat rejection reservoir temperature is 300K. Determine the temperature at
    13·1 answer
  • Following in each of the following three mechanisms, the crank is the input link, 1) draw vectors with labeled angles 2) write t
    11·1 answer
  • A completely mixed activated-sludge process is being designed for a wastewater flow of 10,000 m3/d (2.64 mgd) using the kinetics
    6·1 answer
  • A closed, 5-m-tall tank is filled with water to a depth of 4 m. The top portion of the tank is filled with air which, as indicat
    13·1 answer
  • Three possible career opportunities in embedded systems engineering
    11·1 answer
  • If you are convicted of D.U.I. a second time in five years, your license may be revoked for up to __________ year/s.
    10·1 answer
  • Explain why many sustainable fishing and forestry practice depend on the actions of consumers like you.
    13·2 answers
  • Una frase de: ama la vida quien___________________________________
    6·1 answer
  • A barometer reads a height of 78 cmHg. Express this atmospheric pressure to:
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!