Upload
christopher-olaya
View
159
Download
3
Tags:
Embed Size (px)
Citation preview
“Programming must look DEEPER to find out all possible
solutions to a problem.”
Sample program
clslet name$=“Piolo Pascual ”let school$=“Pililla National High School”print “Hello World!!!”print “I am “;name$print “I am enrolled at “;school$print “Thank your for Reading”end
Program Output
Hello World!!!I am Piolo PascualI am enrolled at Pililla National High SchoolThank you for reading.
Variables May be simply defined as a name
or label that may contain a value. When variables are used in a
computer program, Basic will store your variables in different locations on the hard drive. With this reason, the programmer must tell the computer what type of variable is going to be stored in a particular location on the hardisk.
Examples of Variables
Name=“kevin”X = y + z
Two Types of Variables1. String Variable - contain a word,
letter or a group of numbers that act as labesl or simple text within the program.(ex. Name$=kevin)
2. Numeric Variable – on the other hand are used to store positive or negative numbers. These numbers can be used for computation later on the program.
Symbol Classification Range Precision
$ String Variable A variable declared as a string can contain a maximum of 255
characters.
% Short Integer Variable types of this kind must only contain whole
numbers. Its range is from -32,768 to 32, 768.
& Long Integer Variables of this types has a range of -2,147,483,648 to
2,147,483,647
! Single Precision Variable of this type can contain up to a maximum of 7
decimal places. Its range is from -3.402823E+38 to
+ 3.402823E+38
# Double Precision Have a maximum of 14 decimal places from
1.79769313486321D+308
Rules in giving a Variable Name The first character of a variable
name must be a letter. Variable names cannot contain an
underscore(_), use the decimal point instead to separate word.
Variable names cannot start with the letter “FN” as Basic will assume that these names are functions.
Rules in giving a Variable Name Variable names may not be the same
as any of the words Basic uses to describe operations and functions. These names/words are sometimes called reserved words or keywords like PRINT, LET, DATA, READ, SQR.
TIPS IN GIVING VARIABLE NAME It would be best if the variable name
is descriptive and meaningful of the data it will stand for.
example= mathgrade, averagegrade,
This will enhance the clarity of the program for others who would like to read the program and it makes it easier to remember which variable is storing what value.
Sample Program:clsREM This program will compute for the area of the circlelet r=2.0let pi=3.1416print “Compute the area of a circle.”print “The Radius is equal to: “;rprint “Pi is equal to: “;piarea=pi*r*rprint “The area of the circle is equal to: “;areaprint “End of the Program”
Output Program:
Compute the area of a circle.The Radius is equal to: 1Pi is equal to: 3.1416The area of the circle is equal to: 3.1416End of the Program
Constant Are values that do not change
while the program is running. They are very effective when, for
example, you have a number that you want to use over and over again, you can simply use the constant name instead of typing the numbers every time you need it
Example
Dollar=45.50Pi=3.1416Name=“Piolo”School=“PilillaNHS”
Mathematical Operators Exponentiation- use the caret (^)
symbol to work with numbers and their exponents.
Multiplication-uses Asterisk (*) Division- uses forward slash(/) Integer Division- uses the back
slash (\) to get the whole number answer for a division operation.
Mathematical Operators Modulo Arithmetic – Uses MOD
operator to supply the remainder after any division operation.
Addition – Uses cross (+) Subtraction – Uses the dash (-)
Example
Exponentiation: 2^4 = 16 Multiplication: 2*4 = 8 Division: 4/2 = 2 Integer Division: 10\3 = 3 Modulo Arithmetic: 10 MOD 3 =
1 Addition: 5+41 = 46 Subtraction: 25-16 = 9
CLS Command
CLS – simply means Clear Screen. This command will remove all other contents of the execution window so that the program that your will activate/use/run has a clear screen to use.
Print CommandPRINT – The print command tells
the computer to make an output on the screen. The syntax or the way the command is used is:
Print [variable name] and/or[string constants]
Print CommandExample:print name$print “Hello”print “The average is :”;average
Let CommandThe Let statement or command is
what we usually call an assignment statement. It is used to define the content of variable and constants. It is used in much the same manner as when it is used in math when we write the variable being used in word problem.
Let CommandLike for example: Let x = y +
zThe syntax for LET is:LET [variable name] =
[variable value]
INPUT COMMAND
Used to ask for data from the user. The syntax for input command is: Input [string constant] or [string
message]; variable name
The variable name is important since this command is an assignment command that takes a variable’s value from the user’s input.
Sample program code:
clsrem This program will input and print out your
name and age.name$=“ ”age=0input “Please type in your name: “;name$input “Please enter your age: “;ageprint “Hello “;name$; “Welcome to Basic
Programming”print “I see that you are “;age; “years old.”end
Activity
Problem: Create a program that will input
three numbers and will compute for the average of the three numbers. Print out the Average number.
Hands on Activity