C++
The purpose of this exercise is to create a function which removes elements from an array, another function which either increases or decreases a specific element in an array by a specified amount, and a third function which prints the message contained in the of the array. First create a function with the following heading. (Code circled in red dashes cannot be cut-and- pasted.) int remove (char array[], int count, int remove_index) This function should remove the element at remove_index in the array by moving all of the elements after it down one position in the array, then reduced the number of elements in the array by 1. 1. if count is equal to 0 or if remove_index is greater than or equal to count, then just return count unchanged (indicating that no element was removed), 2. Otherwise use a for loop to move all of the elements "down" one position in the array. For example, the element at position remove_index will be replaced by the element at (remove_index + 1), then the element at (remove_index + 1) will be replaced by the element at (remove_index + 2), etc. 3. Set the element at the last position in the array to 0. 4. Return count - 1 (the new number of characters in the message in the array). Write another function with the heading: void update (char array(), char amount, int index) This function adds amount to the char at position index in the array. The value in amount can be either positive or negative. The last function simply prints the contents of the array on the screen, preceded by a heading: void showArray (string heading, char array[], int count)
In main, do the following: 1. Create an array of char elements named message using the initialization list {'t', 'Q', 'b', ')', 'f' '+', '5'} 2. Declare and initialize the variable count, representing the number of characters actually used in the array, using the formula: int count = sizeof (message) / sizeof (char) ; Using your remove, update, and display functions: 3. print the initial contents of the array (the "message") 4. remove the character at position (index) 3 in the message (this should decrease the count of the number of characters in the message by 1) 5. subtract 14 from the character currently at position 1 in the message 6. remove character at position 0 in the message 7. remove the character at position 2 in the message 8. subtract 55 from the character at position 1 in the message 9. remove the last character in the message 10. print the message As a debugging tool, you might use the showArray function to help find errors in your code.
C++
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am