In: Computer Science
Please find below code in c++ and don't forget to give a Like
Note: Given scenario has a method with void but mentioned that this method should return a sentence to main function. If the void is present this can't return any value. So, changed the void to String type and returning the converted string to main function.
Code:
#include <iostream>
#include <cctype>
#include <string>
using namespace std;
string lowerToUpper(std::string sentence){
string new_se="";
for(int i=0;i<sentence.length();i++){
if(islower(sentence[i])){
new_se+=toupper(sentence[i]);
}
else{
new_se+=sentence[i];
}
}
return new_se;
}
int main()
{
string sentence,new_sentence;
cout<<"Hello how are you doing?\n";
cout<<"Enter sentence to convert: ";
getline(cin,sentence);
new_sentence=lowerToUpper(sentence);
if(new_sentence==sentence){
cout<<"the function called, argument and the incorrect
result";
return -1;
}
else{
return 0;
}
}
Screenshot of code and output: