Interpret a Program and Explain How it Works

IDEAL PM
 (Not rated)
 (Not rated)
Chat

In the textbook, on page 400, solve problem 7.18: What does the following program do?. Copy the sample program and compile it, then find the results. Submit a report which is more than one page length to explain how the program works and how you can improve it. Your report should be formatted according to APA style as outlined in the Ashford Writing Center. Write comments in C++ comments format in the source file, to explain what the functions are and how they work. Submit your source code file and the executable file by Day 7.

 

//Ex. 7.18: Ex07_18.cpp

//What does this program do?

#include <iostream>

using std::cout;

using std::endl;

 

int whatIsThis ( int [], int); //function protoype

 

int main()

 

{

                const int arraySize = 10;

                int a [arraySize] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

               

                int result = whatIsThis (a,arraySize);

               

                cout << "Results is " <<result << endl;

                return 0; //indicates successful termination

} // end main

 

//What does this function do?

int whatIsThis ( int b[], int size)

{

if (size == 1) // base case

return b [0];

else // recursive step

return b [size-1]+ whatIsThis (b, size - 1);

} // end function whatIsThis

    • 10 years ago
    PERFECT ANSWER
    NOT RATED

    Purchase the answer to view it

    • interpret_a_program_and_explain_how_it_works_2.docx