Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Algorithms Am I on the right track?  (Read 6536 times)

0 Members and 1 Guest are viewing this topic.

webdev57

    Topic Starter


    Starter

    • Experience: Beginner
    • OS: Unknown
    Algorithms Am I on the right track?
    « on: September 02, 2011, 09:47:23 AM »
    I really want to understand this was wondering if I have the right idea as far as answering the questions so far. It seems to be so basic ~ for an example, I think if I input 55 the output would be both outputs: output "your grade is" 55  and output "you did OK", I  know X represents the integer right?

    input X

    if (0 <= X and X < 49)
       output "you fail"

    else if (50 <= X and X < 70)
       output "your grade is" X
       output "you did OK"

    else if (70 <= X and X < 85)
    output "your grade is" X
       output "you did well"

    else if (85 <= X and X < 100)
    output "your grade is" X
       output "you did great"

    endif
    output "how did you do?"

    •   What will be printed if the input is 0? "you fail" (would “your grade is X” also be an output?)

    •   What will be printed if the input is 100? "you did great" (would “your grade is X” also be an output?)

    •   What will be printed if the input is 51? "you did OK" (would “your grade is X” also be an output?)
    •   What will be printed if the user enters “Wingding”? Nothing?
    •   Is this design robust? If so, explain why. If not, explain what you can do to make it robust.
    •   How many levels of nesting are there in this design?  4?
    •   Provide a set of values that will test the normal operation of this program segment. Defend your choices.
    •   Provide a set of test values that will cause each of the branches to be executed.
    •   Provide a set of test values that test the abnormal operation of this program segment.
    Any number less than 0, such as -1, or any number over 100 such as 101 and anything that is not an integer.

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: Algorithms Am I on the right track?
    « Reply #1 on: September 02, 2011, 03:04:23 PM »
    Yes, you are on the track.
    What language is this?

    Salmon Trout

    • Guest
    Re: Algorithms Am I on the right track?
    « Reply #2 on: September 02, 2011, 04:40:17 PM »
    What language is this?

    An conceptual teaching language, maybe?

    webdev57

      Topic Starter


      Starter

      • Experience: Beginner
      • OS: Unknown
      Re: Algorithms Am I on the right track?
      « Reply #3 on: September 02, 2011, 05:23:14 PM »
      I am not sure if it is a language, I am pretty new at this. So can someone tell me this..when would

      endif
      output "how did you do?"

      pop up? I mean if there is no room for error, or no error output, would that even be relevant? And is my answer of there being 4 nesting correct? Or is only one nest since all the info comes in between input X and endif? I am sorry, I am trying to understand. Thanks for your input.

      Geek-9pm


        Mastermind
      • Geek After Dark
      • Thanked: 1026
        • Gekk9pm bnlog
      • Certifications: List
      • Computer: Specs
      • Experience: Expert
      • OS: Windows 10
      Re: Algorithms Am I on the right track?
      « Reply #4 on: September 02, 2011, 07:54:23 PM »
      As I  understand, you want to find where a scalper is in a range of values, then print a message for that range only. Normally the variable is non the left and the constant t is on the right.
      Here is a similar solution. We make a block and break out of the block when we are in a range.
      Let invest a thing called "block" so we don't need the else if thing.
      Code: [Select]
      begin block
      if X < 50 {
      output "you fail"
      break
      }

      if  X < 70 {
      output "your grade is" X
      output "you did OK"
      break
      }

      if X < 85 {
      output "your grade is" X
      output "you did well"
      break
      }

      if  X < 100 {
      output "your grade is" X
      output "you did great"
      break
      }

      output "your grade is " X
      output "please report to the dean's office"

      end block
      output "end of report"

      I believe this is what you intend, but it is maybe not self-evident, But that is how programmers do things.
      It might be easier to understand if you made and object  that tests for range and outputs a message.

      webdev57

        Topic Starter


        Starter

        • Experience: Beginner
        • OS: Unknown
        Re: Algorithms Am I on the right track?
        « Reply #5 on: September 02, 2011, 08:27:42 PM »
        That is great, you have really assisted me in understanding this on a much better level. Thank you so much! :)

        Geek-9pm


          Mastermind
        • Geek After Dark
        • Thanked: 1026
          • Gekk9pm bnlog
        • Certifications: List
        • Computer: Specs
        • Experience: Expert
        • OS: Windows 10
        Re: Algorithms Am I on the right track?
        « Reply #6 on: September 02, 2011, 09:41:58 PM »
        Glad to help. Your problem can benefit from a CASE or SWITCH structure. Or you could create your own special function or procedure. You may like to read this:
        http://en.wikipedia.org/wiki/Switch_statement
        In some applications, maybe a network database,  reducing the block to  minimal code may be a critical issue to improve response time.
        Quote
        Optimized switch
        To optimize a switch statement, the programmer must use a very compact range of possible values to test.[1] Sometimes it is necessary to convert the switch to a more suitable range using an inexpensive transformation. See algorithmic efficiency for an explanation of how the programmer can "assist" the compiler to make an efficient choice. See also the section 'Compiler generated branch tables' in branch table article for why optimization is not always performed as expected and how to solve this.
        This can be an interlinings  area of study if you need to work with SQL or similar things.

        Salmon Trout

        • Guest
        Re: Algorithms Am I on the right track?
        « Reply #7 on: September 02, 2011, 11:58:18 PM »
        Geek, I don't think you realise what is going on here. I tried to give a hint, but you didn't take it up.

        I'll try to make it simple.

        1. The OP, webdev57, is not seeking help to write some code. He or she is seeking help with a school or college assignment.

        2. The assignment is to read a program, written in a pseudocode and answer questions about how it would work.

        3. How it would work, that is, if it were a real programming language.

        4. The pseudocode contains structures and logic found in programming languages.

        5. That is what I meant about teaching language but it evidently passed you by.

        6. The above is obvious from the format of the original post, in my opinion.



        Geek-9pm


          Mastermind
        • Geek After Dark
        • Thanked: 1026
          • Gekk9pm bnlog
        • Certifications: List
        • Computer: Specs
        • Experience: Expert
        • OS: Windows 10
        Re: Algorithms Am I on the right track?
        « Reply #8 on: September 03, 2011, 12:07:42 AM »
        Thank you Salmon Trout,
        Did not mean to do his homework for him.  :-[

        Salmon Trout

        • Guest
        Re: Algorithms Am I on the right track?
        « Reply #9 on: September 03, 2011, 12:11:31 AM »
        Thank you Salmon Trout,
        Did not mean to do his homework for him.  :-[

        I think you were OK, he asked enough questions to show that he was thinking the project through, and he seemed to want confirmation that he was on the right track, as his title says.

        I just thought you were wasting your time re writing the code though. Helpful though that seems to have been.


        Geek-9pm


          Mastermind
        • Geek After Dark
        • Thanked: 1026
          • Gekk9pm bnlog
        • Certifications: List
        • Computer: Specs
        • Experience: Expert
        • OS: Windows 10
        Re: Algorithms Am I on the right track?
        « Reply #10 on: September 03, 2011, 01:02:21 AM »
        ...

        I just thought you were wasting your time re writing the code though. Helpful though that seems to have been.
        His code was hard to read. It was redundant and would never do inside of a loop. I just had to re write it.

        Salmon Trout

        • Guest
        Re: Algorithms Am I on the right track?
        « Reply #11 on: September 03, 2011, 02:18:37 AM »
        His code was hard to read. It was redundant and would never do inside of a loop. I just had to re write it.

        It wasn't "his" code; I am pretty sure of that, and I don't see why it shouldn't work within a loop. Why do you say that? Since it is in a yet-to-be-determined language, we cannot make assumptions like that.
        The code listed asks the user to input a number and then using conditional logic, do various things depending on the value of that number.

        The code is written in a kind of generic "does-not-actually-exist" programming language. The object of the exercise seems to be to evaluate the student's ability to read source code and deduce what it does, independent of any particular language implementation.






        Geek-9pm


          Mastermind
        • Geek After Dark
        • Thanked: 1026
          • Gekk9pm bnlog
        • Certifications: List
        • Computer: Specs
        • Experience: Expert
        • OS: Windows 10
        Re: Algorithms Am I on the right track?
        « Reply #12 on: September 03, 2011, 06:01:14 AM »
        Salmon Trout. You are very perceptive. I  made the mistake of thinking he wrote it.
        I did not say it would not work. I was guessing that a compiler would not optimize it. 

        beckymaccery



          Rookie
        • haloooo:)
          • shaw capital management
        • Experience: Beginner
        • OS: Windows XP
        Re: Algorithms Am I on the right track?
        « Reply #13 on: September 15, 2011, 08:26:38 PM »
        i think this language must be visual basic right? :)..oh how really miss studying its been 3 years since i last practice my programming skills fortunately i joined such forum thanks guys for some refresment :-[