Create a free account on Computer Sir Ki Class and unlock access to valuable learning resources.
Exam Paper Downloads: After registering and logging in, you can download exam question papers in PDF format to practice and prepare for your exams.
Student Support: Get assistance with your doubts, queries, and questions related to your studies. Our support is here to help you understand topics and resolve your learning difficulties.
Register today and make your exam preparation easier and more effective!
Problem Statement - Output Writing – isupper(), islower, isalpha()
Write output of the following program.
TC++ #2677
Solution
Run Output
@%%%@##########
char str[21]=”C++ Programming”; //Initialised string in char array.
int len=strlen(str); //Length will be found here. The length will actually be number characters in the given initial string and not the array size, as it is null terminated string. while(len>0)
This loop will run until the len value is reduced to zero, Hence it should be a decrement loop {
if(isupper(str[len-1])) str[len-1]=’@’;
It starts checking from last character. If the character is upper case it is changed to @
else if(islower(str[len-1])) str[len-1]=’#’;
If lowercase it is changed to # character
else if(!isalpha(str[len-1])) str[len-1]=’%’;
All non-alphabet characters are changed to %. this means that ++ and space after that will be changed to %%% len–;
len is decremented so that loop keeps running till first character which is index 0 location of the character array. }
Common Errors
These program need patience and right understanding. Student often miss converting space also as a non alphabet.