/* This program demonstrates * 1. Reading and printing array values * 2. Working with arrays and functions. * 2.a: Linear Search * 2.b: Left Array Shift * a.c: Right Array Shift * * Arrays can be passed into function like regular variables. * However, arrays always pass by reference. So any changes made to the array * in the function will be preserved across the function call and will be refected * in main, or any other calling function. */ #include #include using namespace std; /* Declare the functions here * when we pass an array into the function, we don't have to mention the size * the array. Mentioning it won't result in an error, but it is not necessary. * However, we have to specify it is an array, by using the [] * * Function names are self-descriptive here. They are described while being defined. */ int linearSearch(double arr[], int size, double key); void leftArrayShift(double arr[], int size); void rightArrayShift(double arr[], int size); int main() { double arr[10]; // declare the array const int NUM = 10; //accept array values from the user cout<<"\nEnter values for the array: "; for(int i=0; i<10; i++) { cin>>arr[i]; } double searchVal; int foundPos; cout<<"Enter the search value: "; cin>>searchVal; //call the function, store the returned value in "found" foundPos = linearSearch(arr, NUM, searchVal); if( foundPos == -1) cout<<"The element is not in the array"<0; i--) { arr[i] = arr[i-1]; } arr[0] = 0; }