Course VVBasic B - Lesson 2

Overview

This lesson reinforces the topics from Lesson 1. Text variables and assignment of values to variable with LET are covered.

New VVBasic commands are TEXT and LET commands.

Introductory

As a refresher, ask, What VVBasic commands did we talk about last time?

To review, write some short programs with NUMBER and PRINT on the board, and ask students what the result will be. For instance,

VVBasic commands Output
PRINT "2 + 3 * 4 " = 2 + 3 * 4 2 + 3 * 4 = 14
PRINT "4.5 / 2 = " 4.5 / 2 4.5 / 2 = 2.25
NUMBER Allowance = 2.00
NUMBER Spent = 1.65
PRINT "I had " Allowance " dollars and spent " Spent
PRINT "Now I have " Allowance - Spent " left."
I had 2.00 dollars and spent 1.65
Now I have 0.35 left.
NUMBER Students = 45
NUMBER Teams = Students / 5
NUMBER Coaches = Teams * 2
PRINT "We need " Coaches " coaches."
We need 18 coaches.

Define expression: a combination of numbers, numeric variables, the math operations +, -, *, and /, with parentheses ( and ) to control order of evaluation. Students have seen expressions in NUMBER and PRINT commands. Review the order of operations (* and / before + and -).

Expressions are also used in the LET command. LET changes the value of a variable. TEXT is used to create variables which hold text strings. Some examples to write on the board and discuss with students:

VVBasic commandsOutput Points to make
NUMBER X = 10
PRINT X
LET X = X + 1
PRINT X
10
11
The value of a variable can change. That's the vary-able part.
NUMBER ElevatorCapacity = 2000
NUMBER KidWeight = 90
PRINT "The elevator can hold " ElevatorCapacity/KidWeight " kids."
The elevator can hold 22.2222222 kids. The computer does the math. The computer prints up to seven decimal digits.
NUMBER AngelsScore = 7
NUMBER RedSoxScore = 5
NUMBER Margin = AngelsScore - RedSoxScore
PRINT "The Angels won by " Margin
The Angels won by 2 A NUMBER command can have an expression. Substitute favorite teams as desired.
TEXT Name = "Mr. Jones"
PRINT "Hello " Name
Hello Mr. Jones Variables can hold either numbers or text strings, but not both.

Programming Lab

  1. Enter this program.
    CLEAR
    NUMBER Age = 11
    PRINT "I am " Age
    LET Age = Age + 1
    PRINT "Next year I'll be " Age
    
    Press the Run button. Make sure the output is correct. Click the Clear button when you're done.

  2. Enter this program (about scoops of ice cream) in the program window. Use your name instead of Abner.
    CLEAR
    TEXT Name = "Abner"
    NUMBER Scoops = 6
    PRINT Name " ate " Scoops " scoops of ice cream."
    
    Press the Run button. Make sure the output is correct. Don’t clear your program.

  3. Add more lines to the program so that it looks like this:
    CLEAR
    TEXT Name = "your name"
    NUMBER Scoops = 6
    NUMBER OuncesPerScoop = 2
    NUMBER Ounces
    NUMBER Pounds
    PRINT Name " ate " Scoops " scoops of ice cream."
    LET Ounces = Scoops * OuncesPerScoop
    PRINT "That makes " Ounces " ounces"
    LET Pounds = Ounces / 16
    PRINT "or " Pounds " pounds."
    
    Press the Run button. Change the value of OuncesPerScoop so that the amount of ice cream is just about 1.00 pounds. (You'll have to experiment with different values.)

  4. To convert degrees Fahrenheit to degrees Centigrade, subtract 32 and multiply by 5/9. Here's a program that does the conversion:
    CLEAR
    NUMBER DegreesF = 75
    NUMBER DegreesC = (DegreesF - 32) * 5/9
    PRINT "The temp is " DegreesC " Is it hot? " DegreesC > 26
    
    Run the program. Change DegreesF to 80. Is that hot? Change the PRINT command so that both DegreesF and DegreesC are printed out.
    VVBasic will print out True or False when it evaluates DegreesC > 26.

Concluding Questions and Answers

Ask students to tell you how to write a program that will print
  2 pounds of carrots cost 1.82 dollars.
when the program has three variables, NumPounds, PricePerPound, and VegetableName. The program will look something like this:
TEXT VegetableName = "carrots"
NUMBER NumPounds = 2
NUMBER PricePerPound = 0.91
PRINT NumPounds " pounds of " VegetableName " cost "
      NumPounds * PricePerPound " dollars."

Evaluation Activity

Ask the students to fill in the blanks in this program:
____ Name = "Mr. Smith"
______ Books = 35
NUMBER Students ______
PRINT "In " Name "'s class, there are " _______________ " extra books."