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:
-
LANGUAGE:
Use "Visual Studio" to construct a "Visual Basic" (VB) solution
for each problem.
- The entire exam may be completed
using only the following VB objects:
Form, Label, TextBox, Button, Listbox
and the following data types;
integer, double, string, boolean
- You may use any VB statements presented in class or in assigned reading in the textbook
(except as otherwise noted).
-
Use an appropriate data type for each variable or function.
- Do not use module ("global") scope unless neccessary.
- Do not use ByRef unless it is absolutely neccessary.
- Before writing any VB code,
write a comment line
that says what you plan to do!
- HANDLERS:
Your "handlers" should not do any computation,
nor output,
nor input.
Instead, they should call subs and functions as appropriate.
-
INPUT/OUTPUT:
All input should use a Textbox;
numeric input strings should be converted, before using in computations.
Output should be done with a Listbox
(or label).
-
VARIABLES:
Always input a numerical value (from TextBox) into a variable,
before computing with it.
Give it a meaningful name;
choose appropriate type and scope.
-
COMMENTS:
Each "sub" should begin with a comment line,
explaining WHY it does whatever it does.
Put your name in comment lines at the top & bottom of your code.
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:
- "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
- "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).
- "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!
- "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!)
- "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/ .
|