fork download
  1. //Natalie Zarate CSC 5 Chapter 10, P.589, #5
  2. /*******************************************************************************
  3.  * CORRECT CAPITALIZATION
  4.  *
  5.  * This program will prompt the user for a sentence with improper lowecase use.
  6.  * Then, it will correct the lowercases, if neccessary, and display the
  7.  * corrected sentence.
  8.  * _____________________________________________________________________________
  9.  * INPUT
  10.  * sentence - user inputed sentence
  11.  *
  12.  * OUTPUT
  13.  * (corrected) sentence - user inputted sentence with correct capitalization
  14.  * ****************************************************************************/
  15. #include <iostream>
  16. #include <cstring>
  17. #include <cctype>
  18. using namespace std;
  19.  
  20. /*******************************************************************************
  21.  * Capitalize
  22.  *
  23.  * This program with take the given sentence and fixes improper lowercases
  24.  * _____________________________________________________________________________
  25.  * INPUT
  26.  * string - user inputted sentence
  27.  * ****************************************************************************/
  28. // Prototype for capitalize
  29. void Capitalize (char *string);
  30.  
  31. int main()
  32. {
  33. char sentence[51];
  34.  
  35. // Propmpt user for sentence
  36. cout << "Enter a sentence (50 character limit):" << endl;
  37. cin.getline(sentence, sizeof(sentence));
  38.  
  39. // Call Capitalize
  40. Capitalize(sentence);
  41.  
  42. // Display sentence with proper capitalization
  43. cout << "Fixed Sentence: " << sentence << endl;
  44.  
  45. return 0;
  46. }
  47.  
  48. void Capitalize(char *string)
  49. {
  50. bool capital = true; // Flag to indicate if letter needs to be capitalized
  51.  
  52. // Step through array
  53. while (*string)
  54. {
  55. if (capital && isalpha(*string))
  56. {
  57. //Capitalize the character
  58. *string = toupper(*string);
  59.  
  60. //Tell program that letter is now uppercase
  61. capital = false;
  62. }
  63.  
  64. string++;
  65. }
  66.  
  67. }
Success #stdin #stdout 0.01s 5276KB
stdin
you are so lazily and incessantly beautiful
stdout
Enter a sentence (50 character limit):
Fixed Sentence: You are so lazily and incessantly beautiful