Question

Define a function that counts the number of lowercase and uppercase letters in an input C-String....

Define a function that counts the number of lowercase and uppercase letters in an input C-String. DO NOT DEFINE TWO SEPARATE FUNCTIONS. (in C++)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>
#include<ctype.h>/* for functions isUpper(), isalpha()*/
using namespace std;

//function prototype
void countLowerAndUpperCase(char str[], int &countLower, int &countUpper);

int main()
{
   char str[100];//c-string
   cout << "Enter string: ";
   cin.getline(str, 100);
   int countLower = 0, countUpper = 0;
   //call the function
   countLowerAndUpperCase(str, countLower, countUpper);
   cout << "Number of lower case letters: " << countLower << "\nNumber of upper case letters: "
       << countUpper << endl;
   //to hold output screen
   system("pause");
   return 0;
}
/*
function definition--> count lower case and upper case

*/
void countLowerAndUpperCase(char str[], int &countLower, int &countUpper)
{
   /*loop until it found null character*/
   for (int i = 0; str[i] != '\0'; i++)
   {
       if (isalpha(str[i])) // if it is alphabet
       {
           if (isupper(str[i]))//check upper case
               countUpper++;
           else
               countLower++;
       }
   }
}

//output

//if you need any help regarding this solution ........ please leave a comment ....... thanks

Add a comment
Know the answer?
Add Answer to:
Define a function that counts the number of lowercase and uppercase letters in an input C-String....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT