Question

In: Computer Science

For our current programming assignment I need to create a CleanWord method that reads in one...

For our current programming assignment I need to create a CleanWord method that reads in one variable string at a time and returns a cleaned word without any non letters. The instructions given to us are listed below:

“Clean word” method:

 This is to be implemented as a separate method, so it can be called for either a dictionary word or book word.

 The function will remove any non-letters, except an apostrophe (‘) and numbers from the word.

 All letters will changed to lower case.

 It will then return the updated word. The word could now be blank. The calling method will need to deal with this correctly.

I would appreciate the help!


Language: C++

Solutions

Expert Solution

Thanks for the question.


Below is the code you will be needing Let me know if you have any doubts or if you need anything to change.


Thank You !!


===========================================================================

#include<iostream>
#include<string>
#include<sstream>

using namespace std;


string cleanWord(string &word){
  
   stringstream ss;
   char letter;
   for(int i=0; i<word.size(); i++){
       letter = word.at(i);
       if('a'<=letter && letter<='z'){
           ss<<letter;
       }else if('A'<=letter && letter<='Z'){
           letter = letter - ('A'-'a');
           ss<<letter;
       }else if(letter=='\''){
           ss<<letter;
       }
   }
   string cleanedWord;
   ss>>cleanedWord;

   return cleanedWord;
  
  
}


int main(){
  
  
   string word = "'cleaned#%@#^&362464'WORD3523626";
   cout<<cleanWord(word)<<endl;
}

============================================================================


Related Solutions

C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with...
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with following information: 1,2,3,4,5 red,blue,green,yellow,orange left, right,front, back 2. After having program read the .txt file, output the above information in categories of Symbol, Token Type, and Count : Example: Symbol---Token Type (data type)----Count (how many times symbol appeared in .txt file) =========================================================================== 1 ----digit ----1 2 ----digit ----1 red ----color ----1 blue ----color ----1 left ----direction ----1 right ----direction    ----1
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with...
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with following information: 1,2,3,4,5 red,blue,green,yellow,orange left, right,front, back 2. After having program read the .txt file, output the above information in categories of Symbol, Token Type, and Count : Example: Symbol---Token Type (data type)----Count (how many times symbol appeared in .txt file) =========================================================================== 1 ----digit ----1 2 ----digit ----1 red ----color ----1 blue ----color ----1 left ----direction ----1 right ----direction    ----1
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with...
C++ Assignment Hi, I need to create a program that: 1.Reads a source file (.txt) with following information: 1,2,3,4,5 red,blue,green,yellow,orange left, right,front, back 2. After having program read the .txt file, output the above information in categories of Symbol, Token Type, and Count : Example: Symbol---Token Type (data type)----Count (how many times symbol appeared in .txt file) =========================================================================== 1 ----digit ----1 2 ----digit ----1 red ----color ----1 blue ----color ----1 left ----direction ----1 right ----direction    ----1
Java Programming In this assignment we are going to create our own programming language, and process...
Java Programming In this assignment we are going to create our own programming language, and process it Java. programming language has 6 commands enter add subtract multiply divide return enter, add, subtract, multiply, divide all take 1 parameter (a double value). return takes no parameters.
9) Create a java programming where you will enter two numbers and create only one method,...
9) Create a java programming where you will enter two numbers and create only one method, which will return or display addition, substraction, multiplication, division, average and check which number is greater than the other. Everything in one method and call it in main method.
I need assistance with the below HTML5 web programming assignment. Use as many question as you...
I need assistance with the below HTML5 web programming assignment. Use as many question as you need to answer. (c) Client Lab – Exploring Form Design (25 points) The design of a form, such as the justification of the labels, the use of background colors, and even the order of the form elements can either increase or decrease the usability of a form. Visit some of the following resources to explore form design: Because of the dynamics of web sites,...
In this programming assignment, you will write a program that reads in the CSV file (passenger-data-short.csv),...
In this programming assignment, you will write a program that reads in the CSV file (passenger-data-short.csv), which contains passenger counts for February 2019 on 200 international flights. The data set (attached below) is a modified CSV file on all International flight departing from US Airports between January and June 2019 reported by the US Department of Transportation. You write a program that give some summary statistics on this data set. Create a header file named flights.h. In this file, you...
Java programming. *******I Need complete the following requirements in this project: 1/ Remove the applyRandomBonus method...
Java programming. *******I Need complete the following requirements in this project: 1/ Remove the applyRandomBonus method from the test class 2/ Create a File, Printwriter for an output file yourlastnameErrorLog.txt 3/ Set your maximum array size for accounts to 10 4/ Catch InputMismatch and ArrayIndexOutOfBounds exceptions when reading data from the file: a. Skip any lines that cause an exception b. Write information about the exception to the log file, yourlastnameError.txt c. Include exception type and line number in exception...
Ruby programming Create a Ruby program which reads numbers, deposits them into an array and then...
Ruby programming Create a Ruby program which reads numbers, deposits them into an array and then calculates the arithmetic mean (otherwise known as the average), the median (that is, the number that splits the set of value in half with half being above and half being below the number), and the standard deviation (that is, the average of distance each number is from the mean then squared). Further information about these calculations can be found here: average: http://en.wikipedia.org/wiki/Average (add up...
JAVA PROGRAMMING Hi! I need to create a calculator using do/while loop that calls a menu...
JAVA PROGRAMMING Hi! I need to create a calculator using do/while loop that calls a menu switch where the user choice the calculation type. In the switch each case calls a method to each type of calculation (addition/subtraction/division/multiply/ change set of numbers in the array) those methods sends back the result to be displayed in another method. This application needs to hold the user input's numbers as an array. Thanks for your time. It is a great help!
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT