Write a function that takes as parameter a character array, which may contains l
ID: 3761218 • Letter: W
Question
Write a function that takes as parameter a character array, which may contains lowercase, uppercase, digits, and other special symbols (e.g, *, $, ...), and outputs the number of lowercase, uppercase, digits, and special symbol. Please use a character array to store the input string. You can assume the character array is large enough to store all input characters. Also, write a program to test your function.
Example input: AaBbCc123!@#
Output: Lowercase: 3, Uppercase: 3, Digits: 3, Special symbol: 3.
Please write in C++ code.
-The input string must be read and stored as a charater array.
-A fuction must be included to count the number of lowercase, uppercase, digits, and special symbols.
-A main function must be included to call your function.
Thank you in advance. Please include comments.
Explanation / Answer
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
#include<string.h>
void main()
{
char s[50];
int d=0,u=0,l=0,i,sp=0;
cout<<"Enter String";
cin>>s;
int n=strlen(s);
for(i=0;i<n;i++)
{
if(isdigit(s[i]))
d++;
if(isalpha(s[i]))
{
if(isupper(s[i]))
u++;
else
l++;
}
if(s[i]=='@' || s[i]=='!' || s[i]=='#' || s[i]=='$')
sp++;
}
cout<<"Total Digits are="<<d<<endl;
cout<<"Total Upper Case Caharacters
are="<<u<<endl;
cout<<"Total Lower Case Caharacters
are="<<l<<endl;
cout<<"Total Special Caharacters are="<<sp<<endl;
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.