Coffeehouse Thread

26 posts

Interview questions

Back to Forum: Coffeehouse
  • User profile image
    prog_dotnet

    Normally, statements are executed one after another in the order in which they are written. This is called sequential execution. However, various VB.NET statements enable the programmer to specify that the next statement to be executed might not be the next one in sequence. 
    A transfer of control occurs when an executed statement does not directly
    follow the previously executed statement in the written program.
    During the 1960s, it became clear that the indiscriminate use of transfers of control was
    causing difficulty for software development groups. The problem was the GoTo statement, which allows the programmer to specify a transfer of control to one of a wide range of possible destinations in a program.
    The excessive use of GoTo statements caused programs to become quite unstructured and hard to follow. Since that point in time, the notion of structured
    programming became almost synonymous with “GoTo elimination.”
    The research of Bohm and Jacopini demonstrated that all programs containing GoTo statements could be written without them. Programmers’ challenge during the era was to shift their styles to “GoTo-less programming.” It was not until the 1970s that programmers started taking structured programming seriously.
    The results have been impressive, as software development groups have reported reduced development times, more frequent ontime
    delivery of systems and more frequent within-budget completion of software projects.
    The key to these successes is that structured programs are clearer, easier to debug and modify and more likely to be bug-free in the first place.

    Bohm and Jacopini’s work demonstrated that all programs could be written in terms of only three control structures:
    Namely, the sequence structure, the selection structure and the repetition structure. The sequence structure is built into Visual Basic.
    ---------------------------------

    Visual Basic provides three types of selection structures.

     The If/Then selection structure performs (selects) an action (orsequence of actions) if a condition is true or skips the action (or sequence of actions) if thecondition is false.
    The If/Then/Else selection structure performs an action (or sequence of actions) if a condition is true and performs a different action (or sequence of actions) if the condition is false.
    The Select Case structure, performs one of many actions (or sequences of actions), depending on the
    value of an expression.

    The If/Then structure is called a single-selection structure because it selects or ignores a single action (or a sequence of actions).
    The If/Then/Else structure is called a double-selection structure because it selects between two different actions (or sequences of actions).
    The Select Case structure is called a multiple-selection structure because it selects among many different actions or sequences of actions.

    Visual Basic provides seven types of repetition structures; —While, Do While/Loop, Do/Loop While, Do Until/Loop, Do/Loop Until, For/Next and For Each/Next.

    The words If, Then, Else, End, Select, Case, While, Do, Until, Loop,For, Next and Each are all Visual Basic keywords
     So to conclude;
    Visual Basic has 11 control structures;
    sequence, three types of selection and seven
    types of repetition.
    Each program is formed by combining as many of each type of control structure as is necessary.

  • User profile image
    jj5

    prog_dotnet wrote:
    So to conclude;
    Visual Basic has 11 control structures;
    sequence, three types of selection and seven
    types of repetition.
    Each program is formed by combining as many of each type of control structure as is necessary.

    For someone so keen to copy a page from Chapter One of "The Idiot's Guide to Learning Visual Basic for Dummies" I'm surprised to notice your over-zealous use of the semi-colon punctuation mark.

    Perhaps we are meant to infer some relevance of your comments to this thread, based on the fact that the only control structure in the logic puzzle posted above is a jump?

    Or did you really think that your comments were useful information, even though this is the year 2004 and this is a forum for programmers? Do you suppose we hadn't noticed? Perhaps in your next installment you can wax historical about object-oriented programming, recursive control structures, and functional paradigms.

    How is it do you suppose that your control structures are implemented for your CPU by your compiler? Do you not suppose that the entire point of the question requiring the use of GOTO was to force a programmer to think about how a program might be implemented with serious limiting constraints on their ability to express their program?

    In this case our 'virtual machine' has one bit of read-only state (i.e. non-program memory), which is either zero or one depending on if a parachute is on the track or not which is presumably read via some IO device. The only branching constructs are JMP (jump, AKA goto) and JZ (jump if zero), there were no specified constraints on the size of our program, although with such a constrained programming language any real-world counter part would likely (not exist anymore Tongue Out) have a pretty hard limit on the size of the program itself (and probably be implemented directly in hardware, perhaps by hooking up the base, collector and emitter on a few transistors (with little black caps) to a handful of other primitive components).

    I was really hoping someone would catch me on an off-by-one error, or take a shot at me for making a spelling mistake or flawed assertion (I spotted at least one already). I'm miffed at hearing about how Visual Basic has support for 11 control structures. I'm about as interested as I would be if you told me there were 26 characters in the English alphabet.

    John.

  • User profile image
    prog_dotnet

    “Wanted: Young, skinny, wirey fellows not over 18. Must be expert riders willing to risk death daily. Orphans preferred. Wages $25 per week.”
    —Pony Express advertisement, 1860

    “We realize the skills, intellect and personality we seek are rare, and our compensation plan reflects that. In return, we expect TOTAL AND ABSOLUTE COMMITMENT to project success—overcoming all obstacles to create applications on time and within budget.”
    —Software developer advertisement, 1995

    The stereotypical programmer is a shy young man who works in a darkened room, intensely concentrating on magical incantations that coax the computer to do his bidding. He can concentrate 12-16 hours at a time, often working through the night to realize his artistic vision. He subsists on pizza and Twinkies. When interrupted, the programming creature responds violently, hurling strings of cryptic acronyms at his interrupter—“TCP/IP, RPC, RCS, SCSI, ISA, ACM, and IEEE!” The programmer breaks his intense concentration only to attend Star Trek conventions and watch Monty Python reruns. He is sometimes regarded as an indispensable genius, sometimes as an eccentric artist. Vital information is stored in his head and his head alone.
    ------------------------

    I dont know what your beef is, but there are a lot of people that are not that knowlegble as you apparently are.
     

    “A prudent question is one-half wisdom.”
    —Francis Bacon

  • User profile image
    jj5

    I've been goth-served!

    prog_dotnet wrote:
    The stereotypical programmer is a shy young man who works in a darkened room, intensely concentrating on magical incantations that coax the computer to do his bidding.


    Not shy behind a keyboard. Wink

    prog_dotnet wrote:
    He can concentrate 12-16 hours at a time, often working through the night to realize his artistic vision.


    16 hours. Minimum. 

    prog_dotnet wrote:
    He subsists on pizza and Twinkies.


    Cola and cigarettes.
     
    prog_dotnet wrote:
    When interrupted, the programming creature responds violently, hurling strings of cryptic acronyms at his interrupter—“TCP/IP, RPC, RCS, SCSI, ISA, ACM, and IEEE!”


    This is a somewhat dated sterotype. The programming creatures have evolved an apptitude for TWJ (tri-word-jargon) required to impress management. A more modern response would be:

    envisioneer turn-key experiences
    engineer cross-platform e-business
    target efficient e-markets
    optimize web-enabled action-items
    reinvent seamless relationships

    prog_dotnet wrote:
    The programmer breaks his intense concentration only to attend Star Trek conventions and watch Monty Python reruns.


    Once again, this is a dated sterotype, still embraced perhaps by those that for some twisted reason want to be perceived by others as programmers. For my money, South Park, Futurama, the Matrix and the LOTR are where it's been at for many years now.

    prog_dotnet wrote:
    He is sometimes regarded as an indispensable genius, sometimes as an eccentric artist.


    But more usually he is regarded as a *.

    prog_dotnet wrote:
    Vital information is stored in his head and his head alone.


    This is still true. Not for lack of trying mind you. Oh for an expressive programming language!

    prog_dotnet wrote:
    I dont know what your beef is, but there are a lot of people that are not that knowlegble as you apparently are.

     
    Flattery will get you everywhere. My 'beef' was being lectured about control stuctures in Visual Basic, aggrivated by the fact that you didn't even comment on why you felt this was necessary (when, in my view, it wasn't, or at least appeared to miss the point).

    prog_dotnet wrote:
    “A prudent question is one-half wisdom.”
    —Francis Bacon


    That's cute. What's the other half? What of a question that is not prudent? What of statements out of context?

    John.

  • User profile image
    Richard Acton

    spod wrote:

    ----
    ( i sometimes ask a puzzle / non-cs question..this is my favourite one, but is getting old now.. .)

    I have two bomb fuzes that burn for 60 minutes each...
                  60
    ---------------------------------- Angel

                  60
    ---------------------------------- (b)

    ( this is supposed to show the fuzes, with the time they would burn if you lit one end of them - it's easier on a whiteboard... )

    the rate of burning of the fuzes isn't constant - so Angel might burn 90% of its length in 10 minutes, and the other 10% in the remaining 50 minutes.

    The rate of burning isn't the same for each fuze.

    Use these fuzes to time me 45 minutes exactly.



    Discard 1 fuse. Cut the remaining fuse in half.

    With one half of the fuse, tie it's ends together to form a loop. Tie the other half anywhere on to the loop as so:
     _
    / \
    |  |
    \_/
     |
     |
     |

     ^
     |__ light here
     
    45 minutes will be up when all of the fuse is burnt (excluding the fuse we discarded)

    Edit: didn't see Jeremy W's answer. Thats cool that we found different solutions, but i should get a bonus point for the ascii art Wink

  • User profile image
    prog_dotnet

    1.The fuzes

    Light on of them up, wait until 44:55 and cut the fuze off.

    2. how would you count the number of gas stations in the world

    I wouldnt, its a dynamic dumber wich is regulated by demand and supply.

    3. how many piano tuners in the world.

    The same as above.

    4. What happens to the level of the water in the pond, and why?

    Nothing, its bellow the just noticeable difference

    5. There are 5 jars full of beans. Each bean weighs 10 grams, except for the poison beans (all in one jar), which weigh 9 grams. Weighing only once, and only using the scale how do you determine which jar has poisonous beans?

    You dont weight it, give one bean from each jar to 5 rats, and you will know wich one is poisonous.

    6. And the cars, Write a program that makes the cars collide.Both cars must execute the same program..

    You cant, every reaction has a counter reaction. The length between the cars will never decrease because they will conter react every move the other car does. 

  • User profile image
    Jeremy W

    Guess you don't like logic puzzles then, eh? Wink

  • User profile image
    jj5

    Richard Acton wrote:
    Discard 1 fuse. Cut the remaining fuse in half.

    With one half of the fuse, tie it's ends together to form a loop. Tie the other half anywhere on to the loop as so:
    <snip> 
    45 minutes will be up when all of the fuse is burnt (excluding the fuse we discarded)

    Edit: didn't see Jeremy W's answer. Thats cool that we found different solutions, but i should get a bonus point for the ascii art Wink


    Nope. Your solution is wrong. The problem is that the burn rate is not consistent. You could have created any amount of time, like this one which burns for 36 minutes:

            
                  /   \
    30 minutes => |   | <= 24 minutes
                   \_/
                    |
                    | <= 6 minutes
                    |

    This question is designed to teach you that you need to burn the candle at both ends if you're in IT.. Tongue Out

    John.

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.