Week 4 Algorithms

profileOMG
weeks_work.docx

Work 1

While-End Repetition Structure

Actions for 'While-End Repetition Structure'

Subscribe

Hide Description

Create your own unique While-End  repetition structure. You decide the theme. You should provide both the pseudocode and the flowchart of your example. Be sure to provide an overview of what your repetition structure is doing.Please keep the design simple for this exercise. Just a few lines of code is all that is needed for this response.

Also provide the C code and results of testing your code in an online compiler. Again, this should be a simple loop with just a few lines of code.

Work 2

After reading all of the week 4 reading material, please answer the following question:

What do you feel is the output for the code corresponding to the following pseudocode? Post your answer into Week 4 Discussion Topic using a concept called desk checking:

 

Desk-checking: This phase is sometimes avoided by the programmer who is looking for a shortcut and is eager to run the program on the computer once it is written. However, with careful desk-checking you may discover several errors and possibly save yourself time in the long run. In desk-checking you simply sit down and mentally trace, or check, the logic of the program to attempt to ensure that it is error-free and workable. Many organizations take this phase a step further with a walkthrough, a process in which a group of programmers-your peers-review your program and offer suggestions in a collegial way.

 

* Student feedback and assistance is mandatory. Review your fellow student’s answer and either agree with their response or provide assistance where you think they may be off track. DO NOT PROVIDE THE ANSWER BUT RATHER ASSISTANCE! All answers become final on 11/25/15 (2359); if you need Instructor assistance then specifically request it via your discussion post.

CLASSMATES ANSWER FOR U TO COMMENT ON!!

1) Matthew Coates posted Oct 21, 2015 10:34 PM Subscribe

I feel the output for the pseudocode would be;

123, 123, -+-+-

And how I got this was... For A, A is equal to 1, however A is also being increased by increments of 1 until A is less than or equal to 3. So when the pseudocode "Writes A" it will be 1,2,3.

For B, it is the same situation as A, except for the fact that the highest B can go is the highest value that A has, thanks to the "B<=A", so when we "Write B" we get the same as A, 1,2,3.

For C... it never tells us to write anything that C's conditions represent... it just tells us to write Dash+Dash+Dash. Since Dash is a "CHAR" and not an "INT" we cant really add it as if it were numbers, so... we would write it as -+-+- because of the whole Set Dash = "-"

I hope I utilized desk-checking appropriately. I apologize if my response is confusing, but I am a bit confused. If anyone can guide me in the right direction I would appreciate it!

Thanks!

Matt

2) Kenneth Hartman posted Oct 20, 2015 9:37 PMLast edited: Tuesday, October 20, 2015 9:37 PM EDT Subscribe

I believe the output would be:

11---212------3123---------

An assumption I am making is that the last loop for the value C is not actually trying to add the dash characters together but is really printing the character three times in a row.

 

3) Brady Woods posted Oct 22, 2015 9:32 PM Subscribe

My answer was:

11---212------3123---------

It took me a while to figure it out, I got confused after the For(A) ended the first time. I forgot to set B back to 1 when I went through the For(A) again.

SOLVE!!!

PSEUDOCODE:

 

Declare Dash As Character

Declare A, B, C As Integer

Set Dash = “ – “

 

For (A = 1; A <= 3; A++)

{

     Write A

 

     For (B = 1; B <= A; B++)

     {

         Write B

     }

     End For (B)

 

   For (C = 1; C < = A; C++)

   {

       Write Dash + Dash + Dash

     }

     End For (C)

 

}

End For (A)  

HOMEWORK