Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
28 views9 pages

Theory of Computation Project

The document outlines a series of programming experiments related to the Theory of Computation for a B.Tech course in Computer Science & Engineering. Each experiment includes a specific task, such as designing a program to accept strings with certain properties, and provides sample code implementations in C++. The experiments cover various concepts including string manipulation, binary representation, and machine design.

Uploaded by

Dev Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views9 pages

Theory of Computation Project

The document outlines a series of programming experiments related to the Theory of Computation for a B.Tech course in Computer Science & Engineering. Each experiment includes a specific task, such as designing a program to accept strings with certain properties, and provides sample code implementations in C++. The experiments cover various concepts including string manipulation, binary representation, and machine design.

Uploaded by

Dev Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Sanghvi Institute of

Management & Science


Session 2024 – 25

B.Tech
Computer Science & Engineering

Subject – Theory of Computation


Semester – 5th Sem

Submitted by – Dev Patil


Roll No. – 0837CS21100
Experiment: 1

Design a Program for creating machine that accepts three consecutive one.

CODE:-

#include

#include using namespace std;

bool FuncCheck(string input)

{ int Count = 0;

For( int c=0; c<< "Enter a string: "; cin >> ss; if

(FuncCheck(ss))

{ cout << "The input string contains three consecutive ones." << endl;

Else

{ cout << "The input string does not contain three consecutive ones." << endl;

}
Experiment: 2

Design a Program for creating machine that accepts the string always ending with 101.

CODE:-

#include

#include using namespace std; bool check(string input) { int length = input.length(); if (length <

3) { return false; // The input is too short to end with "101". } if(input[length - 3] == '1' &&

input[length - 2] == '0' && input[length - 1] == '1') return true; } int main() { string ss; cout << "Enter

a string: "; cin >> ss; if (check(ss))

{ cout << "The input string ends with '101'." << endl; }

Else

{ cout << "The input string does not end with '101'." << endl; } return 0;}
Experiment : 3

Design a Program for Mode 3 Machine.

DE: #include #include using namespace std;

bool checkMod3(string String)

{ int state = 0; for (int i=0;i<< "Enter a binary string: ";

cin >> ss; if (checkMod3(ss)) { cout << "String

Accepted" << endl; } else

{ cout << "String Rejected" << endl; } }


EXPERIMENT : 4

Design a program for accepting decimal number divisible by 2.

CODE: #include

#include using namespace std; string decimalToBinary(int decimal) { if (decimal

== 0) { return "0"; } string binary = ""; while(decimal > 0) { int remainder = decimal

% 2; binary = to_string(remainder) + binary; decimal /= 2; } return binary; } bool

checkDivisibility(string binaryNumber) { if (binaryNumber.empty())

{ return false; } return (binaryNumber[binaryNumber.size() - 1] ==

'0'); } int main() { int decimalNumber; cout << "Enter a decimal

number: "; cin >> decimalNumber; string s =

decimalToBinary(decimalNumber); cout<<"The binary

representation of given decimal no is: "<<s<<< "The given decimal

number is divisible by 2." << endl; }else { cout << "The given decimal

number is not divisible by 2." << endl;


Experiment : 5

Design a program for creating a machine which accepts string having equal no. of 1’s & 0’s.

CODE:- include

#include using namespace std; bool

checkString(string input)

{ int onesCount = 0; int zerosCount = 0; for (int

i=0;i<< "Enter a string: "; cin >> ss; if (checkString(ss))

{ cout << "The input string has an equal number of '1's and '0's." << endl; } else { cout << "The

input string does not have an equal number of '1's and '0's." << endl; } return 0;}
Experiment : 6

Design a program for creating a machine which count number of 1’s and 0’s in a string. }
Experiment : 7

Design a Program to find 2’s complement of a given binary number


Experiment : 8

Design a Program which will increment the given binary number by 1.

CODE: #include

#include using namespace std; string

incrementBinary(string binary)

{ string result = binary; int carry = 1; for (int i =

binary.size() - 1; i >= 0; i--)

{ if (carry == 0) { break; } if (binary[i] == '0') {

result[i] = '1'; carry = 0; } else { result[i] = '0'; } } if

(carry == 1) { result = '1' + result; } return result; }

int main() { string binary; cout << "Enter a binary

number: "; cin >> binary;

string incrementedBinary =

incrementBinary(binary);

cout << "Incremented

binary:"<<incrementedBinary <<endl;

You might also like