CS12 Midterm Exam
2006 Spring Semester
(Prof. B.A.Martin)

This exam is "open book":   You may use textbooks & notes, plus built-in VB help.
Upload your code as you compete each question. (No other internet use is permitted during exam).

INSTRUCTIONS:



Before writing your VB code, create a Graphical User Interface ("GUI" or VB "form") that accepts 3 labelled inputs ("low", "high", and "filename"") and displays output in a listBox. Also create a large label, centered at the top, that says "CS12-MIDTERM" and a smaller label at the lower right that displays your name. Add five buttons, as described below.

Textbox inputs (labelled "low" and "high") expect numeric input from the user's keyboard. These input strings must be converted to integer representation, before being used in computations.   The this input field (labelled "filename") expects a string that specifies a "path" to a file on whatever computer is being used.

In addition to the above, there will be several buttons, whose handlers you must write, to perform the actions described below.


Now, write VB code to do the following:

  1. "ONE TO TEN" button click
    The handler for this button should output a message (in the listBox) that gives the sum of all integers between one (1) and ten (10).

    However, your "handler" sub should not do any computation, nor output, nor input.   Instead, it should call subs and functions as appropriate.

    You may use (or copy) the following code for your handler:

    	sub oneToTen_click( ..., ...) handles oneToTen.click
    	  '***** Add up the integers, from one to ten.
    	  '** INPUT:	(none)
     
    	  '** PROCESING:	Compute the sum.
    	  dim tot as integer;
    	  tot=  sumfrom( 1, 10 )
     
    	  '** OUTPUT:	Show the result.
    	  call showit( "The sum is:  ", tot )
    		
    	end sub
    


  2. "FIRSTLINE" button click
    The handler for this button should read the first line of the file specified in the textbox labelled "f", and then display that line as output (in the listBox).


  3. "EVEN TEN" button click
    The handler for this button should output a message (in the listBox) that gives the sum of all EVEN integers between one (1) and ten (10).   To compute the sum of EVEN numbers in this range, you will need to write another function:
    	tot = sumeven( i, j )	
    Do NOT use a For ... Next loop in your sumeven() function.
    Write another function to test whether or not a number is even, and use it to decide whether or not to add each number to the sum.
    NOTE:  Even numbers leave no remainder when divided by two. You will probably want to use the mod operator to test for them. Do NOT use a "For ... Next" loop for this!


  4. "EVENRANGE" button click
    The handler for this button should input two values from the textboxes labelled "low" and "high". If the two numbers are out of sequence (i.e. if high is lower than low), reverse them and report the error. Then compute the sum of all EVEN integers between those two values, output a message (in the listBox) that gives the result.

    Remember:  handlers should not do any computation, nor output, nor input.   Instead, they should call subs and functions as appropriate. (Re-use the function you wrote for the last problem!)


  5. "SUMFILE" button click
    The handler for this button should read the all lines of the file specified in the textbox labelled "f", add up the EVEN values only (discarding the odd values) and then display that total as output (in the listBox).



When you are finished, print out your code (making sure your name appears in a comment line, both at the top and the bottom!)
Also upload your code as "midterm.vb" (and your "designer" code as "midterm.designer.vb" ), to your website account at http://suffolk.li/cs12/ .