Program a clean_string function that combines both the convert_lower and remove_punct functionality in one function. In other words, take a string as a parameter and return a clean version of the string that has no punctuation, no spaces and is all lower case.
#include <iostream>
#include <string>
using namespace std;
// TODO: Add your clean_string function here
int main()
{
string line;
getline(cin, line);
while(line != "quit")
{
cout << clean_string(line) << ": " << line
<< endl;
getline(cin, line);
}
return 0;
}
CODE: C++
string clean_string(string str)
{
// removes punctuations
for (int i = 0, len = str.size(); i < len;
i++)
{
if (ispunct(str[i]))
{
str.erase(i--, 1);
len = str.size();
}
}
cout << str << endl;
//Converts to lowercase
int i=0;
while(str[i]!='\0')
{
if(str[i]>='A' && str[i]<='Z'){
str[i]=str[i]+32;
}
++i;
}
cout << str << endl;
//removes blank spaces
int len = str.size();
for(int i = 0; i < len; i++) {
if (str[i] == ' ') {
for (int j = i; j < len; j++)
str[j] = str[j+1];
len--;
}
}
return str;
}
If you face any problem please comment
Program a clean_string function that combines both the convert_lower and remove_punct functionality in one function. In...
Create a program with the main function and one additional function. The additional function asks for input from the user and returns the output back to the main function for display. This is for c++ and here is my code, could you guys please tell me what I am missing from the instructions. Thank you #include <iostream> using namespace std; int sum (int, int); int main() { int n1, n2, total; cout << "Enter two numbers...
working on a program in c++ The user enters an email address into your program. You must cuteverything after the @ symbol and output it. #include <iostream> #include <string> using namespace std; int main() { string email_adress = ""; //email get the info cout <<"what is your email adress? "; getline(cin, email_adress) ; cin.ignore('@'); // now we put into writitng in sentence cout <<"the email you entered is: " << email_adress << ". " <<"your email adress domian is :"...
Flatten Text: Write a function to implement simple string flatten operation with the help of number of occurrence of characters. For example, the string xxyzzzzzxxx results in x2ylz5x3. In case the "flattened" string doesn’t result in becoming shorter than what we started with, then the function simply returns the starting string. The string should use only uppercase and lowercase letters (a through z). #include <iostream> using namespace std; string flattenText(string str) { string flattenedText = ""; return flattenedText;...
5.9.2: Modify a string parameter. C++ Complete the function to replace any period by an exclamation point. Ex: "Hello. I'm Miley. Nice to meet you." becomes: "Hello! I'm Miley! Nice to meet you!" #include <iostream> #include <string> using namespace std; void MakeSentenceExcited(string& sentenceText) { /* Your solution goes here */ } int main() { string testStr; getline(cin, testStr); MakeSentenceExcited(testStr); cout << testStr; return 0; }
#include <iostream> #include <string> using namespace std; //Write a function that changes all characters in a string to dashes string to_dash(string s){ for(int i = 0; i < s.length(); i++){ } return s; } int main(){ string s; cin >> s; s = to_dash(s); cout << s << endl; }
When I try to run the program it gives me an erron saying Expected expresion on this line, else if(phrase.find(sub_String)!=std::string::npos). #include #include #include using namespace std; int main( ) { // Defining variables. //Initilizing variables. int magicNum; int magicNum1; int position; int phraseLenght; string vowels = "aeiou"; string phrase; string sub; // The phrase and the sub phrase cout << "Enter a phrase:" << endl; std::getline (std::cin,phrase); cout << "Enter a 3-character sub:"...
4) What is the output if the input istom - Sawyer? #include <iostream> using namespace std; int main() { string playerName; cout << "Enter name"; cin >> playerName; cout << endl « playerName; return 0; } a. Tom - Sawyer b. Tom Sawyer c. Tom d. Sawyer 5) Which XXX generates "Adam is 30 years old." as the output? #include <iostream> using namespace std; int main() { string name = "Adam"; int age = 30; XXX return 0; } a....
In C++ write a program that will read three strings from the user, a phrase, a letter to replace, and a replacement letter. The program will change the phrase by replacing each occurrence of a letter with a replacement letter. For example, if the phrase is Mississippi and the letter to replace is 's' the new phrase will be "miizzizzippi". in the function, replace the first parameter is a modifiable string, the second parameter is the occurrence of a letter...
Write a program that takes in a line of text as input, and outputs that line of text in reverse. The program repeats, ending when the user enters "Quit", "quit", or "q" for the line of text.Ex: If the input is:Hello there Hey quitthen the output is:ereht olleH yeHThere is a mistake in my code I can not find. my output is : ereht olleH ereht olleHyeHHow can I fix this?I saw some people use void or the function reverse but we didnt...
CODES: main.cpp #include <iostream> #include <string> #include "ShoppingCart.h" using namespace std; char PrintMenu() { char answer; cout << "MENU" << endl; cout << "a - Add item to cart" << endl; cout << "d - Remove item from cart" << endl; cout << "c - Change item quantity" << endl; cout << "i - Output items' descriptions" << endl; cout << "o - Output shopping cart" << endl; cout << "q - Quit" << endl << endl; while (true) {...