Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The code below almost does what it suppose to do. Im just having problems gettin

ID: 3638347 • Letter: T

Question

The code below almost does what it suppose to do. Im just having problems getting to program end and say "Congratulations" when i change it to the correct mystery word. //anagram.h #ifndef ANAGRAM #define ANAGRAM #include <iostream> #include <list> using namespace std; //------------------------------------------------------------------ // Class declaration for the Anagram Puzzle ADT //------------------------------------------------------------------ class AnagramPuzzle { public: AnagramPuzzle( char answ[], char init[]); // Constructs an anagram puzzle. String answ is the solution to the // puzzle and string init is the initial scrambled letter sequence. void shiftLeft(); // Shifts the letters left one position, the leftmost letter is moved // to the right end of the puzzle. void swapEnds(); // Swaps the letters at the left and right ends of the puzzle. void display(); // Displays an anagram puzzle. bool solved() const; // Returns 1 if a puzzle is solved. Otherwise returns 0. private: // Data members list<char> solution, // Solution to puzzle puzzle; // Current puzzle configuration }; #endif //anagram.cpp #include "anagram.h" #include <list> using namespace std; //-------------------------------------------------------------------- // Implementation of the Anagram Puzzle ADT //-------------------------------------------------------------------- // Simulates a puzzle in which a player attempts to unscramble a // set of letters to form a word. //-------------------------------------------------------------------- AnagramPuzzle:: AnagramPuzzle (char answ[], char init[]) // Constructs an anagram puzzle. String answ is the solution to the // puzzle and string init is the initial scrambled letter sequence. { int answ_size = 0, init_size = 0; answ_size = strlen(answ); // get size of answer array init_size = strlen(init); // get size of initial array solution = list<char>(answ, answ+answ_size); // create lists of each puzzle = list<char>(init, init+init_size); } //-------------------------------------------------------------------- void AnagramPuzzle:: shiftLeft () // Shifts the letters left one position, the leftmost letter is moved // to the right end of the puzzle. { char ch= solution.front(); //gets first character solution.pop_front(); //removes the firstcharacter solution.push_back(ch); //inserts the first char at the end } //-------------------------------------------------------------------- void AnagramPuzzle:: swapEnds () // Swaps the letters at the left and right ends of the puzzle. { char firstChar = solution.front();//gets frist char char lastChar = solution.back(); //gets last char solution.pop_front(); //removes first char solution.push_front(lastChar); //inserts last char at first solution.pop_back(); //removes last char solution.push_back(firstChar); //inserts first char at last } //-------------------------------------------------------------------- void AnagramPuzzle:: display () // Displays an anagram puzzle. { list<char>::iterator it; it = solution.begin(); //gets iterator to begning // iterate through the solution //and displays the solution while(it != solution.end()) { cout<<*it; it++; } cout << endl; } //-------------------------------------------------------------------- int AnagramPuzzle:: solved () // Returns 1 if a puzzle is solved. Otherwise returns 0. { return (puzzle == solution); } //puzzle.cpp #include "anagram.h" #include <iostream> using namespace std; //--------------------------------------------------------------- // The main() function provides the user interface to the puzzle. void main () { AnagramPuzzle mysteryWord("right","irtgh"); // Puzzle char move, // User input move userQuit; // User quits puzzle // Display the initial puzzle. mysteryWord.display(); // Loop until puzzle solved or user quits userQuit = 0; while ( !mysteryWord.solved() && !userQuit ) { cout << "Enter move ( L/S/Q ): "; // Get user move cin >> move; switch ( move ) // Process move { case 'L' : case 'l' : mysteryWord.shiftLeft(); break; case 'S' : case 's' : mysteryWord.swapEnds(); break; case 'Q' : case 'q' : userQuit = 1; break; default: cout << "Invalid move" << endl; } mysteryWord.display(); // Display puzzle } if ( mysteryWord.solved() ) cout << "Congratulations!" << endl; } The code below almost does what it suppose to do. Im just having problems getting to program end and say "Congratulations" when i change it to the correct mystery word. //anagram.h #ifndef ANAGRAM #define ANAGRAM #include <iostream> #include <list> using namespace std; //------------------------------------------------------------------ // Class declaration for the Anagram Puzzle ADT //------------------------------------------------------------------ class AnagramPuzzle { public: AnagramPuzzle( char answ[], char init[]); // Constructs an anagram puzzle. String answ is the solution to the // puzzle and string init is the initial scrambled letter sequence. void shiftLeft(); // Shifts the letters left one position, the leftmost letter is moved // to the right end of the puzzle. void swapEnds(); // Swaps the letters at the left and right ends of the puzzle. void display(); // Displays an anagram puzzle. bool solved() const; // Returns 1 if a puzzle is solved. Otherwise returns 0. private: // Data members list<char> solution, // Solution to puzzle puzzle; // Current puzzle configuration }; #endif //anagram.cpp #include "anagram.h" #include <list> using namespace std; //-------------------------------------------------------------------- // Implementation of the Anagram Puzzle ADT //-------------------------------------------------------------------- // Simulates a puzzle in which a player attempts to unscramble a // set of letters to form a word. //-------------------------------------------------------------------- AnagramPuzzle:: AnagramPuzzle (char answ[], char init[]) // Constructs an anagram puzzle. String answ is the solution to the // puzzle and string init is the initial scrambled letter sequence. { int answ_size = 0, init_size = 0; answ_size = strlen(answ); // get size of answer array init_size = strlen(init); // get size of initial array solution = list<char>(answ, answ+answ_size); // create lists of each puzzle = list<char>(init, init+init_size); } //-------------------------------------------------------------------- void AnagramPuzzle:: shiftLeft () // Shifts the letters left one position, the leftmost letter is moved // to the right end of the puzzle. { char ch= solution.front(); //gets first character solution.pop_front(); //removes the firstcharacter solution.push_back(ch); //inserts the first char at the end } //-------------------------------------------------------------------- void AnagramPuzzle:: swapEnds () // Swaps the letters at the left and right ends of the puzzle. { char firstChar = solution.front();//gets frist char char lastChar = solution.back(); //gets last char solution.pop_front(); //removes first char solution.push_front(lastChar); //inserts last char at first solution.pop_back(); //removes last char solution.push_back(firstChar); //inserts first char at last } //-------------------------------------------------------------------- void AnagramPuzzle:: display () // Displays an anagram puzzle. { list<char>::iterator it; it = solution.begin(); //gets iterator to begning // iterate through the solution //and displays the solution while(it != solution.end()) { cout<<*it; it++; } cout << endl; } //-------------------------------------------------------------------- int AnagramPuzzle:: solved () // Returns 1 if a puzzle is solved. Otherwise returns 0. { return (puzzle == solution); } #include "anagram.h" #include <list> using namespace std; //-------------------------------------------------------------------- // Implementation of the Anagram Puzzle ADT //-------------------------------------------------------------------- // Simulates a puzzle in which a player attempts to unscramble a // set of letters to form a word. //-------------------------------------------------------------------- AnagramPuzzle:: AnagramPuzzle (char answ[], char init[]) // Constructs an anagram puzzle. String answ is the solution to the // puzzle and string init is the initial scrambled letter sequence. { int answ_size = 0, init_size = 0; answ_size = strlen(answ); // get size of answer array init_size = strlen(init); // get size of initial array solution = list<char>(answ, answ+answ_size); // create lists of each puzzle = list<char>(init, init+init_size); } //-------------------------------------------------------------------- void AnagramPuzzle:: shiftLeft () // Shifts the letters left one position, the leftmost letter is moved // to the right end of the puzzle. { char ch= solution.front(); //gets first character solution.pop_front(); //removes the firstcharacter solution.push_back(ch); //inserts the first char at the end } //-------------------------------------------------------------------- void AnagramPuzzle:: swapEnds () // Swaps the letters at the left and right ends of the puzzle. { char firstChar = solution.front();//gets frist char char lastChar = solution.back(); //gets last char solution.pop_front(); //removes first char solution.push_front(lastChar); //inserts last char at first solution.pop_back(); //removes last char solution.push_back(firstChar); //inserts first char at last } //-------------------------------------------------------------------- void AnagramPuzzle:: display () // Displays an anagram puzzle. { list<char>::iterator it; it = solution.begin(); //gets iterator to begning // iterate through the solution //and displays the solution while(it != solution.end()) { cout<<*it; it++; } cout << endl; } //-------------------------------------------------------------------- int AnagramPuzzle:: solved () // Returns 1 if a puzzle is solved. Otherwise returns 0. { return (puzzle == solution); } //puzzle.cpp #include "anagram.h" #include <iostream> using namespace std; //--------------------------------------------------------------- // The main() function provides the user interface to the puzzle. void main () { AnagramPuzzle mysteryWord("right","irtgh"); // Puzzle char move, // User input move userQuit; // User quits puzzle // Display the initial puzzle. mysteryWord.display(); // Loop until puzzle solved or user quits userQuit = 0; while ( !mysteryWord.solved() && !userQuit ) { cout << "Enter move ( L/S/Q ): "; // Get user move cin >> move; switch ( move ) // Process move { case 'L' : case 'l' : mysteryWord.shiftLeft(); break; case 'S' : case 's' : mysteryWord.swapEnds(); break; case 'Q' : case 'q' : userQuit = 1; break; default: cout << "Invalid move" << endl; } mysteryWord.display(); // Display puzzle } if ( mysteryWord.solved() ) cout << "Congratulations!" << endl; }

Explanation / Answer

using namespace std; class money{ private: public: int dollars; int cents; money(); void setDollars(int value); void setCents(int value); int add(money& value); int subtract(money& value); int multiply(money& value); int divide(money& value); bool compare(money& value); bool isEqual(money& value); }; money::money(){ dollars = 0; cents = 0; } void money::setDollars(int value){ money::dollars = value; } void money::setCents(int value){ money::cents = value; }