Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Get the following C + + code, , INCLASS 0 3 . cpp , from Blackboard. Place it into a Dev - C + +

Get the following C++ code, , INCLASS03.cpp, from Blackboard. Place it into a Dev-C++ project. The program will compile and run (though not quite correctly).
/*
CIS 251 In Class Assignment
This program performs various operations on a ten
element int array.
*/
#include
using namespace std;
void start (int boxes [10]);
void move (int squares [10], int x, int y, int z);
void add (int arr [10], int first, int last);
void print (int arr [10]);
int main ()
{
int my_arr [10];
cout << "The original array is:
";
print (my_arr);
start (my_arr);
cout <<"
The array after start is:
";
print (my_arr);
move (my_arr, 2,4,6);
cout <<"
The array after move is:
";
print (my_arr);
add (my_arr, 3,7);
cout <<"
The array after add is:
";
print (my_arr);
cout <<"
";
return 0;
}
void start (int boxes [10])
{
int index, count;
count =17;
for (index =0; index <10; index++)
{
boxes [index]= count;
count--;
}
}
void move (int squares [10], int x, int y, int z)
{
int temp;
temp = squares [x];
squares [x]= squares [y];
squares [z]= squares [y];
squares [y]= temp;
}
void add (int arr [10], int first, int last)
{
int m;
for (m = first; m <= last; m++)
arr [m]++;
}
void print (int arr [10])
{
int z;
for (z =0; z <10; z++)
cout << z <<"";
}
Questions and Experiments:
1. The function print is supposed to print each element of the array but does not work. What does it print?
Fix the print function so that it works properly.
2. Now that print has been fixed, run your program again. Why did funny values show up for the first call to print?
3. The array has different names in the functions than it does in main. Explain why this is not a problem.
4. Would the program still work if the array had the same name in the functions as in main?
5. What values would be placed in the array by the function start if count was initially set equal to 0 instead of 17? Show the values.
6. Remove the {} associated with the for statement in the function start. Run your program and explain clearly why the output changes as shown.
Add the {} back to the program.
7. Say that we have an array, my_arr, with the following values:
5934612192234
[0][1][2][3][4][5][6][7][8][9]
and the function move is called as follows:
move (my_arr, 1,3,5);
Show above how this call would change the array.
8. Explain clearly what the function add does. Include the parameters first and last in your explanation.
9. How would add change the array if called as follows:
add (my_arr, 7,2);
Explain your answer.
Add a function prototype and definition for a function called print_reverse to your program. print_reverse takes an array as a parameter and prints the array values in reverse order. Have your program call this function after the last print. Have main print a label indicating that the array is being printed in reverse before the call.

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

Step: 3

blur-text-image

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

Professional Visual Basic 6 Databases

Authors: Charles Williams

1st Edition

1861002025, 978-1861002020

More Books

Students also viewed these Databases questions

Question

Challenges Facing Todays Organizations?

Answered: 1 week ago