//Maxwell Brewer CS1A Chapter 10, p. 591, #15
//
/*******************************************************************************
* STATISTICAL ANALYSIS OF TEXT FILE CHARACTERS
* (MODIFIED FOR USER INPUT INSTEAD OF READING FROM A FILE)
* _____________________________________________________________________________
* This program reads a string entered by the user and performs a statistical
* analysis of its content. Specifically, it calculates the number of
* uppercase letters, lowercase letters, and numeric digits in the input.
*
* INPUT:
* userInput : A string entered by the user.
*
* OUTPUT:
*
* : The total count of uppercase letters.
* : The total count of lowercase letters.
* : The total count of numeric digits.
*
******************************************************************************/
#include <iostream>
#include <string>
using namespace std;
// Function prototype
void Cal_Statistics(const string &input, unsigned &uppercase,
unsigned &lowercase, unsigned &digit);
int main() {
// Variables to hold statistics
unsigned uppercase = 0, lowercase = 0, digit = 0;
// Variable to hold user input
string userInput;
cout << "==============================================\n";
// Prompt the user to enter a string
cout << "Please enter a string:\n";
getline(cin, userInput);
// Call the function to calculate statistics
Cal_Statistics(userInput, uppercase, lowercase, digit);
// Display the calculated statistics
cout << "\n\t\t:: Results ::\n";
cout << "Uppercases : " << uppercase << "\n";
cout << "Lowercases : " << lowercase << "\n";
cout << "Digits : " << digit << "\n";
return 0;
}
// Function to calculate statistics
void Cal_Statistics(const string &input, unsigned &uppercase,
unsigned &lowercase, unsigned &digit) {
for (char ch : input) {
if (isupper(ch)) {
uppercase++;
} else if (islower(ch)) {
lowercase++;
} else if (isdigit(ch)) {
digit++;
}
}
}