[ThinkingInC ++] 21. Exercises on C (3)
/*** Function: Use the while loop to read words from the standard input (cin) into the string. This is an "infinite" * while loop. You can use the break statement to interrupt (and exit the program ). For the words to be read, use the series if statement * this word "maps" to an integer, and then use this Integer as the selection condition of a switch statement. The word above indicates that it is the end sign of the program. Use a file to output the Test Program * Time: August 15, 2014 08:22:17 * Author: cutter_point */# include
# Include
# Include
# Include
# Include
Using namespace std; // design a class, including all functions class operatorText {public: // operatorText () = default; operatorText (string s = ""): s (s) {} // The words in the standard input (cin) are read into the string void inWord (istream & is ); // The meaning of an integer as the selection condition of a switch statement string theMeanOfInt (); // the words to be read are mapped to an integer using a series of if Statements, you can use void wordToInt (); private: // to store the word string s; // to store the corresponding integer int is ;}; // The words in the standard input (cin) are read into the string void operatorText: inWord (istream & is) {// enter a word, save to class cout <"\ n input word:"; string ps; is> ps; this-> s = ps ;} /* use the series of if Statements to read the words. The word "ing" is an integer. void wordToInt (const string s, int & is); */void operatorText :: wordToInt () {if (s = "I" | s = "I") {is = 5 ;} else if (s = "love" | s = "Love" | s = "LOVE") {is = 5 ;} else if (s = "China") {is = 5;} else {is = 1; cout <"\ n word" <
> PanDuan; if (panDuan = 'I') {while (1) {// create a word object operatorText ot ("haha"); ot. inWord (cin); // enter the word ot. wordToInt (); // enter the meaning of the word cout <