I have a question where all lowercase characters of a string should be converted into uppercase characters.But as per the question, certain lines in the code should not be changed. I have written the code below.
#include <iostream>
#include <string>
#include <stdio.h>
#include <ctype.h>
using namespace std;
class StringOps {
public:
void stringToUpper(string &s) //This line should not be changed
{
char c;
int i=0;
while (s[i])
{
c=s[i];
putchar (toupper(c));
i++;
}
}
};
int main(void)
{
string str ="Hello World";
StringOps obj;
obj.stringToUpper(str);
cout << str; //This line should not be changed
return 0;
}
I get the output as:
HELLO WORLDHello World
But the required output is:
HELLO WORLD HELLO WORLD
How do I make the
cout<<str;
statement in main() to print the result computed in the function :
void stringToUpper(string &s)