The language of this program needs to be C++ for visual studio express 2013 for
ID: 3858802 • Letter: T
Question
The language of this program needs to be C++ for visual studio express 2013 for windows.
Create a CharConverter class that has these two pubic member functions.
-uppercase member function accepts a string of words from the user and returns a copy of it with all letters of the string converted from lowercase to uppercase. If the original letters are already uppercase or are not letters they are to be left alone.
-properWords member function accepts a string of words from the user and returns a copy of it with the first letter of each word converted to uppercase.
Write a simple program that uses the class and ask the user to input a string of words. The program should then call the properWords function and display the resulting string. Then the program should call the uppercase function and display the resulting string. Make sure the program loops to ask the user if they want to convert more strings uuntil the user chooses to quit.
Explanation / Answer
NOTE: I have completed the assignment and below is the code. Please check and let me know if you find any issues. I will revert back within 24 hours.
Code:
#include <iostream>
#include <string>
#include <locale>
using namespace std;
class CharConverter{
private:
locale loc;
public:
string uppercase(string str)
{
for(int i = 0; i < str.size(); i++)
str[i] = toupper(str[i], loc);
return str;
}
string properWords(string str)
{
int start_chr = 0;
for(int i = 0; i < str.size(); i++){
if(start_chr == 0 && str[i] != ' '){
str[i] = toupper(str[i], loc);
start_chr = 1;
}
if(str[i] == ' ')
start_chr = 0;
}
return str;
}
};
int main()
{
CharConverter cc;
string in_str;
while(true){
cout << " Enter a string of words, type 'quit' to exit: ";
getline(cin, in_str);
if(in_str.compare("quit") == 0 )
break;
cout << " Properwords for the given string is: " << cc.properWords(in_str);
cout << " Uppercase of given string is: " << cc.uppercase(in_str);
cout << " ";
}
return 0;
}
Code execution screenshot:
https://pasteboard.co/GBZ7t0H.png
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.