Need help with these array problems.
int countAllPunctuation( const string array[ ], int n
);
Return the total number of punctuation symbols found in all the
elements of the passed array argument. For the purpose of this
function, the characters '.' , ',', '!', ';', ''', '-', '/', ':',
'?', '"' count as punctuation symbols (that is, period, comma,
exclamation mark, semicolon, apostrophe, dash, slash, colon,
question mark, and double quote). Return -1 if n <= 0. For
example, for the array string data[ 4 ] = { "howard-",
"ucla.", "howard", "ucla" }; countAllPunctuation( data, 4 ) should
return the value 2 while countAllPunctuation( data, -14
) should return -1.
int countFloatingPointValues(
const string array[
],int n
);
Return the total number of floating-point values found in all the
array elements of the passed array argument. For the purpose of
this function, a floating-point value should have the form #.#,
where # is one of the digits 0-9. The decimal point is optional but
should only be found once for the element to count as a valid
floating-point value. Return -1 if n <= 0. For example, for the
array string data[ 4 ] = { "4.4.3.3", "44",
"33.098", "33.098a" };
countFloatingPointValues( data, 4 ) should return the
value 2 while countFloatingPointValues( data, -14
) should return -1. According to this
specification, all of the following are valid floatingPointValues:
"1.0", "1", ".0101", "0.0123". What I am after is the
regular expression: (0-9)+(.)?(0-9)* That means one or
more digit characters followed by an optional decimal point
followed by additional optional digit characters.
int removeDuplicatedValues( string array[ ],
int n );
This function should ensure that none of the array elements are the
same. All the non-duplicated values should be kept together at the
front of the array and your function should use "" (the empty
string) to fill out the array as needed. Return the number of
elements which were removed or -1 if the array has no
elements. For example, for the array people[
5 ] shown above, removeDuplicatedValues( people, 5
) should return 0 and the array argument should be
unchanged. However, removeDuplicatedValues( people, -5
) should return -1. And finally, for the
array string data[ 4 ] = { "happy", "days",
"happy", "days" }; removeDuplicatedValues(
data, 4 ) should return the value 2 and the array argument should
be changed to: { "happy", "days", "", "" };
#include <iostream>
#include <string>
using namespace std;
int countAllPunctuation( const string array[], int n );
int main() {
string data[ 4 ] = { "howard-", "ucla.", "howard",
"ucla" };
cout << countAllPunctuation( data, 4 ) <<
endl;
cout << countAllPunctuation( data, -14 )
<< endl;
return 0;
}
int countAllPunctuation( const string array[], int n ) {
int count = 0;
char ch;
if(n <= 0) {
return -1;
}
for(int i = 0; i < n; ++i) {
for(int j = 0; j <
array[i].size(); ++j) {
ch =
array[i][j];
if(ch == '.' ||
ch == ','|| ch == '!'|| ch == ';'|| ch == '\'' || ch == '-'|| ch ==
'/'|| ch == ':'|| ch == '?'|| ch == '"') {
count++;
}
}
}
return count;
}
Need help with these array problems. int countAllPunctuation( const string array[ ], int n ); Return...
Can you make this a function? Thank you. int locationOfMin(const string a[], int n): Return the position of a string in the array such that that string is < = every string in the array. If there is more than one such string, return the smallest position of such a string. Return -1 if the array has no elements. Here's an example: string people[5] = { "samwell", "jon", "margaery", "daenerys" "tyrion" }: int j = locationOfMin(people, 5);//returns 3, since daenerys...
/* Array expander: Write a function that accepts an int array as argument. The function should create a new array that is n times the size of the argument array, where n is a user input. The function should copy the contents of the argument array to the new array, and initialize the unused elements of the second array with 0. The function should return a pointer to the new array */ #include <iostream> using namespace std; const int NUM_ELEM...
(a) Write a recursive function int find(const int A[], int n, int x); which returns the first index i = 0, . . . , n − 1 such that A[i] == x, or n if it is not found. (b) Write a recursive function int rfind(const int A[], int n, int x); which returns the last index i = 0, . . . , n − 1 such that A[i] == x, or n if it is not found....
(C++ program )Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is one element larger than the argument array. The first element of the new array should be set to 0. Element 0 of the argument array should be copied to the element 1 of the new array. Element 1 of the argument array should be copied to element 2 of the new array, and so forth....
Give high level pseudocode for someFunction below: int someFunction(std::string lastName, const Data* array, int size) { return binaryFindLastByLastName(lastName, array, size) - binaryFindFirstByLastName(lastName, array, size) + 1; } // Thanks!
C++ Need the step count for this function. int binarySearch(const int array[], int size, int value) { int first = 0, last = size − 1, middle, position = −1; bool found = false; while (!found && first <= last) { middle = (first + last) / 2; if (array[middle] == value) { found = true; position = middle; } else if (array[middle] > value) last = middle − 1; else first = middle + 1; } return position; }
C++ ONLY Write a function, int flip(string a[], int n); It reverses the order of the elements of the array and returns n. The variable n will be greater than or equal to zero. Example: string array[6] = { "a", "b", "", "c", "d", "e" }; int q = flip(array, 4); // returns 4 // array now contains: "c" "" "b" "a" "d" "e" Write a function, int flip(string a[], int n); It reverses the order of the elements of...
In C++, develop a class that supports array rotation. Rotating an array is an operation where you shift all elements of the array some number of positions left or right, and elements that are shifted off of the left or right end of the array "wrap around" to the right or left end, respectively. For example, if we rotate the array [1, 2, 3, 4, 5] to the right by 1, we get the array [5, 1, 2, 3, 4]....
The function takes three parameters: string array, int arraySize, and string word The function will loop through the string array. If word is found in the array, return the matched element’s position (index) in the array. Otherwise, return -1. When a match is found in the array, the loop should be terminated at the time --- no need to continue the loop. If no match is found, the function should display all elements in the array, as well as the...
Write a function getScores(...) that is given a string, an int type array to fill and the max number of elements in the array as parameters and returns an integer result. The function will find each substring of the given string separated by space characters and place it in the array. The function returns the number of integers extracted. For example: int values[3]; getScores("123 456 789", values, 3 ); would return the count of 3 and fill the array with...