Programming Exercise: Basic Tools
In this exercise we will perform some basic warmups. This is all
CS 10 or 12 material.
3 points
- Create an array of 5 strings in your main function.
- Write a function int maxLen(string strings[], int size)
that takes an array of strings and returns the length of the longest
string.
- Write a function int maxLenIndex(string strings[], int
size) that takes an array of strings and returns the index of the
longest string.
- Write a function void rotate(string strings[], int size)
that takes an array of strings and "rotates" the array by one place.
Thus, the array ["hello", "my", "name", "is", "bob"] would become
["my", "name", "is", "bob", "hello"].
- Write a function void remove(string strings[], int size, int
pos) that removes the string at position pos from the array
strings and moves everything after it in the array forward. If
you called remove(a, 5, 1) on the array ["abc", "def", "efg",
"hij", "klm"], the array would become ["abc", "efg", "hij", "klm"].
Extra Credit Options
- 1 point: Rewrite all of these functions to use vectors instead
of arrays.
- 1 point: Rewrite all of these functions to use lists instead of
arrays.
- 2 points: Rewrite these functions using recursion