fork download
  1. //Maxwell Brewer CS1A Chapter 10, p. 591, #15
  2. //
  3. /*******************************************************************************
  4.  * ANALYZE TEXT FILE CHARACTERS
  5.  * (MODIFIED FOR USER INPUT INSTEAD OF READING FROM A FILE)
  6.  * _____________________________________________________________________________
  7.  * This program performs a statistical analysis of uppercase letters,
  8.  * lowercase letters, and numeric digits from the input and will most likely
  9.  * be critisized by professor Argila.
  10.  *
  11.  * INPUT:
  12.  * userInput : A string entered by the user.
  13.  *
  14.  * OUTPUT:
  15.  *
  16.  * : The total count of uppercase letters.
  17.  * : The total count of lowercase letters.
  18.  * : The total count of numeric digits.
  19.  *
  20.  ******************************************************************************/
  21.  
  22. #include <iostream>
  23. #include <iomanip>
  24. #include <string>
  25.  
  26. using namespace std;
  27.  
  28. // Function prototype
  29. void Cal_Statistics(const string &input, unsigned &uppercase,
  30. unsigned &lowercase, unsigned &digit);
  31.  
  32. int main() {
  33. // Variables to hold statistics
  34. unsigned uppercase = 0, lowercase = 0, digit = 0;
  35.  
  36. // Variable to hold user input
  37. string userInput;
  38.  
  39. cout << "==============================================\n";
  40.  
  41. // Prompt the user to enter a string
  42. cout << "Enter a string:\n\n";
  43. getline(cin, userInput);
  44.  
  45. // Call the function to calculate statistics
  46. Cal_Statistics(userInput, uppercase, lowercase, digit);
  47.  
  48. // Display the calculated statistics
  49.  
  50. cout << "Uppercases : " << uppercase << "\n";
  51. cout << "Lowercases : " << lowercase << "\n";
  52. cout << "Digits : " << digit << "\n";
  53.  
  54. return 0;
  55. }
  56.  
  57. // Function to calculate statistics
  58. void Cal_Statistics(const string &input, unsigned &uppercase,
  59. unsigned &lowercase, unsigned &digit) {
  60.  
  61. for (char ch : input) {
  62. if (isupper(ch)) {
  63. uppercase++;
  64.  
  65. } else if (islower(ch)) {
  66. lowercase++;
  67.  
  68. } else if (isdigit(ch)) {
  69. digit++;
  70. }
  71. }
  72. }
Success #stdin #stdout 0s 5284KB
stdin
esvtvw57tvw897w3847t9vw3879vTFtedYGJHEDswhbHjhd778
stdout
==============================================
Enter a string:

Uppercases : 9
Lowercases : 24
Digits     : 17