5. convertToUpper - Given an input string, the function converts all alphabetic characters to uppercase. Write the new string into an output file called Upper.txt and return true. If the input string is empty just return false. The function header is: bool convertToUpper(const string & st)

Respuesta :

Answer:

#include <iostream>

#include <cstring>

#include <fstream>

using namespace std;

bool convertToUpper(const string &st);

int main()

{

string s;

cout << "Enter the string: " << endl;

getline(cin, s);

convertToUpper(s);

return 0;

}

bool convertToUpper(const string &st) {

if(st.length() == 0) {

return false;

} else {

ofstream myfile;

myfile.open ("Upper.txt");

for(int i=0;i<st.length();i++) {

if(st[i]>='a' && st[i]<='z') {

myfile << (char)toupper(st[i]);

} else {

myfile <<st[i];

}

}

myfile.close();

}

 

}

ACCESS MORE
EDU ACCESS