Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What is the output of the following code? Assume all other necessary and relevan

ID: 3824001 • Letter: W

Question

What is the output of the following code? Assume all other necessary and relevant C++ code is present in the program, it’s just not shown below. Add a comment to every line of code. Hint: make a table of values for jack

void someFunction( const array< int, 5 > &a, int b );

int main(){

array< int, 5 > jack;

for( int x = 0; x < jack.size(); x++ ){

jack[ x ] = 100 / (x+1); }

someFunction( jack, 0 );

return 0; }

void someFunction( const array< int, 5 > &a, int current ) {

if( b < a.size() ){

cout << a[ current ] << “ “;

someFunction( a, current+1 ); }

}

Explanation / Answer

Answer: 100 50 33 25 20

void someFunction( const array< int, 5 > &a, int b ); // function prototype

int main(){

array< int, 5 > jack; //declaraing jack type integer array

for( int x = 0; x < jack.size(); x++ ){ //looping from 0 to jack array size 5

jack[ x ] = 100 / (x+1); } //filling the array with value in each iteration.

someFunction( jack, 0 );//calling this function with jack array and first index of an array

return 0; }

void someFunction( const array< int, 5 > &a, int current ) {

if( b < a.size() ){ // check whether current position of an array is less than the array size

cout << a[ current ] << “ “; //displaying the array value based on index

someFunction( a, current+1 ); }//calling this funtion again with index incremented by 1

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote