Answered step by step
Verified Expert Solution
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, INCLASScpp from Blackboard. Place it into a DevC project. The program will compile and run though not quite correctly
CIS In Class Assignment
This program performs various operations on a ten
element int array.
#include
using namespace std;
void start int boxes ;
void move int squares int x int y int z;
void add int arr int first, int last;
void print int arr ;
int main
int myarr ;
cout "The original array is:
;
print myarr;
start myarr;
cout
The array after start is:
;
print myarr;
move myarr, ;
cout
The array after move is:
;
print myarr;
add myarr, ;
cout
The array after add is:
;
print myarr;
cout
;
return ;
void start int boxes
int index, count;
count ;
for index ; index ; index
boxes index count;
count;
void move int squares 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 int first, int last
int m;
for m first; m last; m
arr m;
void print int arr
int z;
for z ; z ; z
cout z ;
Questions and Experiments:
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.
Now that print has been fixed, run your program again. Why did funny values show up for the first call to print?
The array has different names in the functions than it does in main. Explain why this is not a problem.
Would the program still work if the array had the same name in the functions as in main?
What values would be placed in the array by the function start if count was initially set equal to instead of Show the values.
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.
Say that we have an array, myarr, with the following values:
and the function move is called as follows:
move myarr, ;
Show above how this call would change the array.
Explain clearly what the function add does. Include the parameters first and last in your explanation.
How would add change the array if called as follows:
add myarr, ;
Explain your answer.
Add a function prototype and definition for a function called printreverse to your program. printreverse 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started