//Maxwell Brewer CS1A Chapter 10, p. 591, #15
//
/*******************************************************************************
* ANALYZE TEXT FILE CHARACTERS
* (MODIFIED FOR USER INPUT INSTEAD OF READING FROM A FILE)
* _____________________________________________________________________________
* This program performs a statistical analysis of uppercase letters,
* lowercase letters, and numeric digits from the input and will most likely
* be critisized by professor Argila.
*
* 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 <iomanip>
#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 << "Enter a string:\n\n";
getline(cin, userInput);
// Call the function to calculate statistics
Cal_Statistics(userInput, uppercase, lowercase, digit);
// Display the calculated statistics
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++;
}
}
}