Answer to Question #87339 in C++ for iss

Question #87339
Declare a string array of size 5. Prompt the user to enter five strings that are stored in the array. Afterward, prompt the user to enter a character. Write a function that expects the following three parameters: an array, the size of the array, and a char. The function counts the number of occurrences of that chain all of the strings stored in the array and returns it. Call that function from the main and output the returned value.
1
Expert's answer
2019-04-05T07:36:07-0400
#include <iostream>
#include <cstring>

using namespace std;

int checker(string [], int, char);

int main() {
string arr[5];
	for(int i = 0; i < 5; i++) {
		cout << "Please, enter " << i + 1 << "string: ";
		getline(cin, arr[i]);
	}
char ch;
	cout << "Enter symbol: ";
	cin >> ch;
	cout << "Quantity of symbol " << ch << " is " << checker(arr, 5, ch);
return 0;
}

int checker(string str[], int a, char ch) {
int number = 0;	
	for (int i = 0; i < a; i++) {
	    int len  = str[i].length();
		for (int j = 0; j < len; j++) {
			if (str[i][j] == ch)
				number++;
		}
	}
return number;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS