473,394 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

is this ok

thanks for the replysir.
i have made this code so far in declaring the NFA. In fact i do know what am
i supposed to do , i just cant get it right.
please have a look at the following code and tell me am i in the right way,
or can i do the covertion from this structure, and if possible (not trying
to bother you) one kind of solution.
thanks much

struct TLink
{
int linkNode;
int stringMax;
int string[5];
};

struct Node
{
int isFinalState;
int max_links;
TLink Link[5];
} NFA[5];

struct DLink
{
int meCilinLidhet;
int stringNo;
int node[5];
};

struct NodeD
{
int stringNode;
int isFinalState;
int max_links;
DLink Link[5];
} DFA[5];

int max_states;
int maxNode;

void NFA_input()
{
int i, j, k, f;
cout<<"\nHow MAny states does the NFA has =";
cin>>max_states;
for (i=0; i<max_states; i++)
{
cout<<"\nIs State q["<<i<<"] final State ? (yes=1, No=0)";
cin>>NFA[i].isFinalState;
cout<<"\nHow many transitions does this State have ?";
cin>>NFA[i].max_links;
for (j=0; j<NFA[i].max_links; j++)
{
cout<<"\nThe "<<j+1<<" transition is linking state q["<<i<<"] with
state =";
cin>>NFA[i].Link[j].linkNode;
cout<<"\nHow many strings make this transition=";
cin>>NFA[i].Link[j].stringMax;
for (k = 0; k < NFA[i].Link[j].stringMax; k++)
{
cout<<"\nEnter those strings=\n";
cout<<"delta["<<k+1<<"]= ";
cin>>NFA[i].Link[j].string[k];
}
}
}
}

void print_NFA()
{
int i, j, k ;
for (i=0; i<max_states; i++)
{
cout<<"\nState q["<<i<<"]";
for (j=0; j<NFA[i].max_links; j++)
{
cout<<"\n is linked with state q["<<NFA[i].Link[j].linkNode<<"]";
cout<<" with string";
for (k = 0; k < NFA[i].Link[j].stringMax; k++)
cout<<" " <<NFA[i].Link[j].string[k];
}
cout<<"\n";

}
cout<<"\nInitial State of the automata is:q[0]\n ";
cout<<"\nFinal States of the automata are: ";
for (i=0; i<max_states; i++)
{
if (NFA[i].isFinalState == 1)
cout<<"\n q["<<i<<"] \t";
}
}
int main()
{
clrscr();
char line[80]="-------------------------------------------------";
NFA_input();
cout<<"\nTranitions of the NFA are: \n";
cout<<line;
print_NFA();
cout<<"\n"<<line;
cin.get(); cin.ignore();
return 0;
}


Jul 22 '05 #1
23 2061
Ricky wrote:
thanks for the replysir.
i have made this code so far in declaring the NFA. In fact i do know what am
i supposed to do , i just cant get it right.
please have a look at the following code and tell me am i in the right way,
or can i do the covertion from this structure, and if possible (not trying
to bother you) one kind of solution.
thanks much
I will review your code, but I have no clue what a NFA is. Perhaps you
should not use acronyms or abbreviations, but spell them out.

struct TLink
{
int linkNode;
int stringMax;
int string[5];
};
Why are there 5 int values for the string?
The '5' is a _magic_ number and should be a named constant, such
as:
const unsigned int MAX_NUMBERS_IN_STRING = 5;
Also, do you want signed or unsigned integers. In many communications
scenarios, numbers are unsigned to allow for more range. If the
number is not negative, declare it as unsigned.

struct Node
{
int isFinalState;
int max_links;
TLink Link[5];
} NFA[5];
1. The member "isFinalState" implies a boolean (true / false) type.
You should name it that way:
bool isFinalState;
2. What is with the number '5'? Magic number again. Convert to
a named constant. See above.

struct DLink
{
int meCilinLidhet;
int stringNo;
int node[5];
};
1. What is with the number '5'? Magic number again. Convert to
a named constant. See above.
2. What is the difference between a TLink and a DLink?
Your names are not very descriptive.

struct NodeD
{
int stringNode;
int isFinalState;
int max_links;
DLink Link[5];
} DFA[5]; 1. What is with the number '5'? Magic number again. Convert to
a named constant. See above.
1. The member "isFinalState" implies a boolean (true / false) type.
You should name it that way:
bool isFinalState;


int max_states;
int maxNode;
Do these variables _need_ to be global?

void NFA_input()
{
int i, j, k, f;
cout<<"\nHow MAny states does the NFA has =";
cin>>max_states;
1. Since the number of states is dynamic, you may want to
consider allocating them from dynamic memory (i.e. using
'new') and using a dynamic container, such as a vector
or list.

2. You don't check for invalid input. What happens if
the user enters "apple" or "3.14159"?
(I believe the input operation will set the stream's
fail bit or bad bit).
for (i=0; i<max_states; i++)
{
cout<<"\nIs State q["<<i<<"] final State ? (yes=1, No=0)";
cin>>NFA[i].isFinalState;
Or:
unsigned int yes_no;
NFA[i].isFinalState = yes_no == 1;

What happens when max_states is 10? You only have 5
elements allocated in your array.

cout<<"\nHow many transitions does this State have ?";
I suggest you flush the output buffer before requesting input:
cout.flush();
cin>>NFA[i].max_links;
What happens if the number of transitions is 30?
You only have 5 allocated.
What happens when the user enters a negative number, such
as -2? You did allow that by specifying max_links as an
int and not an unsigned int.

for (j=0; j<NFA[i].max_links; j++)
{
cout<<"\nThe "<<j+1<<" transition is linking state q["<<i<<"] with
state =";
cin>>NFA[i].Link[j].linkNode;
cout<<"\nHow many strings make this transition=";
cin>>NFA[i].Link[j].stringMax;
for (k = 0; k < NFA[i].Link[j].stringMax; k++)
{
cout<<"\nEnter those strings=\n";
cout<<"delta["<<k+1<<"]= ";
cin>>NFA[i].Link[j].string[k];
Possible array overflow: you only have 5 allocated.
What happens when there are 6, or zero?

}
}
}
}
[snip -- printing function]
int main()
{
clrscr();
This is not a standard C++ function. Do you really need the
screen cleared? The program will be more portable with out it.
For example, in some operating systems, you could redirect the
output of your program into a file. How does clearing the
screen work with redirecting the output?
char line[80]="-------------------------------------------------";
NFA_input();
cout<<"\nTranitions of the NFA are: \n";
cout<<line;
print_NFA();
cout<<"\n"<<line;
cin.get(); cin.ignore();
return 0;
}


Summary
-------
I believe you don't have an efficient data structure. Your
implied requirements allow a dynamic amount of states and
transitions. Fixed sized arrays are very bad for dynamic
quantities of elements. Your I/O is not checked for
boundary conditions or stream failures. Your naming
conventions could use improvement for better readability.

You need to use pointer when dealing with dynamic structures.
If you insist on arrays, place a pointer in your structure
and allocate the array at run-time. You will need to
remember the size of the array because the C++ language
does not provide a sizeof() operation for dynamic arrays.
A std::vector is much safer, and also handles dynamic
expansion.

Your nodes have a common set of members (maybe methods
too), you should factor out the commonalities into
a base class:
struct BaseState
{
bool is_final_state;
unsigned int max_states;
};

struct Node
: public BaseState
{
TLink * links;
};

struct DNode
: public BaseState
{
int stringNode;
DLink * links;
};
--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

Jul 22 '05 #2
"Thomas Matthews" <Th**************************@sbcglobal.net> wrote
in message news:c1*******************@newssvr33.news.prodigy. com...
Ricky wrote:
thanks for the replysir.
i have made this code so far in declaring the NFA. In fact i do know what am i supposed to do , i just cant get it right.
please have a look at the following code and tell me am i in the right way, or can i do the covertion from this structure, and if possible (not trying to bother you) one kind of solution.
thanks much
I will review your code, but I have no clue what a NFA is. Perhaps

you should not use acronyms or abbreviations, but spell them out.


It stands for National Fire Academy. It is in constant competition
with the DFA (Department of Foreign Affairs.)

See http://www.google.com/search?q=NFA+DFA.
Jul 22 '05 #3
Dear sir,
I am so pleased to write you,and i want on this opportunity to thank you about your help,i was wondering if you would mind helping me to write a C program that convert a NFA to an equivalent DFA,i found this program in C++ program but i haven't studied it yet at the university.
I am looking forward to getting you answer.
Sincerely,
Ayoub

Jul 22 '05 #4
Dear sir,
I am so pleased to write you,and i want on this opportunity to thank you about your help,i was wondering if you would mind helping me to write a C program that convert a NFA to an equivalent DFA,i found this program in C++ program but i haven't studied it yet at the university.
I am looking forward to getting you answer.
Sincerely,
Ayoub

Jul 22 '05 #5
Dear sir,
I am so pleased to write you,and i want on this opportunity to thank you about your help,i was wondering if you would mind helping me to write a C program that convert a NFA to an equivalent DFA,i found this program in C++ program but i haven't studied it yet at the university.
I am looking forward to getting you answer.
Sincerely,
Ayoub

Jul 22 '05 #6
Dear sir,
I am so pleased to write you,and i want on this opportunity to thank you about your help,i was wondering if you would mind helping me to write a C program that convert a NFA to an equivalent DFA,i found this program in C++ program but i haven't studied it yet at the university.
I am looking forward to getting you answer.
Sincerely,
Ayoub

Jul 22 '05 #7
Dear sir,
I am so pleased to write you,and i want on this opportunity to thank you about your help,i was wondering if you would mind helping me to write a C program that convert a NFA to an equivalent DFA,i found this program in C++ program but i haven't studied it yet at the university.
I am looking forward to getting you answer.
Sincerely,
Ayoub

Jul 22 '05 #8
"angelayoub" <an********@caramail.com> wrote...
Dear sir,
What if I'm a madam?
I am so pleased to write you,and i want on this opportunity to thank you about your help,i was wondering if you would mind helping me to write a C
program that convert a NFA to an equivalent DFA,i found this program in C++
program but i haven't studied it yet at the university. I am looking forward to getting you answer.


Here is my answer. Read carefully. First, this is a C++ newsgroup.
If you need help with a C program, you're in a wrong place. Please
consider posting to comp.lang.c. Second, if you need some program
written, you're better off contacting your fellow students from the
university. We here don't write programs to strangers. If you want
to hire somebody, consider posting to misc.jobs.offered. Third, if
this is your first time here, consider reading the Welcome message
posted here weekly by Shiva, and the FAQ list. You can find the FAQ
here: http://www.parashift.com/c++-faq-lite/ and the Welcome message
is duplicated at http://www.slack.net/~shiva/welcome.txt. Fourth,
please don't post FIVE TIMES. Be patient, it takes a few minutes
for the people around the globe to see your posting and reply.

There is probably more that you could correct about the way you
posted. I'll leave it to others.

Good luck with your studies!
Jul 22 '05 #9
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:GNvUb.183151$5V2.887680@attbi_s53...
"angelayoub" <an********@caramail.com> wrote...
Dear sir,
What if I'm a madam?
I am so pleased to write you,and i want on this opportunity to

thank you about your help,i was wondering if you would mind helping me to write a C program that convert a NFA to an equivalent DFA,i found this program in C++ program but i haven't studied it yet at the university.
I am looking forward to getting you answer.


Here is my answer. Read carefully. <snip>


Yes. And please don't send unsolicited email.

Jonathan
Jul 22 '05 #10
Dear sir,
I am so pleased to write you,and i want on this opportunity to thank you about your help,i was wondering if you would mind helping me to write a C program that convert a NFA to an equivalent DFA,i found this program in C++ program but i haven't studied it yet at the university.
I am looking forward to getting you answer.
Sincerely,
Ayoub

Jul 22 '05 #11
Dear sir or madam,
I am so pleased to write you,and i want on this opportunity to thank you about your help,i was wondering if you would mind helping me to write a C program that convert a NFA to an equivalent DFA,i found this program in C++ program but i haven't studied it yet at the university.
I am looking forward to getting you answer.
Sincerely,
Ayoub

Jul 22 '05 #12
Dear sir or madam,
I am so pleased to write you,and i want on this opportunity to thank you about your help,i was wondering if you would mind helping me to write a C program that convert a NFA to an equivalent DFA,i found this program in C++ program but i haven't studied it yet at the university.
I am looking forward to getting you answer.
Sincerely,
Ayoub

Jul 22 '05 #13
Dear sir,
I am so pleased to write you,and i want on this opportunity to thank you about your help,i was wondering if you would mind helping me to write a C program that convert a Non deterministic Finite Automat to an equivalent Deterministic Finite Automata,i found this program in C++ program but i haven't studied it yet at the university.
I am looking forward to getting you answer.
Sincerely,
Ayoub

Jul 22 '05 #14
Dear sir or madam,
I am so pleased to write you,and i want on this opportunity to thank you about your help,i was wondering if you would mind helping me to write a C program that convert a NFA to an equivalent DFA,i found this program in C++ program but i haven't studied it yet at the university.
I am looking forward to getting you answer.
Sincerely,
Ayoub

Jul 22 '05 #15
angelayoub wrote:
I am so pleased to write you,and i want on this opportunity to thank you about your help,i was wondering if you would mind helping me to write a C
program that convert a NFA to an equivalent DFA,i found this program in C++
program but i haven't studied it yet at the university. I am looking forward to getting you answer.


Please read this: http://www.slack.net/~shiva/welcome.txt

You are posting to a USENET newsgroup that has different abilities, hence
different rules, from www.talkaboutprogramming.com .

You should expect 24~36 hours before getting an answer. Repeating the
question will annoy the people capable of answering. Further,
www.talkaboutprogramming.com might not be able to show you your own post in
this list for a while.

The only answer for your sparse question is more questions:

Have you used Google.com to search for a C version?

Have you used Google to search for a forum that discusses NFA or DFA?

Why do you think you need C, just because you have not learned to write C++?

Have you tried to compile the source you have?

Have you tried to contact the forum most closely related to the source you
have - such as it's author's favorite mailing list?

Could you read the source and look up the keywords you don't know in a C++
tutorial? (Relying only on a university for an education is very limiting.
You will not make it in the Real World without the ability to teach yourself
new languages.)

--
Phlip
http://www.xpsd.org/cgi-bin/wiki?Tes...UserInterfaces


Jul 22 '05 #16
I am so pleased to write you,and i want on this opportunity to thank
you
about your help,i was wondering if you would mind helping me to write a
C
program that convert a NFA to an equivalent DFA,i found this program in
C++
program but i haven't studied it yet at the university.
I am looking forward to getting you answer.

Jul 22 '05 #17
angelayoub wrote:
I am so pleased to write you,and i want on this opportunity to thank
you
about your help,i was wondering if you would mind helping me to write a
C
program that convert a NFA to an equivalent DFA,i found this program in
C++
program but i haven't studied it yet at the university.
I am looking forward to getting you answer.


By the number of posts in thes newsgroup, I'd say you are not.
You don't read the reply's by others (hmm, so what makes me
think the OP will read this one?).

Use your favorite search engine and search the following
newsgroups, using the terms "NFA DFA convert"
news:comp.programming (your best bet)
news:comp.lang.c (for questions about the C language)
--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

Jul 22 '05 #18
In article <d3b401ce7fda32c320f2ca006ab3c478
@localhost.talkaboutprogramming.com>, an********@caramail.com says...
Dear sir,
I am so pleased to write you,and i want on this opportunity to thank you about your help,i was wondering if you would mind helping me to write a C program that convert a NFA to an equivalent DFA,i found this program in C++ program but i haven't studied it yet at the university.
I am looking forward to getting you answer.


First of all, it looks a great deal as if your news program is mis-
configured, or else you're expecting Usenet to be somewhat different
than it really is -- I'm seeing about a half dozen copies of your post.

In any case, almost any decent book on compiler construction will cover
NFA to DFA conversion. The usual recommendation in this is area is
"Compilers: Principles, Techniques and Tools", but Aho, Sethi and
Ullman, generally known as The Dragon Book, due to the picture on the
cover (of a knight in armor slaying a dragon).

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jul 22 '05 #19
I was wondering if would someone mind giving a C program that minimizate the states of DFA.

Jul 22 '05 #20
I was wondering if someone would mind giving an algorithm that if a DFA
contain a nonproductive state.

Jul 22 '05 #21
angelayoub wrote:
I was wondering if someone would mind giving an algorithm that if a DFA
contain a nonproductive state.


By definition, DFA states are all producible unless there are no
transitions that go there.
Jul 22 '05 #22
This sounds an awful lot like a homework question. Do you know what an
algorithm is? What a DFA is? What a nonproductive state is? Try to ask
questions about things you don't know or understand, not ask us to do your
homework problem. By the way, this is a newgroup where questions about C++
are asked, not about DFAs.

"angelayoub" <an********@caramail.com> wrote in message
news:2f******************************@localhost.ta lkaboutprogramming.com...
I was wondering if someone would mind giving an algorithm that if a DFA
contain a nonproductive state.

Jul 22 '05 #23
"angelayoub" <an********@caramail.com> wrote in message news:<2f******************************@localhost.t alkaboutprogramming.com>...
I was wondering if someone would mind giving an algorithm that if a DFA
contain a nonproductive state.


DFA's are a special case of graph theory. Graph theory in C++ is covered
by the boost::graph library, so peraps you could look there?

www.boost.org

Regards,
Michiel Salters
Jul 22 '05 #24

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: William C. White | last post by:
Does anyone know of a way to use PHP /w Authorize.net AIM without using cURL? Our website is hosted on a shared drive and the webhost company doesn't installed additional software (such as cURL)...
2
by: Albert Ahtenberg | last post by:
Hello, I don't know if it is only me but I was sure that header("Location:url") redirects the browser instantly to URL, or at least stops the execution of the code. But appearantely it continues...
3
by: James | last post by:
Hi, I have a form with 2 fields. 'A' 'B' The user completes one of the fields and the form is submitted. On the results page I want to run a query, but this will change subject to which...
0
by: Ollivier Robert | last post by:
Hello, I'm trying to link PHP with Oracle 9.2.0/OCI8 with gcc 3.2.3 on a Solaris9 system. The link succeeds but everytime I try to run php, I get a SEGV from inside the libcnltsh.so library. ...
1
by: Richard Galli | last post by:
I want viewers to compare state laws on a single subject. Imagine a three-column table with a drop-down box on the top. A viewer selects a state from the list, and that state's text fills the...
4
by: Albert Ahtenberg | last post by:
Hello, I have two questions. 1. When the user presses the back button and returns to a form he filled the form is reseted. How do I leave there the values he inserted? 2. When the...
1
by: inderjit S Gabrie | last post by:
Hi all Here is the scenerio ...is it possibly to do this... i am getting valid course dates output on to a web which i have designed ....all is okay so far , look at the following web url ...
2
by: Jack | last post by:
Hi All, What is the PHP equivilent of Oracle bind variables in a SQL statement, e.g. select x from y where z=:parameter Which in asp/jsp would be followed by some statements to bind a value...
3
by: Sandwick | last post by:
I am trying to change the size of a drawing so they are all 3x3. the script below is what i was trying to use to cut it in half ... I get errors. I can display the normal picture but not the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.