Presentation on theme: "P1PMF Split1 QBASIC. P1PMF Split2QBasic Command Prompt Will launch the emulator DOS operating system? Press Alt + Enter to display the widescreen."— Presentation transcript:
P1PMF Split1 QBASIC
P1PMF Split2QBasic Command Prompt Will launch the emulator DOS operating system? Press Alt + Enter to display the widescreen
P1PMF Split3QBasic C:\qbasic>qbasic Come to the directory where the QBasic (in this example c: \ qbasic) and start a program qbasic Interface QBasic interpreter. Press the ESC key to close the splash screen
P1PMF Split5 Commands QBASIC's The command tells QBasic interpreter to do something. I can write small or big letters The new line is crossed by pressing the ENTER
P1PMF Split6 Name that may contain value Numerical variables: Basically variables named with just a letter or a word Example X=25, we assigned the value of 25 to the variable X, so tha Qbasic will now know that the variable named x keeps the number 25 PRINT X (run this prog.) The screen will show 25 QBasicVariable
P1PMF Split7 QBasicStrings Strings There are certain types of data (or information) called "strings". Strings containing a string of characters (letters, numbers and symbols) bounded by double quotes. For example, "Hello" is a string. The following list are also strings: " " "Ovojestring" "abc123" "1 + 1 = 2"
Example: b$= “Hello Everyone” PRINT b$ On the screen you will see Hello Everyone P1PMF Split8
P1PMF Split9 QBasicTerms terms The term is something that an interpreter is calculated. For example: (gives 2) (gives 53) 3 * 34 (gives 102) 80 / 4 (gives 20) (100 * 3) + 56 (gives 356)
P1PMF Split10 QBasicPRINT PRINT instruction says QBasic interpreter to print something on the screen. PRINT Press any key to continue
P1PMF Split11 QBasic The First Program PRINT “Hello Everyone" Enter this command and press ENTER Hello Everyone Press any key to continue On the output screen program prints Hello everyone Since the program is carried out, then the bottom of the screen says the message the interpreter waits until any button is pressed to return to the program code
P1PMF Split12 QBasicPRINT PRINT “Hello" PRINT “Everyone" Hello Everyone To print all in the same line, place a semicolon after the PRINT "Hello" PRINT “Hello"; PRINT “Everyone" HelloEveryone You can use multiple print statements in your program. Also, if you put a comma instead of a semicolon, the program will insert spaces between two words. PRINT “Hello", PRINT “Everyone" Hello Everyone
QBasicPRINT The PRINT command can print more than one string on the line, to apply this [ put the ; sign between the variables] Example: Having two variables -name$,which contains name Rob, and age, which contains the number 34,then,to print name and age,you type [ PRINT “name - ” ; name$ ; “Age-” ;age ] On the screen :when program run you will see Name-Rob.Age-34 OR: You can type the program as follows PRINT “Name-” ; name$ PRINT “Age-”;age results : Name-Rob Age-34 P1PMF Split13
P1PMF Split14 File Edit View ┌────────────────┐ │ New │ │ Open... │ │ Save │ │ Save As... │ ├────────────────┤ │ Print... │ ├────────────────┤ │ Exit │ └────────────────┘ QBasic New Program From the File menu choose New to create a new program ┌────────────────────────────────────────────┐ │ │ Loaded file is not saved. Save it now? │ │ ├────────────────────────────────────────────┤ │ └────────────────────────────────────────────┘ Qbasic gives a warning that the program is not saved, choose No to turn up a new program.. Recording program: File - Save * use the tab key to move from one frame to another * select Floppy A * type the name of the program * scroll to Save and press ENTER
P1PMF Split15 Qbasic Variables The variable: is data that is stored in computer memory (RAM). Location variables in RAM is called "address." The following program prints the variable X on the screen: PRINT X 0 Variable X is assigned a free address , and there is 0
P1PMF Split16 QBasicVariable The following program sets the X at 15, and then prints the variable: X = 15 PRINT X 15 Variable X is assigned the value 15
P1PMF Split17 QBasicVariable Variables are accessed line of its name. Variable names can have a combination of letters and numbers. The following list represents the names of valid variables: Y num VALUE xYz abc123
P1PMF Split18 QBasicVariable You can also use multiple variables in the program: X = 82 Y = 101 Z = 79 PRINT X PRINT Y PRINT Z The memory addresses of variables does not have to be exactly the same
P1PMF Split19QBasic PRINT If you close your phrase with quotation marks, then it becomes a string and will not be calculated. For example: PRINT prints the calculated value of the expression.? Delete the current program and enter the following: PRINT " " To clear the output of the screen use the CLS command.
P1PMF Split20 QBasic The variables and expressions x = (10 * 7) PRINT x 570 Also variables can be used as expressions. speed = 50 time = 2 distance = velocity * time PRINT will be from 100 Also can be combined with variable numbers in expressions. X = 100 Y = X * 7 PRINT Y 700
P1PMF Split21 QBasic Variables and Strings If you put a symbol of US dollars ($) to the end of a variable, then the tagging that is a variable of type string. X$ = “Hello Everyone" PRINT X$ Hello Everyone String can be added to the end of the existing string variable. X$ = “Hello" X$ = X$ + “Everyone" PRINT X$ HelloEveryone You can also add a string variable to each other. a$ = "String1" b$ = "String2" c$ = "String3" d$ = a$ + b$ + c$ PRINT d$ String1String2String3
P1PMF Split23 Create the following program: DIM FirstName AS STRING DIM LastName AS STRING CLS INPUT “Enter First Name: “, FirstName INPUT “Enter Last Name: “, LastName PRINT ‘Prints a line of nothing PRINT “Nice To Meet You, “; FirstName ; “ “; LastName If the user entered School Freeware as the first and last name, the program’s output would be: Enter First Name: School Enter Last Name: Freeware Nice To Meet You, School Freeware QBasicINPUT
P1PMF Split24 DIM FirstName AS STRING DIM LastName AS STRING DIM Num1 AS INTEGER DIM Num2 AS INTEGER CLS INPUT “Enter First Name: “, FirstName INPUT “Enter Last Name: “, LastName PRINT ‘Prints a line of nothing PRINT “Nice To Meet You, “; FirstName ; “ “; LastName PRINT INPUT “Enter First Integer To Add: “, Num1 INPUT “Enter Second Integer To Add: “, Num2 PRINT PRINT Num1; “ + “; Num2; “ = “; Num1 + Num2 We can modify the program to allow the user to enter two numbers. The program will add the numbers together.
If the user entered School Freeware as the first and last name, 25 for the first number, and 10 for the second number, the program’s output would be: Enter First Name: School Enter Last Name: Freeware Nice To Meet You, School Freeware Enter First Integer To Add: 25 Enter Second Integer To Add: = 35 P1PMF Split25
QBasicGOTO GOTO means that the program will jump to a particular line We can use GOTO to jump not only back but also forward,to any line you want, the line must be labeled.You can have more than one label P1PMF Split26
QBasic IF….THEN……ELSE This command checks if an argument involving a variable is true,an argument may look like this: IF a=15 THEN …. If the argument is true (and a really equals to 15),the Qbasic executes the command you put after the IF……THEN. IF a=15 THEN PRINT “OK” If the argument is not true(if a is not equal to 15),Qbasic bypasses this line and goes to the next. P1PMF Split
In some cases,you can see the ELSE command,which tells Qbasic exactly what to do if the argument is not true IF a=15 THEN PRINT “OK” ELSE PRINT “It’s not 15” * This example means that if a equals to 15,the computer will show OK on the screen. But if a is not equal to 15,you will see It’s not 15 P1PMF Split28
QBasicIF….THEN……ELSE IF statements are used to check conditions in the program. The structure of the if statement is as follows: If Then Do something ElseIf Then Do something> Else Do something End If P1PMF Split29
QBasicIF….THEN……ELSE The Expression Signs (Relational Operators) For If Statements Are: < Less than <= Less than or equal to > Greater than >= Greater than or equal to = Equal to <> Not Equal to P1PMF Split30
When the condition is met, the code associated with condition will trigger. For example, in a new file type: CLS IF 5 > 2 THEN PRINT “5 Is Greater Than 2” END IF The output will be: 5 Is Greater Than 2 If the greater than changed to a less than, the computer will not output any information because the condition is not met: CLS IF 5 < 2 THEN PRINT “5 Is Less Than 2” END IF P1PMF Split31
CLS IF 5 > 10 THEN PRINT “5 Is Greater Than 10” ELSE PRINT “5 Is Not Greater Than 10” END IF Since 5 is not greater than 10, the output will be: 5 Is Not Greater Than 10 P1PMF Split32
P133 The next example will prompt the user to enter two numbers. The program will check for the greatest number and give a report on its findings. DIM Num1 AS INTEGER DIM Num2 AS INTEGER CLS INPUT "Enter First Number: ", Num1 INPUT "Enter Second Number: ", Num2 IF Num1 > Num2 THEN PRINT Num1; "Is Greater Than"; Num2 ELSEIF Num2 > Num1 THEN PRINT Num2; " Is Greater Than"; Num1 ELSE PRINT “The Numbers Are The Same” END IF The output is dependent on the user input.