Question

Draw an automaton which will accept all integers (in binary form) of Odd parity (number of...

Draw an automaton which will accept all integers (in binary form) of Odd parity (number of 1’s in the string is odd). Now write a code in a high level language (C++) for the automaton. Take inputs of two strings, one of odd parity (e.g, 00111011) and another one of even parity (e.g., 1100110011). Your code should accept the right string and reject the wrong one. Print your code and results

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

Program:

#include<iostream>

using namespace std;

int main()

{

  char string1[100],string2[100]; // variable declaration

  int i,count=0; // variable declaration

  

  cout<<"Enter string1: ";

cin>>string1; // accept string1

  

  for(i=0;string1[i]!='\0';++i) // Loop runs until end of the string1

  {

    if(string1[i]=='1') // Count number of 1s in the string

      count++; // Increment count

  }

if(count%2==1) // Check count is odd or not

cout<<"String accepted."<<endl;

else

   cout<<"String rejected."<<endl;

count=0; // Count assigned to 0

  cout<<"\nEnter string2: ";

  cin>>string2; // accept string2

  

  for(i=0;string2[i]!='\0';++i) // Loop runs until end of the string2

  {

    if(string2[i]=='1') // Count number of 1s in the string

      count++; // Increment count

  }

if(count%2==1) // Check count is odd or not

cout<<"String accepted."<<endl;

else

   cout<<"String rejected."<<endl;

  return 0;

}

Output:

Add a comment
Know the answer?
Add Answer to:
Draw an automaton which will accept all integers (in binary form) of Odd parity (number of...
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
  • In C:Write a program that can determine whether a user input is a binary number or...

    In C:Write a program that can determine whether a user input is a binary number or not. (1, 2, 3, 8, 13) Write a program that accomplishes all of the following: Greets the user and informs them that the program will determine whether an input from the user is a valid binary number or not (e.g., consisting of only 0’s and/or 1’s). Accept an integer input from the user. Assume that the user provides a valid numeric input that will...

  • 1. Write a recursive function that returns the sum of all even integers in a LinkedBinaryTree. Yo...

    please explain each line of code! ( in python ) 1. Write a recursive function that returns the sum of all even integers in a LinkedBinaryTree. Your function should take one parameter, root node. You may assume that the tree only contains integers. You may not call any methods from the LinkedBinaryTree class. Specifically, you should traverse the tree in your function def binary tree even sum (root): Returns the sum of al1 even integers in the binary tree 2....

  • Undecimal to decimal&decimal to undecimal #Your code here Thank you! Binary-to-Decimal In a previous lab, we...

    Undecimal to decimal&decimal to undecimal #Your code here Thank you! Binary-to-Decimal In a previous lab, we considered converting a byte string to decimal. What about converting a binary string of arbitrary length to decimal? Given a binary string of an arbitrarily length k, bk-1....bi .box the decimal number can be computed by the formula 20 .bo +21.b, + ... + 2k-1. bx-1- In mathematics, we use the summation notation to write the above formula: k- 2.b; i=0) In a program,...

  • 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 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...

  • Write a program that uses a recursive function to determine whether a string is a character-unit...

    Write a program that uses a recursive function to determine whether a string is a character-unit palindrome. Moreover, the options for doing case sensitive comparisons and not ignoring spaces are indicated with flags. For example "A nut for a jar of tuna" is a palindrome if spaces are ignored and not otherwise. "Step on no pets" is a palindrome whether spaces are ignored or not, but is not a palindrome if it is case sensitive. Background Palindromes are character sequences...

  • In this assignment, you will be creating three static methods as described below: The method duplicate...

    In this assignment, you will be creating three static methods as described below: The method duplicate should accept one parameter of type String (named “str”). The method should return a String with every character in str repeated n times, where n is the length of str if str has an odd number of characters e.g. duplicate("Hat") should return "HHHaaattt" and n is double the length of str if str has an even number of characters E.g. duplicate("Hi") should return "HHHHiiii"....

  • Calculator Project

    AssignmentYou will be designing a calculator complete with user interface to take input from the user, process a response, and produce the output.Step 1: Present a menuFirst thing you should do is present a menu to the user when your program is first ran. Make sure that the operations match the numbers presented below, otherwise the graders won't be able to grade your program.1. Cartesian distance 2. Vector x matrix 3. Normalize 4. Quit Enter command:You will present the menu and wait for the user to input their...

  • 1. You are given a C file which contains a partially completed program. Follow the instructions...

    1. You are given a C file which contains a partially completed program. Follow the instructions contained in comments and complete the required functions. You will be rewriting four functions from HW03 (initializeStrings, printStrings, encryptStrings, decryptStrings) using only pointer operations instead of using array operations. In addition to this, you will be writing two new functions (printReversedString, isValidPassword). You should not be using any array operations in any of functions for this assignment. You may use only the strlen() function...

  • Write a recursive function called freq_of(letter, text) that finds the number of occurrences of a specified...

    Write a recursive function called freq_of(letter, text) that finds the number of occurrences of a specified letter in a string. This function has to be recursive; you may not use loops!   CodeRunner has been set to search for keywords in your answer that might indicate the use of loops, so please avoid them. For example: Test Result text = 'welcome' letter = 'e' result = freq_of(letter, text) print(f'{text} : {result} {letter}') welcome : 2 e and A list can be...

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