Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 using namespace std;

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 #include using namespace std;

/* Your code goes here */

int main() { vector inVector; int size; int input; int i; int x; bool result;

// 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Implementing Ai And Machine Learning For Business Optimization

Authors: Robert K Wiley

1st Edition

B0CPQJW72N, 979-8870675855

More Books

Students also viewed these Databases questions