0% found this document useful (0 votes)
9 views1 page

D Que4.cpp

The document contains a C++ program that defines a function to count how many strings in a given array start with the letter 'a' or 'A'. It prompts the user to input the size of the array and the strings, then outputs the count of those strings. The function iterates through the array and checks the first character of each string to determine the count.

Uploaded by

sidgft1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views1 page

D Que4.cpp

The document contains a C++ program that defines a function to count how many strings in a given array start with the letter 'a' or 'A'. It prompts the user to input the size of the array and the strings, then outputs the count of those strings. The function iterates through the array and checks the first character of each string to determine the count.

Uploaded by

sidgft1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <bits/stdc++.

h>
/**
* This function calculates the count of all the elements in B having 'A' or 'a' as
their first character.
*
* Parameters:
* N (INTEGER): The size of the array B.
* B (STRING ARRAY): The given string array.
*
* Returns:
* INTEGER: The number of strings in the array B that start with 'a' or 'A'.
*/
int spotAstring(int N, std::vector<std::string> B) {
int count = 0;
for (int i = 0; i < N; i++) {
if (B[i][0] == 'a' || B[i][0] == 'A') {
count++;
}
}
return count;
}

int main() {
int N;
std::cout << "Enter the size of the array: ";
std::cin >> N;

std::vector<std::string> B(N);
std::cout << "Enter the strings: ";
for (int i = 0; i < N; i++) {
std::cin >> B[i];
}

int count = spotAstring(N, B);


std::cout << "Number of strings starting with 'a' or 'A': " << count <<
std::endl;

return 0;
}

You might also like