![]() |
|
|
#1 |
|
Junior Member
Join Date: Sep 2010
Location: NC
Posts: 9
![]() |
I am a student majoring in Security. We are taking a programming class and I am not understanding the structure part at all. I know a structure is a basic unit of programming logic and each sturcture is one of the following: sequence, selection, and loop. What is an acceptable sturctured program though? The book gives all these illustrations with a big DON'T beside them, I am confused.
__________________
Members don't see ads in threads. Register your free account today and become a member on Tech Today Online, gaining access to posting privileges, contests, free plug-ins and other downloads, unlimited online storage for your photographs, reviews, free marketplace listings, and much more. |
|
|
|
|
|
#2 |
|
Senior Member
Join Date: Jul 2010
Location: Doylestown, PA
Posts: 159
![]() |
Structured programming enforces logical structure to make the program more efficient, easy to understand and maintain.
Large routines are broken down into smaller modules, and use of the GOTO statement is strongly discouraged Let's say you have a program that reads a data file line by line, processes the data and prints it. A structured program may look like this: Open File While (end of file is not reached) read line of data if (error condition) Call Error routine end program end if Call routine to process and print data end while end program The same program that does not use structured programming might look like this: Open file LABEL1: read line of file if there was data process data.... print data.... else GOTO LABEL2 GOTO LABEL1 LABEL2: exit program Even in this simple example, you can see that it can easily become hard to follow, and the chance of introducing bugs increases as the lines of code increase. I hope this helps answer you question. If not, post again and we'll give it another shot.
__________________
-John |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Sep 2010
Location: NC
Posts: 9
![]() |
Thanks John, That makes more sense than the book. Can you place a sequence within the true half of a dual alternative decision in a structured program? This is just one of the questions the book ask. I know that the dual alternative is used in the selection structure but can it be used in the sequence structure, since sequence you follow an action in a task in order? I really like the programming part that I have learned so far but not sure about structures.
|
|
|
|
|
|
#4 |
|
Senior Member
Join Date: Jul 2010
Location: Doylestown, PA
Posts: 159
![]() |
Yes, you certainly can.
In a single alternative structure, if a condition is true, you do something, if it's false, you do nothing. In a dual-alternative basically means that if a condition is true, you do something, and if it's false, you do something else. Within that IF construct, IF something is true, you might do some things. If it's false, you might do other things. For example: If today = Monday do action 1 do action 2 do action 3 do action 4 do action 5 else do action 6 do action 7 ENDIF
__________________
-John |
|
|
|
|
|
#5 |
|
Junior Member
Join Date: Sep 2010
Location: NC
Posts: 9
![]() |
Ok I see what you mean, so you could place decision within a loop and a loop within one of the steps in a sequence, right. I can understand the psuecode lots better than the flowcharts.
Thank you |
|
|
|
|
|
#6 |
|
Senior Member
Join Date: Jul 2010
Location: Doylestown, PA
Posts: 159
![]() |
yes, that's correct. You're getting it now
![]() That's exactly why I used pseudocode for the examples....it's how I learned and it makes the most sense to me. I only used flowcharts to diagram the highest levels of functionality, much like an outline.
__________________
-John |
|
|
|
|
|
#7 |
|
Junior Member
Join Date: Sep 2010
Location: NC
Posts: 9
![]() |
You're right I do understand the examples you gave and my mind is wrapping around it better. Thank you so much.
|
|
|
|
|
|
#8 |
|
Junior Member
Join Date: Sep 2010
Location: NC
Posts: 9
![]() |
Thanks again John, I made a 95 on the quiz she threw at us yesterday.
|
|
|
|
|
|
#9 |
|
Senior Member
Join Date: Jul 2010
Location: Doylestown, PA
Posts: 159
![]() |
That's awesome Roxy - you should be very proud of yourself. I'm happy for you!
__________________
-John |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|