Question
Part A) Complete the function SearchChars() that has one string parameter and one character parameter. The function returns the number of characters in the string
Part A)
Complete the function SearchChars() that has one string parameter and one character parameter. The function returns the number of characters in the string that are equal to the character parameter.
Ex: If the input is pvqt q, then the output is:
1
#include
int SearchChars(string inputString, char x) {
/* Your code goes here */
}
int main() { string inputString; char x; int result;
cin >> inputString; cin >> x;
result = SearchChars(inputString, x);
cout << result << endl;
return 0; }
Part B)
Define a function CheckSum() that takes one integer vector parameter and one integer parameter. The function computes the sum of the vector's elements. Then, the function returns true if the sum is greater than the integer parameter, and returns false otherwise.
Ex: If the input is:
4 -9 4 -10 3 -9
then the vector has 4 elements {-9, 4, -10, 3}, and the integer parameter is -9. The output is:
False, the sum of all the elements is not greater than -9.
#include
/* Your code goes here */
int main() { vector
// Read the vector's size, and then the vector's elements cin >> size; for (i = 0; i < size; ++i) { cin >> input; inVector.push_back(input); }
cin >> x;
result = CheckSum(inVector, x);
if (result) { cout << "True, the sum of all the elements is greater than " << x << "." << endl; } else { cout << "False, the sum of all the elements is not greater than " << x << "." << endl; }
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started