Home > Visual Basic > Visual Basics

Visual Basics

February 3rd, 2010

1. Table 1 below shows the standard prices for items in a department store. Suppose prices will be reduced for the annual President’s Day Sale. The new price will be computed by reducing the old price by 10 percent, rounding up to the nearest dollar, and subtracting 1 cent. If the new price is greater than the old price, the old price is used as the sale price. Write a program to display in a list box the output shown in Table 2 below.

Table 1 President’s Day sale.

———————————————————————–

Item Original Price

———————————————————————–

GumShoes 39.00

SnugFoot Sandals 21.00

T-Shirts 7.75

Maine Handbag 33.00

Maple Syrup 6.75

Flaked Vest 24.00

Nightshirt 26.00

Table 2 Output

Item Sale Price

GumShoes 35.99

SnugFoot Sandals 18.99

T-Shirt 6.99

Maine Handbag 29.99

Maple Syrup 6.75

Flaked Vest 21.99

Nightshirt 23.99

2. Rewrite the program so input, processing, and output are each performed by calls to Sub procedures.

Private Sub btnCompute_Click(…) Handles btnCompute.Click

‘Convert feet and inches to centimeters

Dim str As String

Dim feet, inches, totalInches, centimeters As Double

str = “Give the length in feet and inches. “

feet = CDbl(InputBox(str & “Enter the number of feet.”))

inches = CDbl(InputBox(str & “Enter the number of inches. “))

totalInches = 12 * feet + inches

centimeters = 2.54 * totalInches

txtOutput.Text = “The length in centimeters is ” & centimeters

End Sub

3. Write a program to declare an array with the statement Dim state(49) As String and maintain a list of certain states. The list of states should always be in alphabetical order and occupy consecutive elements of the array. The buttons in the program should give the user the following options:

(a) Take the state specified by the user in a text box and insert it into its proper position in the array. If the state is already in the array, so report.

(b) Take the state specified by the user in a text box and delete it from the array. If the state is not in the array, so report.

(c) Display the states in the array.

4. The table below contains the statistics for a stock portfolio. (The current prices are given for January 17, 2008.)

Stock portfolio.

——————————————————————————-

Number Date Purchase Current

Stock of Shares Purchased Price/Share Price/Share

——————————————————————————-

Amgen 200 8/19/97 12.625 47.42

Delta Airlines 100 12/3/97 55.875 15.19

Novell 500 8/27/97 10.375 6.13

PPG 100 12/18/97 28.375 62.64

Timken 300 3/13/98 34.625 26.88

——————————————————————————-

(a) Compose a program to create the sequential file csvSTOCKS.TXT containing the information in the Stock portfolio table.

5. Write a program that contains a list box (with Sorted = False), a label, and two buttons captioned “Add an Item” and “Delete an Item”. When the Add an Item button is clicked, the program should request an item with an input dialog box and then insert the item above the currently highlighted item. When the Delete an Item button is clicked, the program should remove the highlighted item from the list. At all times, the label should display the number of items in the list.

6. A computer dealer offers two basic computers, the Deluxe ($1000) and the Super ($1500). The customer can order any of the following additional options: upgraded video card ($200), internal modem plus Wi-Fi ($30), or 1GB of added memory ($120). Write a program that computes the cost of the computer system selected.


Visual Basics

Categories: Visual Basic Tags: , , , , , ,
Comments are closed.
Bear