/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby,
C#, OCaml, VB, Perl, Swift, Prolog, Javascript, Pascal, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
//Nirali Patel
//Ucid:np92
#include <iostream>
#include <fstream>
#include <string>
#include <array>
using namespace std;
//checks if the user wants to enter a string
void user_choice()
{
char user_input;
string str;
fstream newfile;
int max_n = 20;
//checks if the user wants to enter a string
for(int i = 0; i < max_n; i++)
{
cout<<"Do you want to enter a string?"<<endl;
cin>> user_input;
//if the user enters y, it asks to enter a string over the alphabet
if(user_input == 'y')
{
cout<<"Please enter a string over a alphabet:"<<endl;
cin>> str;
}
//if the user enters n, program terminates
if(user_input == 'n')
{
cout<<"Your done"<<endl;
}
//opens the file to read the string
newfile.open("./in.txt", ios::in);
//checks whether file is open
if (newfile. is_open())
{
string str;
//reads data from file object and puts it into string
while (getline(newfile, str))
{
//prints the data of the string
cout<< str[i] << endl;
}
}
}
//closes the file object
newfile.close();
//if the user enters neither y nor n, then asks the user again to enter a string
while((user_input != 'y') || (user_input != 'n'))
{
cout<<"Wrong input. Please try again."<<endl;
cout<<"Do you want to enter a string"<<endl;
cin>> user_input;
}
}
void DFA_implement()
{
//DFA implementation
//begins with the start state of DFA
string length[25];
int numbers[9];
char string1[25];
string letters = {'a', 'b', 'c', 'd','e', 'f', 'g', 'h', 'i', 'j', 'k',
'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
int array[] = {0,1,2,3,4,5,6,7,8,9};
char s1[] = {'a', 'b', 'c', 'd','e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
string s2[50] = {".a", ".b", ".c", ".d", ".e", ".f", ".g", ".h", ".i", ".j", ".k", ".l", ".m",
".n", ".o", ".p", ".q", ".r", ".s", ".t", ".u", ".v", ".w", ".x", ".y", ".z"};
string s3 = {".com"};
int start_state;
int current_state = 'a';
char final_string = 'z';
int max_DFA_states = 82;
int previous_state = 0;
int final_state = 82;
int count = 0;
char c;
//checks the start state
if(c == 'a')
{
start_state = 1;
//prints the start state
cout<<"The start state is: "<< start_state << endl;
}
//After string is processed on dfa, print the character and name of the current state of dfa
for(int i = 0; i < max_DFA_states; i++)
{
c += count;
cout<<"The character is: "<< c <<endl;
if(c == 'a' && c == 'b')
{
previous_state = 'a';
previous_state += current_state;
cout<<"The name of the current state of dfa is: "<< current_state <<endl;
}
//check if the character reaches end of the string
if(c == 'z')
{
cout<<"stop, the final string is: "<< final_string << endl;
}
}
}
//check whether string is accepted or rejected
void check_string()
{
string s;
string s3 = {".com"};
int max_n = 82;
int max_DFA_states = 82;
int previous_state = 0;
int final_state = 82;
final_state += max_n;
//if final state is reached, check whether string is accepted or rejected
if ((max_DFA_states == 82) || (string) s3 == ".com")
{
//string is accepted when the L1 ends in .com
cout<<"String is accepted"<<endl;
}
else
{
cout<<"string is not accepted"<<endl;
}
//function calls
user_choice();
DFA_implement();
check_string();
}
int main()
{
//Prints project 1, section number, semester, written by, & Instructor: Marvin Nakayama,
[email protected]
cout<<"Project 1 for CS 341"<<endl;
cout<<"Section number: 007"<<endl;
cout<<"Semester: Fall 2022"<<endl;
cout<<"Written by: Nirali Patel"<<endl;
cout<<"Instructor: Marvin Nakayama,
[email protected]"<<endl;
int max_n = 85;
char user_input;
string s;
//function calls
user_choice();
DFA_implement();
check_string();
}