Question

Write a program in c++ to implement/simulate a finite automaton that accepts (only):Odd length binary numbers...

Write a program in c++ to implement/simulate a finite automaton that accepts (only):Odd length binary numbers // 0000001, 101, 11111, etc. It must return accepted or rejected(HAVE TO SHOW EACH STATE AS A FUNCTION,Q0 AND Q1. CANNOT USE STRINGS OR LENGTH OF STRING) not the same posted problem

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>

using namespace std;

int main()
{
int i = 0;
char c;
printf("Enter Input:");
while ((c = getchar()) != '\n')
{ // read a line char by char
if ( c!='0' && c!='1')
{
    printf("Invalid Input \n");
    return 0;
}

printf("The value at state q%u\n is %c\n",i, c);
i++;
}
if(i%2 != 0)
{
printf("The string is accepted");
   
}
else
{
printf("The string is Rejected");
}
return 0;
}

Add a comment
Know the answer?
Add Answer to:
Write a program in c++ to implement/simulate a finite automaton that accepts (only):Odd length binary numbers...
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
  • Write a function program in python to implement/simulate a finite automaton that accepts (only):Odd length binary...

    Write a function program in python to implement/simulate a finite automaton that accepts (only):Odd length binary numbers // 0000001, 101, 11111, etc. the program must be based on the finite automatic theory. cannot use string

  • Write a program in python programming language using functions to implement/simulate a finite automaton that accepts...

    Write a program in python programming language using functions to implement/simulate a finite automaton that accepts (only): Signed and unsigned real numbers. // .12345, 1.2345, -12345., +12345E0, .12345E-10, 1.2345E+1, etc. Show: Finite Automaton Definition, Graph, Table

  • write a program in c++ that only takes in odd length binary inputs (000,111,101,11111,101,1010110,etc: have to...

    write a program in c++ that only takes in odd length binary inputs (000,111,101,11111,101,1010110,etc: have to have the following functions. sample input : 101 output: accepted sample input 1011 output: rejected void q0, void q1, void accept, and void reject

  • C++ Program NO STRINGS OR ARRAYS Problem: Odd length unsigned integer numbers // 12345, 6 ,891...

    C++ Program NO STRINGS OR ARRAYS Problem: Odd length unsigned integer numbers // 12345, 6 ,891 etc. -Finite Automaton -Definition -Graph -Table Please don't use strings or arrays

  • Write a C++ program that simulate a menu based binary number calculator.You don't have to write the main part of the...

    Write a C++ program that simulate a menu based binary number calculator.You don't have to write the main part of the program just the two functions for my C++ program. I wanted to post the sample code from my class but it won't allow me it's too long. This calculate shall have the following five functionalities: Provide sign extension for a binary number Provide two’s complement for a binary nunber string signed_extension(string b);              // precondition: s is a string that...

  • Write a C/C++ program that simulate a menu based binary number calculator. This calculate shall have the following three...

    Write a C/C++ program that simulate a menu based binary number calculator. This calculate shall have the following three functionalities: Covert a binary string to corresponding positive integers Convert a positive integer to its binary representation Add two binary numbers, both numbers are represented as a string of 0s and 1s To reduce student work load, a start file CSCIProjOneHandout.cpp is given. In this file, the structure of the program has been established. The students only need to implement the...

  • I am trying to write a c++ program that will add two binary numbers that are...

    I am trying to write a c++ program that will add two binary numbers that are entered into the command line. I cannot get the program to send anything to stdout. code attached. int main(int argc, char *argv[]) //           IN       IN {    char partialSum[MAX_DIGITS + 1]; //partial sum of the binary numbers    char sum[MAX_DIGITS + 1];       //sum of the binary numbers    bool noError;       //no error flag       //Exit if insufficient arguments...

  • 1. Specification Write a C program to implement a simple calculator that accepts input in the...

    1. Specification Write a C program to implement a simple calculator that accepts input in the following format and displays the result of the computation: calc [operand_1] [operator] [operand_2] The operands operand_1 and operand_2 are non-negative integers. The operator is one of the following: addition (+), subtraction (-), multiplication (x), division (/) and modulo (%). Note: For the multiplication operator, use letter ‘x’. If you use the asterisk ‘*’, your program will not work properly 2. Implementation • The program...

  • I would like some assistance correcting an issue I am having with this assignment. Once a...

    I would like some assistance correcting an issue I am having with this assignment. Once a finite state automaton (FSA) is designed, its transition diagram can be translated in a straightforward manner into program code. However, this translation process is considerably tedious if the FSA is large and troublesome if the design is modified. The reason is that the transition information and mechanism are combined in the translation. To do it differently, we can design a general data structure such...

  • You must write a C program that prompts the user for two numbers (no command line...

    You must write a C program that prompts the user for two numbers (no command line input) and multiplies them together using “a la russe” multiplication. The program must display your banner logo as part of a prompt to the user. The valid range of values is 0 to 6000. You may assume that the user will always enter numerical decimal format values. Your program should check this numerical range (including checking for negative numbers) and reprompt the user for...

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