Thread: plz help me friends

  1. #1
    Registered User
    Join Date
    Jun 2011
    Posts
    22

    plz help me friends

    hi, I coded nfa to dfa program
    Code:
    #include <iostream>
    using namespace std;
    int main()
    {
    	char **dfa_trans = 0;
    	dfa_trans = new char *[3];
    	for (int i=0;i<3;i++)
    	{
    		dfa_trans[i]=new char[2];
    	}
    
    	char **nfa_trans=0;
    	nfa_trans=new char *[3];
    	for (int i=0;i<3;i++)
    	{
    		nfa_trans[i]=new char[2];
    	}
    	
    	char *dfa_state=0;
    	dfa_state=new char [3];
    	
    	char *nfa_state=0;
    	nfa_state=new char [3];
    	
    	char *dfa_start=0;
    	dfa_start=new char [3];
    	
    	char *Alphabet=0;
    	Alphabet=new char [3];
    
    
    	int i,j,k,n_alphabet,n_nfastate,e=0,c=0,temp=0;
    	char nfa_start;
    
    	
    	cout<<"please enter the number of alphabes you wish to use: "<<end1;
    	cin>>n_alphabet;
    	cout<<"please enter alphabets.Note: e stands for ebsilon" <<end1;
    	for (i=0;i<n_alphabet;i++)
    		cin>>Alphabet[i];
    
    	cout<<"please enter the number of states you need to use: "<<end1;
    	cin>>n_nfastate;
    	cout<<"enter name of states" <<end1;
    	for (i=0;i<n_alphabet;i++)
    		cin>>nfa_state[i];
    	
    	cout<<"please enter your start state: "<<end1;
    	cin>>nfa_start;
    	cout<<"enter * if you don't wish to use an alphabet" <<end1;
    	for (j=0;j<n_nfastate;j++)
    	{	
    		cout<<"at state "<<nfa_state[j];
    		for(i=0;i<n_alphabet;i++)
    		{
    			cout<<" if alphabet "<<" ' "<<alphabet[i]<<" ' "<<" go to: "
    	;
    			cin>>nfa_trans[i] [j];
    			if (Alphabet[i]=='e' && nfa_trans[i] [j] ! = '*')
    			{
    				e++;
    				dfa_start[e-1]=nfa_state[j];
    			}
    		}
    	}
    
    	cout<<"****************e= "<<e<<end1;
    	for(k=0;k<e;k++)
    	{
    	
    		if(dfa_start[k]!=nfa_start)
    		{
    			c++;
    		}
    	}
    	if(c==e)
    	}
    		dfa_start[e]=nfa_start;
    		e++;
    		}
    	for(k=0;k<e;k++)
    		if(dfa_start[e-1]<dfa_start[k])
    		{	
    			temp=dfa_start[k];
    			dfa_start[k]=dfa_start[e-1];
    			dfa_start[e-1]=temp;
    		}
    
    	cout<<"e= "<<e<<end1;
    	cout<<Dfa states:"<<end1;
    	for(k=0;k<e;k++)
    	{
    		cout<<dfa_start[k]<<end1;
    	}
    	cout<<"your nfa transition function is the following:"<<end1;
    	for(j=0 ; j<n_nfastate ; j++)
    	{
    		cout<<end1;
    		for(i=0;i<n_alphabet;i++)
    		{
    			cout<<nfa_trans[i] [j]<<"             ";
    		}	
    		cout<<end1;
    	}
    	cout<<"Dfa transition function:"<<end1;
    	for(k=0;k<e;k++)
    	{
    	
    		for(i=0;i<n_alphabet-1;i++)
    		{
    			if(Alphabet[i]!='e' && nfa_trans[i][k]=='*')
    			{
    				nfa_trans[i][k]=dfa_start[k];
    			}
    			cout<<"at state "<<" "<<dfa_start[k]<<" at alphabet "<<" ' "<<Alphabet[i]<<" ' "<<" go to: "<<nfa_trans[i][k]<<end1;
    		}
    	}
    	cout<<end1;
    		return 0;
    	}
    but this have errors, please debug this code and make true the bugs, thank you my friends

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > please debug this code and make true the bugs, thank you my friends
    Translation:
    I found some crap code on the net matching some keywords, it doesn't work, and I'm clueless as to what needs to be fixed.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jun 2011
    Posts
    22
    Quote Originally Posted by Salem View Post
    > please debug this code and make true the bugs, thank you my friends
    Translation:
    I found some crap code on the net matching some keywords, it doesn't work, and I'm clueless as to what needs to be fixed.

    this code don't works? why?

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Maybe you need to be even less subtle, Salem.

    Where's that 2x4?
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  5. #5
    Registered User
    Join Date
    Jun 2011
    Posts
    22
    Quote Originally Posted by grumpy View Post
    Maybe you need to be even less subtle, Salem.

    Where's that 2x4?
    this code works well, i change that up code. but when code arrives to ************e place, program closed, why? plz help on this problem.

    new code :
    Code:
    #include <iostream>
    #include <string>
    #include <stdlib>
    using namespace std;
    int main()
    {
    	char **dfa_trans = 0;
    	dfa_trans = new char *[3];
    	for (int i=0;i<3;i++)
    	{
    		dfa_trans[i]=new char[2];
    	}
    
    	char **nfa_trans=0;
    	nfa_trans=new char *[3];
    	for (int i=0;i<3;i++)
    	{
    		nfa_trans[i]=new char[2];
    	}
    	
    	char *dfa_state=0;
    	dfa_state=new char [3];
    	
    	char *nfa_state=0;
    	nfa_state=new char [3];
    	
    	char *dfa_start=0;
    	dfa_start=new char [3];
    	
    	char *Alphabet=0;
    	Alphabet=new char [3];
    
    
    	int i,j,k,n_alphabet,n_nfastate,e=0,c=0,temp=0;
    	char nfa_start;
    
    	
    	cout<<"please enter the number of alphabes you wish to use:"<<endl;
    	cin>>n_alphabet;
    	cout<<"please enter alphabets.Note: e stands for ebsilon"<<endl;
    	for (i=0;i<n_alphabet;i++)
    		cin>>Alphabet[i];
    
    	cout<<"please enter the number of states you need to use:"<<endl;
    	cin>>n_nfastate;
    	cout<<"enter name of states:"<<endl;
    	for (i=0;i<n_alphabet;i++)
    		cin>>nfa_state[i];
    	
    	cout<<"please enter your start state:"<<endl;
    	cin>>nfa_start;
    	cout<<"enter * if you don't wish to use an alphabet"<<endl;
    	for (j=0;j<n_nfastate;j++)
    	{	
    		cout<<"at state "<<nfa_state[j];
    		for(i=0;i<n_alphabet;i++)
    		{
    			cout<<" if alphabet "<<" ' "<<Alphabet[i]<<" ' "<<" go to: "
    	;
    			cin>>nfa_trans[i] [j];
    			if (Alphabet[i]=='e' && nfa_trans[i] [j] !='*')
    			{
    				e++;
    				dfa_start[e-1]=nfa_state[j];
    			}
    		}
    	}
    
    	cout<<"****************e= "<<e<<endl;
    	for(k=0;k<e;k++)
    	{
    	
    		if(dfa_start[k]!=nfa_start)
    		{
    			c++;
    		}
    	}
    	if(c==e)
    	{
    		dfa_start[e]=nfa_start;
    		e++;
    		}
    	for(k=0;k<e;k++)
    		if(dfa_start[e-1]<dfa_start[k])
    		{	
    			temp=dfa_start[k];
    			dfa_start[k]=dfa_start[e-1];
    			dfa_start[e-1]=temp;
    		}
    
    	cout<<"e= "<<e<<endl;
    	cout<<"Dfa states:"<<endl;
    	for(k=0;k<e;k++)
    	{
    		cout<<dfa_start[k]<<endl;
    	}
    	cout<<"your nfa transition function is the following:"<<endl;
    	for(j=0;j<n_nfastate;j++)
    	{
    		cout<<endl;
    		for(i=0;i<n_alphabet;i++)
    		{
    			cout<<nfa_trans[i][j]<<"             ";
    		}	
    		cout<<endl;
    	}
    	cout<<"Dfa transition function:"<<endl;
    	for(k=0;k<e;k++)
    	{
    	
    		for(i=0;i<n_alphabet-1;i++)
    		{
    			if(Alphabet[i]!='e' && nfa_trans[i][k]=='*')
    			{
    				nfa_trans[i][k]=dfa_start[k];
    			}
    			cout<<"at state  "<<"  "<<dfa_start[k]<<" at alphabet "<<" ' "<<Alphabet[i]<<" ' "<<" go to: "<<nfa_trans[i][k]<<endl;
    		}
    	}
    	cout<<endl;
    		return 0;
    	}

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > this code don't works? why?
    Maybe it's a problem with the chair?

    If your "plan" is to pass whatever course you're on through "google" + "forum nagging", then you're just going to fail miserably. You really don't want that failure to be a week into your new job, obtained as a result of your fake degree obtained through copy/pasting.

    Write your OWN code, or drop the course and find something else to do in life - programming is not for you.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User
    Join Date
    Jun 2011
    Posts
    22
    plz go out from my forum

  8. #8
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Now, there's a reversal. A new member asking a site moderator to leave. If it comes to a contest, I know which way I would bet.

    For abbaskhan, this link will help you understand the responses you're getting.

    It would also be a good idea to type in english, with uppercase letters at the start of sentences, rather than using SMS tapping.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  9. #9
    Registered User
    Join Date
    Jun 2011
    Posts
    22
    Quote Originally Posted by grumpy View Post
    Now, there's a reversal. A new member asking a site moderator to leave. If it comes to a contest, I know which way I would bet.

    For abbaskhan, this link will help you understand the responses you're getting.

    It would also be a good idea to type in english, with uppercase letters at the start of sentences, rather than using SMS tapping.

    I don't know english well, I'm french, sorry

  10. #10
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    The code you've found is crap anyway, so you'd yourself a favour to start from scratch.
    Anyway, like mentioned, show some code YOU'VE written, and we'll help you further.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. hello friends
    By gitac in forum C Programming
    Replies: 6
    Last Post: 06-30-2012, 11:08 AM
  2. need a help friends... pls
    By joelove in forum C Programming
    Replies: 4
    Last Post: 02-08-2010, 12:32 PM
  3. Friends...
    By pritin in forum C++ Programming
    Replies: 3
    Last Post: 03-27-2007, 06:38 AM
  4. Hello Friends , Help Me
    By RahulDhanpat in forum C Programming
    Replies: 3
    Last Post: 04-22-2006, 09:08 PM
  5. Thanx Friends..
    By madmax in forum C Programming
    Replies: 1
    Last Post: 03-15-2003, 08:37 AM