Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Understanding Loops: Showing the Variables a Program - Fall 2008 | IST 256, Lab Reports of Information Technology

Material Type: Lab; Class: Application Programming for Information Systems; Subject: Information Studies; University: Syracuse University; Term: Spring 2008;

Typology: Lab Reports

Pre 2010

Uploaded on 08/09/2009

koofers-user-cf2
koofers-user-cf2 ๐Ÿ‡บ๐Ÿ‡ธ

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
IST 256
Lab 6 โ€“ February 4, 2008
1. Understanding Loops โ€“ showing the variables of a program
For this problem, you are not to put any part of the program into Visual Studio. You are
to write your answers on this lab sheet. (This of this as a practice exam question.)
A. Consider the following program for a button:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim counter, sum As Integer
counter = 0
sum = 0
' add integers from 1 to 10
For counter = 1 To 10 Step 1
sum = sum + counter
Next counter
' show the number to the user
Label1.Text = CStr(sum)
End Sub
In the following boxes, write the values of the variables as this program is executed:
Variable
Val1
Val2
Val3
Val4
Val5
Val6
Val7
Val8
Val9
Val10
Val11
counter
sum
What number will be shown to the user? (write it here):
B. Consider the following program for a button:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim counter, sum, square As Integer
counter = 0
sum = 0
square = 0
' add the squares of integers from 1 to 6
For counter = 1 To 6 Step 1
square = counter * counter
sum = sum + square
Next counter
' show the number to the user
Label1.Text = CStr(sum)
End Sub
pf3

Partial preview of the text

Download Understanding Loops: Showing the Variables a Program - Fall 2008 | IST 256 and more Lab Reports Information Technology in PDF only on Docsity!

IST 256

Lab 6 โ€“ February 4, 2008

1. Understanding Loops โ€“ showing the variables of a program

For this problem, you are not to put any part of the program into Visual Studio. You are

to write your answers on this lab sheet. (This of this as a practice exam question.)

A. Consider the following program for a button:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim counter, sum As Integer counter = 0 sum = 0

' add integers from 1 to 10 For counter = 1 To 10 Step 1 sum = sum + counter Next counter

' show the number to the user Label1.Text = CStr(sum) End Sub

In the following boxes, write the values of the variables as this program is executed:

Variable Val1 Val2 Val3 Val4 Val5 Val6 Val7 Val8 Val9 Val10 Val

counter

sum

What number will be shown to the user? (write it here):

B. Consider the following program for a button:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim counter, sum, square As Integer counter = 0 sum = 0 square = 0

' add the squares of integers from 1 to 6 For counter = 1 To 6 Step 1 square = counter * counter sum = sum + square Next counter

' show the number to the user Label1.Text = CStr(sum) End Sub

In the following boxes, write the values of the variables as this program is executed:

Variable Val1 Val2 Val3 Val4 Val5 Val6 Val

counter

sum

square

What number will be shown to the user? (write it here):

Before you leave lab today, please show me this part of your lab sheet.

2. Compute Interest โ€“ extending the compute interest program

For this application, you should open Visual Studio and create a new project named

something like ComputeInterest. This new project should be in the same lab projects

folder as usual.

In the initial form , change the name and text properties of the form for the new

ComputeInterest project.

In class, an application was developed for a simpler version of the ComputeInterest

program. In this application, the user typed in numbers for the following:

Initial bank balance

Number of years to compute a new balance

Interest rate, given as a decimal number

There were two buttons, one called Compute Interest, and one for Close.

When the user clicked on the Compute Interest button, a new bank balance was

computed by computing the interest each year and adding it into the bank balance for that

year.

Here is the program:

Public Class Form

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim counter, numyears As Integer Dim balance, interestrate, interestamount As Single

' Get the user balance, number of years, and interest rate balance = CSng(TextBox1.Text) numyears = CInt(TextBox2.Text) interestrate = CSng(TextBox3.Text)

' compute the interest for each year and add to balance For counter = 1 To numyears Step 1 interestamount = balance * interestrate balance = balance + interestamount Next counter