Question: (I need help completing this program. I'm simply trying to complete the ones that say //TODO. You can ignore the gold problem if you want

(I need help completing this program. I'm simply trying to complete the ones that say //TODO. You can ignore the gold problem if you want to. Overall, It keeps giving me errors. Also, it's in c++)

main.cpp:

#include #include "swap.h"

using namespace std; int main(int argc, char const *argv[]) { int foo[5] = {1, 2, 3, 4, 5};

cout << "Addresses of elements:" << endl; //TODO Print the addresses of array elements

cout << endl;

cout << "Elements:" << endl;; //TODO Print all the elements using pointers

cout << endl;

int a,b; int f; int flag = 1; while(flag == 1){ cout<<"Enter indices of elements you want to swap?"<>a; cout<<"Second index"<>b; cout<<"Enter 0 for pass-by-value, 1 for pass-by-pointer"<>f;

switch (f) { case 0: // Pass by Value // Compare the resultant array with the array you get after passing by pointer cout << "Before swapping" << endl; for(int i = 0;i<5;i++){ cout<

swap(foo[a],foo[b]);

cout << " After swapping" << endl; for(int i = 0;i<5;i++){ cout<

case 1: // Pass by pointer cout << "Before swapping" << endl; for(int i = 0;i<5;i++){ cout<

// TODO complete the function in swap.cpp file swap_by_pointers(&foo[a],&foo[b]);

cout << " After swapping" << endl; for(int i = 0;i<5;i++){ cout<

} cout<> flag; }

cout << "Reversing the array"; // Reverse your array // TODO complete the function in swap.cpp file reverse(foo,5);

cout << " After reversing" << endl; for(int i = 0;i<5;i++){ cout<

// GOLD problem // Cumulative sum of the array // TODO call this function cumulative_sum properly so that it passes the array 'foo' // and updates 'foo' with cumulative summation. // After this function call, you will get the updated array here // TODO complete the function declaration in swap.h file // TODO complete the function in swap.cpp file // cumulative_sum(,5);

cout << " After cumulative summation" << endl; for(int i = 0;i<5;i++){ cout<

return 0; }

swap.cpp:

#include "swap.h"

// Function definitions // Pass By Value void swap(int n1, int n2) { int temp; temp = n1; n1 = n2; n2 = temp; }

// Pass By Pointer void swap_by_pointers(int *n1, int *n2) { // TODO Complete this function }

// Function to reverse the array through pointers void reverse(int array[], int array_size) { // pointer1 pointing at the beginning of the array int *pointer1 = array;

// pointer2 pointing at end of the array int *pointer2 = array + array_size - 1; // TODO Use the above swap function and update pointers to reverse your array //while (pointer1 < pointer2) {

//} }

// GOLD problem // Function to do cumulative sum of the array // void cumulative_sum(, int array_size) // { // int i = 1; // // TODO // // }

swap.h:

// Header file for Function declarations

void swap(int, int); void swap_by_pointers(int*, int*); void reverse(int array[], int array_size);

// Complete the function declaration here for gold problem // void cumulative_sum(, int array_size);

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!