Help please! I need my code to use an exception handling method to check if the user entered a correct word. Here is the logic: When given two words, the child may claim that transformation of the first word into the second is possible. In this case, the program asks the child to demonstrate the correctness of the answer by typing a sequence of words starting with the first and ending with the second. Such a sequence is an acceptable proof sequence if each word is obtained from its predecessor by swapping a single pair of adjacent letters. For example, the sequence tops, tosp, tsop, stop, sotp, sopt, spot proves that the word tops can be transformed into spot. If the proof sequence is accepted, the child earns a point and play proceeds to the next round with a fresh pair of words. A proof sequence is rejected if a word cannot be obtained from its predecessor by swapping an adjacent pair of letters, or if the first word in the sequence is not the first word of the pair of words being tested, or if the last word is not the second word in the given pair. When a sequence is rejected, play proceeds to the next round, but the child earns no points. The child may observe that transformation is not possible. If the child'Â’s answer is correct, he or she receives a point and play proceeds to the next round. If the child'Â’s answer is incorrect and the transformation is indeed possible, the child receives no points. In this case, however, the program displays a correct proof sequence before moving on to the next round of the game. This is my code at the moment. This is Dev C++ #include #include #include #include using namespace std; void sort(char str[],int size,vector& transpositions); int main() {    char str1[]="spot";    char str1Copy[]="spot";    char str2[]="stop";    vector transpose;    vector reverse_transpose;    cout<<"The first word is "<=0;k--)    {        int index=reverse_transpose[k];        swap(str1Copy[index],str1Copy[index+1]);        cout<& transpositions) {    int upperBound=size-1;    while       {            if(str[k]>str[k+1])            {                transpositions.push_back(k);                swap(str[k],str[k+1]);            }        }        upperBound--;    }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Computer Science

Help please! I need my code to use an exception handling method to check if the user entered a correct word.

Here is the logic:

When given two words, the child may claim that transformation of the first word into the second is possible. In this case, the program asks the child to demonstrate the correctness of the answer by typing a sequence of words starting with the first and ending with the second. Such a sequence is an acceptable proof sequence if each word is obtained from its predecessor by swapping a single pair of adjacent letters. For example, the sequence

tops, tosp, tsop, stop, sotp, sopt, spot

proves that the word tops can be transformed into spot. If the proof sequence is accepted, the child earns a point and play proceeds to the next round with a fresh pair of words.

A proof sequence is rejected if a word cannot be obtained from its predecessor by swapping an adjacent pair of letters, or if the first word in the sequence is not the first word of the pair of words being tested, or if the last word is not the second word in the given pair. When a sequence is rejected, play proceeds to the next round, but the child earns no points.

The child may observe that transformation is not possible. If the child'Â’s answer is correct, he or she receives a point and play proceeds to the next round. If the child'Â’s answer is incorrect and the transformation is indeed possible, the child receives no points. In this case, however, the program displays a correct proof sequence before moving on to the next round of the game.

This is my code at the moment. This is Dev C++

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

void sort(char str[],int size,vector<int>& transpositions);
int main()
{
   char str1[]="spot";
   char str1Copy[]="spot";
   char str2[]="stop";
   vector<int> transpose;
   vector<int> reverse_transpose;
   cout<<"The first word is "<<str1<<endl
   <<"The second word is "<<str2<<endl;
   sort(str1,4,transpose);
   sort(str2,4,reverse_transpose);
   cout<<"The transformation steps are: "<<endl;
   cout<<str1Copy<<" ";
   for(int k=0;k<transpose.size();k++)
   {
       int index=transpose[k];
       swap(str1Copy[index], str1Copy[index+1]);
       cout<<str1Copy<<" ";
   }
   for(int k=reverse_transpose.size()-1;k>=0;k--)
   {
       int index=reverse_transpose[k];
       swap(str1Copy[index],str1Copy[index+1]);
       cout<<str1Copy<<" ";
   }
   cout<<endl;

   return 0;   
}
void sort(char str[], int size, vector<int>& transpositions)
{
   int upperBound=size-1;
   while       {
           if(str[k]>str[k+1])
           {
               transpositions.push_back(k);
               swap(str[k],str[k+1]);
           }
       }
       upperBound--;
   } 

Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Header Files
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education