Please assist me with the Code and the answers to the questions.
Posted: Wed Apr 27, 2022 5:07 pm
Please assist me with the Code and the answers to the
questions.
Program works with arrays using pointers to reference elements instead of indexes. */ #include <cstdlib> #include <iostream> using namespace std; = int main(int argc, char *argv[]) { // initialize a 1 dimensional array int arr [10] {2, 4, 5, 6, 7, 8, 9, 10, 11, 13}; // pointer that moves thru an array to visit elements int *mover, *last;// a pointer to the last element of the array int n; // n is a step size for moving thru the array 1 last = cout << "The array in forward direction is:\n"; // print array in forward direction for (mover = arr; mover <= last; mover++) cout << *mover << " "; cout << "\n\nThe array addresses in forward are:\n"; // print the array addresses in forward order 2 cout << "\n\nThe array in reverse direction is:\n"; // print array in reverse direction 3 cout << "\n\nEvery second element of the array is: \n";
// print every second element of the array 4 cout << "\n\nEnter an array step: "; cin >> n; cout << "\nEvery nth element of the array is: \n"; // print every nth element of the array 5 cout << "\n\n"; return 0; } * Make the following changes to your program at the indicated spots (you should not use indexes anywhere in the program, only pointers): 1. Assign the address of the last element of the array to last. 2. Add code that prints the addresses of the array elements separated by spaces. 3. Add code that prints the values in the array in reverse order. 4. Add code that prints the every second value of the array.
5. Add code that prints every nth value of the array (where n is given by the user). 6. Submit your completed Lab6.cpp file on Blackboard. * Answer the following questions: 1. Change the Boolean expression in the for loop for printing forward direction values to mover >= last. Run the program. What happens? Explain clearly why. Change the program back. 2. Change the increment in the for loop for printing forward direction values to mover Run the program. Let it continue to run for 97 seconds. What happens? Explain clearly why. Change the program back.
Change the program back. 3. How far apart are the address values in the array? 4. Why does the answer to 3. make sense for the given array? 5. Change the type of the array to double and compile your program. Explain clearly why compiler errors occur. | 6. Fix the program so that it works for a double value array. What change did you need to a make?
7. Run the program. What part of the program output is different and why? YOUR RÉSUMÉ SAYS YOU'RE A MULTI- CELLED LIFE FORM. scottadame Daol.com THAT'S EXACTLY WHAT WE'RE LOOKING FOR! I'M TRYING TO SHAKE HANDS. IF YOU FEEL HARASSED IN ANY WAY JUST LET OUT A YELP. 9/10 2009 United Feature Syndicate, Inc. www.dilbert.com
questions.
Program works with arrays using pointers to reference elements instead of indexes. */ #include <cstdlib> #include <iostream> using namespace std; = int main(int argc, char *argv[]) { // initialize a 1 dimensional array int arr [10] {2, 4, 5, 6, 7, 8, 9, 10, 11, 13}; // pointer that moves thru an array to visit elements int *mover, *last;// a pointer to the last element of the array int n; // n is a step size for moving thru the array 1 last = cout << "The array in forward direction is:\n"; // print array in forward direction for (mover = arr; mover <= last; mover++) cout << *mover << " "; cout << "\n\nThe array addresses in forward are:\n"; // print the array addresses in forward order 2 cout << "\n\nThe array in reverse direction is:\n"; // print array in reverse direction 3 cout << "\n\nEvery second element of the array is: \n";
// print every second element of the array 4 cout << "\n\nEnter an array step: "; cin >> n; cout << "\nEvery nth element of the array is: \n"; // print every nth element of the array 5 cout << "\n\n"; return 0; } * Make the following changes to your program at the indicated spots (you should not use indexes anywhere in the program, only pointers): 1. Assign the address of the last element of the array to last. 2. Add code that prints the addresses of the array elements separated by spaces. 3. Add code that prints the values in the array in reverse order. 4. Add code that prints the every second value of the array.
5. Add code that prints every nth value of the array (where n is given by the user). 6. Submit your completed Lab6.cpp file on Blackboard. * Answer the following questions: 1. Change the Boolean expression in the for loop for printing forward direction values to mover >= last. Run the program. What happens? Explain clearly why. Change the program back. 2. Change the increment in the for loop for printing forward direction values to mover Run the program. Let it continue to run for 97 seconds. What happens? Explain clearly why. Change the program back.
Change the program back. 3. How far apart are the address values in the array? 4. Why does the answer to 3. make sense for the given array? 5. Change the type of the array to double and compile your program. Explain clearly why compiler errors occur. | 6. Fix the program so that it works for a double value array. What change did you need to a make?
7. Run the program. What part of the program output is different and why? YOUR RÉSUMÉ SAYS YOU'RE A MULTI- CELLED LIFE FORM. scottadame Daol.com THAT'S EXACTLY WHAT WE'RE LOOKING FOR! I'M TRYING TO SHAKE HANDS. IF YOU FEEL HARASSED IN ANY WAY JUST LET OUT A YELP. 9/10 2009 United Feature Syndicate, Inc. www.dilbert.com