Question

Pseudocode for main: Get a string from user If string has correctly matched delimiters print All matched correctly Pseudocod
0 0
Add a comment Improve this question Transcribed image text
Answer #1

//implemented in cpp

// hope u do like the solution....ping me via comments...

#include<iostream>

#include<stack>
#include<cstdio>
using namespace std;

bool is_open(char c){
   if(c =='(')return true;
   return false;
}

bool is_close(char c){
   if(c ==')')return true;
   return false;
}
int is_brother(char c){
   if(c != '\0')return true;
   return false;
}
bool fsm(string str){
   stack <char> s;
   int i=0;
   while(1){
       if(is_open(str[i]))s.push(str[i]);
       else if(is_close(str[i]))
           {
               if(s.empty()){
                   cout<<"No symbol to pop \n";return false;
               }
               s.pop();}
       else if(is_brother(str[i])); // do nothing
       else break ;//state 4 break here;
       i++;
   }
   if(!s.empty()){cout<<"Excess Open braces \n";return false;}
   return true;  
  

}
int main(){

   string str;
   cout<<"enter string please: ";
   cin >> str;
   cout << fsm(str)<<"\n";

   return 0;
}

prasad@prasad-HP-15-Notebook-PC: ~/Desktop rasad@prasad-HP-15-Notebook-PC:~/Desktop$ g++ match.cpp ПАР rasad@prasad-HP-15-Not

Add a comment
Know the answer?
Add Answer to:
Pseudocode for main: Get a string from user If string has correctly matched delimiters print "All...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Read Section 6.1.5 (p.235) on the Parenthesis Matching problem. They gave 5 examples: the first t...

    Please help with this. The hint refers to the attached picture. Read Section 6.1.5 (p.235) on the Parenthesis Matching problem. They gave 5 examples: the first two are " correct", and the remaining 3 "incorrect". Notice that the last one is actually "fixable". You just have to append the string")" to the input to get a properly matched expression! Here is another example: the string (O[(is incorrect, but is fixable if you append )]) Thus we want to classify the...

  • Write a client function parenthesesMatch that given a string containing only the characters for parentheses, braces...

    Write a client function parenthesesMatch that given a string containing only the characters for parentheses, braces or curly braces, i.e., the characters in ’([{}])’, returns True if the parentheses, brackets and braces match and False otherwise. Your solution must use a Stack. For, example: >>> parenthesesMatch('(){}[]') True >>> parenthesesMatch('{[()]}') True >>> parenthesesMatch('((())){[()]}') True >>> parenthesesMatch('(}') False >>> parenthesesMatch('({])') False >>> parenthesesMatch('((())') False >>> parenthesesMatch('(()))') False >>> Hint: It is not sufficient to just count the number of opening and closing...

  • Evaluateeg EvaluateInFix.java: import java.util.Stack; import java.util.Scanner; public class EvaluateInfix {    public static void main(String[] args)...

    Evaluateeg EvaluateInFix.java: import java.util.Stack; import java.util.Scanner; public class EvaluateInfix {    public static void main(String[] args)    {    Scanner keyboard = new Scanner(System.in); System.out.println("This program an inFix Expression: "); System.out.print("Enter an inFix Expression that you want to evaluate (or enter ! to exit): "); String aString = keyboard.nextLine();    while (!aString.equals("!")) {    System.out.println (evaluateinFix(aString));    System.out.print("Enter an inFix Expression that you want to evaluate (or enter ! to exit): ");    aString = keyboard.nextLine(); } // end while...

  • language is java Restrictions: You are not allowed to use anything from the String, StringBuilder, or...

    language is java Restrictions: You are not allowed to use anything from the String, StringBuilder, or Wrapper classes. In general, you may not use anything from any other Java classes, unless otherwise specified. You are not allowed to use String literals in your code ("this is a string literal"). You are not allowed to use String objects in your code. The methods must be implemented by manipulating the data field array, The CSString Class: NOTE: Pay very careful attention to...

  • Let’s build a dynamic string tokenizer! Start with the existing template and work on the areas...

    Let’s build a dynamic string tokenizer! Start with the existing template and work on the areas marked with TODO in the comments: Homework 8 Template.c Note: If you turn the template back into me without adding any original work you will receive a 0. By itself the template does nothing. You need to fill in the code to dynamically allocate an array of strings that are returned to the user. Remember: A string is an array. A tokenizer goes through...

  • Consider the following C++ program. It reads a sequence of strings from the user and uses...

    Consider the following C++ program. It reads a sequence of strings from the user and uses "rot13" encryption to generate output strings. Rot13 is an example of the "Caesar cipher" developed 2000 years ago by the Romans. Each letter is rotated 13 places forward to encrypt or decrypt a message. For more information see the rot13 wiki page. #include <iostream> #include <string> using namespace std; char rot13(char ch) { if ((ch >= 'a') && (ch <= 'z')) return char((13 +...

  • Instructions: Consider the following C++ program. It reads a sequence of strings from the user and...

    Instructions: Consider the following C++ program. It reads a sequence of strings from the user and uses "rot13" encryption to generate output strings. Rot13 is an example of the "Caesar cipher" developed 2000 years ago by the Romans. Each letter is rotated 13 places forward to encrypt or decrypt a message. For more information see the rot13 wiki page. #include <iostream> #include <string> using namespace std; char rot13(char ch) { if ((ch >= 'a') && (ch <= 'z')) return char((13...

  • You will be writing a simple Java program that implements an ancient form of encryption known...

    You will be writing a simple Java program that implements an ancient form of encryption known as a substitution cipher or a Caesar cipher (after Julius Caesar, who reportedly used it to send messages to his armies) or a shift cipher. In a Caesar cipher, the letters in a message are replaced by the letters of a "shifted" alphabet. So for example if we had a shift of 3 we might have the following replacements: Original alphabet: A B C...

  • Please read the problem carefully and answer the 2 questions below code: /***************************************************************** * Program: palindrome.c...

    Please read the problem carefully and answer the 2 questions below code: /***************************************************************** * Program: palindrome.c * * Purpose: implements a recursive function for determining *   if a string is a palindrome * * Authors: Steven R. Vegdahl, Tammy VanDeGrift, Martin Cenek * *****************************************************************/ #include #include #include /***************************************************************** * is_palindrome - determines whether a string of characters is a palindrome * * calling sequence: *    result = is_palindrome(str, first_index, last_index) * * parameters - *    str - the string to test *    first_index -...

  • How do I do this? -> string print() const; Function to output the data, return the...

    How do I do this? -> string print() const; Function to output the data, return the output in the form of string, with all elements in the hash table included and each seperated by a space this is my code: template <class elemType> string hashT<elemType>::print() const { for (int i = 0; i < HTSize; i++){        if (indexStatusList[i] == 1){        cout <<HTable[i]<< " " << endl;        }   }    } **********Rest of the code...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT