Final answer:
The sample C++ program reads a sentence character by character, counting the number of capital and small letters until it encounters a double quote. It uses the get() function to read input and checks the ASCII value to determine the letter case.
Step-by-step explanation:
Counting Capital and Small Letters in a C++ ProgramWriting a program to count the capital and small letters in a sentence involves reading characters one by one until a terminating character is encountered. In C++, the get() function can be used to read characters from the standard input. To differentiate between capital and small letters, you can use ASCII values where capital letters range from 65 to 90 and small letters range from 97 to 122. Below is a sample program that fulfills the requirements:
#include
using namespace std;
int main() {
char c;
int capitalCount = 0, smallCount = 0;
cout << "Enter a sentence (ending with a double quote '"):";
while (cin.get(c) && c != '"') {
if (c >= 'A' && c <= 'Z')
++capitalCount;
else if (c >= 'a' && c <= 'z')
++smallCount;
}
cout << "Capital letters: " << capitalCount << "\\";
cout << "Small letters: " << smallCount << endl;
return 0;
}
The program will read characters until a double quote is entered, counting each capital and small letter. After entering the terminating character, it will display the counts.To write a C++ program that counts the number of capital letters and small letters in a sentence, you can use the get() function to read the characters of the sentence one by one. You can then check each character using library functions like isupper() and islower(). If a character is uppercase, you increment a counter for capital letters, and if it is lowercase, you increment a counter for small letters. Finally, you display the count of capital letters and small letters using cout.