/*
Q5. Write a program to use a String class with a member function that converts a string from lower case to upper case.
You can make use of standard library functions like toupper() to convert single characters to upper case.
You can find theis function in the header file ctype.h.
*/
# include "iostream"
# include "stdio.h"
using namespace std;
# include "ctype.h"
# define MAX 100
class String
{
public:
char *cString;
public:
char* fnString(char *cStr)
{
char szArray[MAX]={0};
int nloop=0;
while (*cStr != NULL)
{
szArray[nloop++] = toupper(*cStr);
cStr++;
}
return szArray;
}
};
int main()
{
String Obj;
Obj.cString=(char *)calloc(sizeof(char)*100,1);
printf("Enter the String which to be upper case\n");
gets(Obj.cString);
strcpy(Obj.cString, Obj.fnString(Obj.cString));
printf("%s\n",Obj.cString);
return 0;
}
OUTPUT:
Enter the String which to be upper case
this program is used to convert from lower case to upper case letter
THIS PROGRAM IS USED TO CONVERT FROM LOWER CASE TO UPPER CASE LETTER
Press any key to continue . . .
No comments:
Post a Comment