Writing a c++ program using visual studio

profilershrestha
COSC1436Lab6-ArraysLabc.docx

Arrays Lab C++

This lab has several parts, each worth an equal amount of credit. Please put all three parts into one file. Title it (ArrayLab_Rameshwar Shrestha), and comment the code appropriately to distinguish different parts of the lab:

1) Create a function call sumArray which will return the sum of an array that is passed in. Note that a length of the array should also be specified. input: arr={1, 2, 3, 4}, length=3 returns: 6 (because the 4 was ignored because it was past the length)

2) Create a function call convertToDecimal. This method will take an int array { 3, 2, 4 } and a length of the array, and will return a single integer where each part of the array is a digit in the new integer (324). To do this you will need to multiply: 3*10^2 + 2*10^1 + 4*10^0 = 324 add an optional parameter that allows it to take a base to multiply it to such as base 2 or base 8 (in the example I’m using base 10 of course).

3) Write a function printAccending, that will take an int array and the length as its input and output each integer on a line that is greater than the last. If one is smaller it will drop to a new line and continue from there: input {2, 5, 8, 3, 9, 9, 7} output: 2, 5, 8 3, 9, 9 7

4) Write a function reverseArrayEven which will loop through a given array (with a size provided as well), and will reverse the digits if they are even numbers. input: {1, 2, 4, 5, 6, 9, 10} returns: {10, 9, 4, 5, 6, 2, 1}

5) Write a function to search a 2-dimentional array for a value. The method should take a reference to a row and col integer, and if the value is found then set the row and col variables accordingly. If the value is not found row and col should both equal -1. Note that lengths of the array should also be taken as input. input: {{1,2,3},{4,5,6},{7,8,9}}, inputRow=3, inputCol=3, foundRow&, foundCol&, searchValue=6 after function completes: foundRow = 1, foundCol=2