Question

A) Fix any errors to get the following program to run in your environment.               B)...

A) Fix any errors to get the following program to run in your environment.              

B) Document each line of code with comments and describe 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.

Program 3

#include <iostream>
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;
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer A and B)

Program code to copy:

// header file
#include <iostream>
using namespace std;

// Function declaration for m()
void m(int, int []);
// function that sets the first element of list as 100
void p(int list[], int arraySize)
{
list[0] = 100;
}

// main function
int main()
{
int x = 1; // defining int variable x
int y[10]; // declaring int array y[] of size 10
y[0] = 1; // setting first element of y as 1.
// calling function m with parameters x and y
// this will set y[0] = 5555
m(x, y);
// displaying the results after function call m(x,y)
cout << "x is " << x << endl;
cout << "y[0] is " << y[0] << endl;
// exit
return 0;
}

// function that sets the first element
// of integer array numbers[0] = 5555
void m(int number, int numbers[])
{
number = 1001;
numbers[0] = 5555;
}

Sample output:

x is 1 y[0] is 5555

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

Answer C)

Summary of final version of the program:

First, integer variable x is declared and is set to 1. Next, integer array y[ ] is declared & the first element of the array y[ ] is set to be 1. Next, function m(x,y) is called which sets the first element of the array y[ ] to be 5555. Finally, the values of x and y[0] are displayed which are 1 and 5555 respectively.

Add a comment
Know the answer?
Add Answer to:
A) Fix any errors to get the following program to run in your environment.               B)...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++, Will Upvote: A) Try to get the following programs to run in your environment. B)...

    C++, Will Upvote: A) Try to get the following programs to run in your environment. B) If the programs will run, document each line of code with comments and describe any changes you had to make to the original code to get it to work. If the programs are unable to be modified to run with desirable results, explain why you think so. C) Description your solution and a synopsis of how your code is intended to work and the...

  • C++ problem. Please just find and fix the errors and highlight it afterwards. Do not add...

    C++ problem. Please just find and fix the errors and highlight it afterwards. Do not add any new comments or remove comments from teachers. Thank you very much *R 2B PROGRAM 1B: INSERTION SORT Find and rix errors. Ron the program once and save the outpat as a conment at the end of the source file Changed by: IDE #include <iostream> using namespace std: void insertionSort (int aryll, int size) int main double list(1001-(50.1, 30.2, 80.3, 10.5, 30.2, 40.9, 90.8,...

  • Consider the following C++code snippet and what is the output of this program? # include<iostream> using...

    Consider the following C++code snippet and what is the output of this program? # include<iostream> using namespace std; void arraySome (int[), int, int); int main () const int arraysize = 10; int a[arraysize]-1,2,3,4,5, 6,7,8,9,10 cout << "The values in the array are:" << endl; arraySome (a, 0, arraySize) cout<< endl; system ("pause") return 0; void arraySome (int b[], int current, int size) if (current< size) arraySome (b, current+1, size); cout << b[current] <<""; a) Print the array values b) Double...

  • C++ class 3.2.4: If-else statement: Fix errors. Re-type the code and fix any errors. The code...

    C++ class 3.2.4: If-else statement: Fix errors. Re-type the code and fix any errors. The code should convert non-positive numbers to 1. if (userNum > 0) cout << "Positive." << endl; else cout << "Not positive, converting to 1." << endl; Answer #include using namespace std; int main() { int userNum; cin >> userNum; /* Your solution goes here */ return 0; userNum = 1; cout << "Final: " << userNum << endl;

  • //This program is your final exam. //Please fill in the functions at the bottom of the...

    //This program is your final exam. //Please fill in the functions at the bottom of the file. (evenCount and insertItem) //DO NOT CHANGE ANYTHING ELSE. //main has all the code needed to test your functions. Once your functions are written, please build and make sure it works fine //Note that in this case, the list is not sorted and does not need to be. Your goal is to insert the number in the given position. #include <iostream> #include <fstream> using...

  • //This program is your final exam. //Please fill in the functions at the bottom of the...

    //This program is your final exam. //Please fill in the functions at the bottom of the file. (evenCount and insertItem) //DO NOT CHANGE ANYTHING ELSE. //main has all the code needed to test your functions. Once your functions are written, please build and make sure it works fine //Note that in this case, the list is not sorted and does not need to be. Your goal is to insert the number in the given position. #include <iostream> #include <fstream> using...

  • When I run this code use ./main How to fix it when program reminds segmentation fault...

    When I run this code use ./main How to fix it when program reminds segmentation fault (core dumped)? #include <iostream> void set_num(int* i_prt, int num) { *i_prt = num; } int main(int argc, char** argv) { int x; set_num(&x, 13); std::cout << "x: " << x << std::endl; int* y; set_num(y, 4); std::cout << "*y:" << *y << std::endl; }

  • There are many problems with the program below. Describe 5 of these problems in detail. For...

    There are many problems with the program below. Describe 5 of these problems in detail. For each, also explain how you could fix or avoid the issue. #include <iostream> using namespace std; class Duck { public: virtual void quack() { cout << "Quack" << endl; } }; class RubberDuck : public Duck { public: RubberDuck() { array = NULL; } RubberDuck(int size) { array = new int[size]; array[0] = 1; array[1] = 2; array[2] = 3; } ~RubberDuck() { delete...

  • C++ Type in the above program . Before running the program, change each of the question...

    C++ Type in the above program . Before running the program, change each of the question marks to the numbers 1 through 5 indicating the order in which that line will be executed. Run the program and check your numbers. Fix and rerun if necessary. Submit the program and the output. #include <iostream> using namespace std; //prototypes void DemonstrateProc1(); void DemonstrateProc2(int num); int main() { cout << "?. Execution starts with main. " << endl; DemonstrateProc1();       cout << "?....

  • 15.6: Fix the code to print the count from 1 to x (to loop x times)...

    15.6: Fix the code to print the count from 1 to x (to loop x times) #include <iostream> // include the header file using namespace std; void count(int x){    for(int i=1; i<=x; i++){ cout<<x; } } int main(){    int x,i;    cin >> x; count(x);    return 0; } 15.7 Fix the nested for loops to print the count from 1 to x twice, e.g. "12....x12.....x" #include <iostream> // include the header file using namespace std; int main(){...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT