/******************************************************************************
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;
void user_choice()
{
string str;
string line;
fstream newfile;
char user_input;
int max_n = 41;
//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;
//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, line))
{
//prints the data of the string
cout<< line << endl;
}
}
}
//if the user enters n, program terminates
if(user_input == 'n')
{
cout<<"program terminates"<<endl;
}
exit(0);
}
//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. Do you want to enter a string?";
cin>> str;
}
}
//DFA implementation
void DFA_implement()
{
//initialization
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 = 1;
int current_state = 1;
string final_string = ".com";
int max_DFA_states = 41;
int previous_state = 0;
int final_state = 41;
int count = 0;
char c = 'a';
//begins with the start state
//prints the start state
cout<<"The start state is: "<< start_state << endl;
for(int i = 0; i < max_DFA_states; i++)
{
//After string is processed on dfa, print the character and name of the current state of dfa
c++;
cout<<"The character is: "<< c << endl;
//After string is processed on dfa, print the name of the current state of dfa
current_state++;
previous_state += current_state;
cout<<"The name of the current state of dfa is: "<< current_state <<endl;
}
for(int i = 0; i < 1; i++)
{
cout<<"The character is: "<< s3 <<endl;
}
//checks if the character reaches end of the string
if(current_state == 41)
{
cout<<"stop, the final string is: "<< final_string << endl;
}
}
//check whether string is accepted or rejected
void check_string()
{
string s;
string final_string= {".com"};
int max_n = 40;
int max_DFA_states = 40;
int previous_state = 0;
int final_state = 42;
char c;
//prints the final state
cout<<"The final state is: "<< final_state <<endl;
//if final state is reached, check whether string is accepted or rejected
if (max_DFA_states >= 40 || final_string == ".com")
{
//string is accepted when the L1 ends in .com
cout<<"String is accepted"<<endl;
}
else
{
cout<<"string is not accepted"<<endl;
}
}
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 = 41;
char user_input;
string s;
//function calls
DFA_implement();
check_string();
user_choice();
return 0;
}