Home > Casio > Personal Computer > Casio Z1 Gr User Manual

Casio Z1 Gr User Manual

    Download as PDF Print this page Share this page

    Have a look at the manual Casio Z1 Gr User Manual online for free. It’s possible to download the document as PDF or print. UserManuals.tech offer 338 Casio manuals and user’s guides for free. Share the user manual or guide on Facebook, Twitter or Google+.

    							  31 .. .. (displays line 30 to 60) 30 INPUT “H=”;H 40 V=PI+R^2*H 50 PRINT “V=”;V 60 END Here, a correction will be made in line 40. .. (Displays line 40 to 60, line 40 at the upper line of the display) .. (Enables program editing) 40 V=PI+R^2*H  .. .. .. .. .. .. .. .*. . . (Moves cursor and makes correction) 40 V=PI*R^2*H 50 PRINT “V=”;V 60 END  BRK ( BRK key exits EDIT mode) Ready P0  5.4 BASIC Program Execution 5.4.1 Program Execution Once a BASIC program is stored in memory, it can be executed using one of the two following procedures.  Using Shift (program area) in CAL mode  EXAMPLE: Shift P9 Executes the program in program area 9.  Entering RUN command in BASIC mode  EXAMPLE: Shift RUN . . Executes the program in the current program area.  Execute the program input in the previous section to determine the volume of a cylinder with a height ao 10 (radius is fixed at 15). Shift RUN . .  RUN H=?_ 10 . .  H=?10 V= 7068.583471 Ready P0 _ 5.4.2 Errors At times, the results produced by a program are not what is expected. Such irregular executions can be broadly divided under two major classifications.  
    						
    							  32 1. Executions that produce errors 2. Irregular execution that do not produce errors (mostly logic errors)  Execution that produce errors  Simple programming errors. This is the most common type of program error and is generally caused by mistakes in program syntax. Such errors result in the following message being displayed: SN error P0-10 This message indicates that a syntax error has been detected in line 10 of the program stored in program area 0. The indicated program line should be chacked and corrected to allow proper execution.  Program logic errors. This type of error is generally caused by such illegal operations as division by zero or LOG(0). Such errors result in the following message being displayed: MA error P0-10 As before, this message indicates that a mathematical error has been detected in line 10 of the program stored in program area 0. In this case, however, program lines related to the indicated program line as well as indicated program line itself should be examined and corrected. When an error message is displayed, the following operations can be used in BASIC mode to display the line in which the error was detected. Shift LIST 10 . .  Shift EDIT 10 . .  Shift LIST  .  . .  Shift EDIT  .  . .   The periods contained in LIST . and EDIT . instruct the computer to automatically display the last program line executed  Irregular execution that do not produce errors  Such errors are also caused by a flaw in the program, and must be corrected by executing the LIST or EDIT command to examine the program to detect the problem. The TRON command can also be used to help trace the execution of the program. Entering  T   R   O   N  . . puts trace mode ON. Now executing a BASIC program displays the program area and line number as execution is performed, and halts execution until . . is pressed. This allows confirmation of each program line, making it possible to quickly identify problem lines. Executing .T   R   O   F   F  . . cancels the trace mode. 5.5 Commands Though there are a variety of commands available in BASIC for use in programs, the nine fundamental commands listed below are the most widely used.  The following program reads data items located within the program itself, with a number of data items being read being determined by input from an operator. The operator may input any value, but note that values greater than 5 are handled as 5 (because there are only 5 data items in line 180). The program then displays the sum  
    						
    							  33 of the data read from line 180, followed by the square root and cube root of the sum. Program execution is terminated when the operator enters a zero.  10 S=0 20 RESTORE 30 INPUT N 40 IF N>5 THEN N=5 50 IF N=0 THEN GOTO 130 60 FOR I=1 TO N 70 READ X 80 S=S+X 90 NEXT I 100 GOSUB 140 110 PRINT S;Y;Z 120 GOTO 10 130 END 140 REM SQUARE/CUBE ROOT 150 Y=SQR S 160 Z=CUR S 170 RETURN 180 DATA 9,7,20,28,36 Clear current total assigned to S Specifies read operation should begin with 1st data item Input the number of data items to be read Input of values greater than 5 should be treated as 5 Jump to line 130 when input is zero This section is repeated the number of times specified by operator input in line 30   Branch to subroutine starting from line 140 Displays contents of variables S,Y,Z Jump to line 10 Program end Remarks Square root calculation Cube root calculation Return to statement following the GOSUB Data read by READ statement in line 70 5.5.1 REM The REM command (line 140) is actually short for the word “remarks”. The computer disregards anything following a REM command, and so it is used for such purposes as labels in order to make the program list itself easier to follow. Note that a single quotation mark ( Shift  ‘ ) can be used in place of the letters “REM”. 5.5.2 INPUT The INPUT command (line 30) is used to allow input from the computer’s keyboard during program execution. The data input are assigned to a variable immediately following the INPUT command. In the above example, input numeric data are assigned to the variable N. Note that a string variable must be used foe a string input.  EXAMPLE: 10 INPUT A$ (string input) 5.5.3 PRINT The PRINT command (line 110) is used to display data on the computer’s display. In this example, this command is used to display the results of the sum, square root and cube root calculations. 5.5.4 END The END command (line 130) brings execution of the program to an end, and can be included anywhere within the program. 5.5.5 IF – THEN The IF/THEN command (lines 40 and 50) is used for comparisons of certain conditions, basing the next operation upon whether the comparison turns out to be true of false. Line 40 checks whether or not value assigned to N is greater than 5,  
    						
    							  34 and assigns a value of 5 to N when the original value is greater. When a value of 5 or less is originally assigned to N, execution proceeds to the next line, with N retaining its original value. Line 50 checks whether or not value assigned to N is zero. In the case of zero, program execution jumps to nine 130, while execution proceeds to next line (line 60) when N is any other value besides zero.  Note: Line 50 can also be abbreviated as follows: 50 IF N=0 THEN 130 5.5.6 GOTO The GOTO command (lines 50 and 120) performs a jump to a specified line number or program area. The GOTO statement in line 120 is an unconditional jump, in that execution always returns to line 10 of the program whenever line 120 is executed. The GOTO statement in line 50, on the other hand, is a conditional jump, because the condition of the IF-THEN statement must be met before the jump to line 130 is made.  Note: Program area jumps are specified as GOTO #2 (to jump to program area 2). 5.5.7 FOR/NEXT The FOR/NEXT combination (line 60 and 90) forms a loop. All of the statements within the loop are repeated the number of times specified by a value following the word “TO” in the FOR statement. In the example being discussed here, the loop is repeated N number of times, with the value N being entered by the operator in line 30. 5.5.8 READ/DATA/RESTORE These statements (lines 50, 180, 20) are used when the amount of data to be handled is too large to require keyboard input with every execution. In this case, data are included within the program itself. The READ command assigns data to variables, the DATA statement holds the data to be read, and the RESTORE command is used to specify from which point the read operation is to be performed. In the program example here, the READ command reads the number of data items specified by the input variable N. Though the DATA statement holds only five data items, the RESTORE command in line 20 always returns the next read position to the first data item, the READ statement never runs out of data to read. 5.5.9 GOSUB/RETURN The GOSUB/RETURN commands (line 100 and 170) are used for branching to and from subroutines. Subroutines (lines 140 to 170) are actually mini programs within the main program, and usually represent routines that are performed repeatedly at different locations within a program. This means that GOSUB/RETURN makes it possible to write the repeated operation once, as a subroutine, instead of writing each time it is needed within the main program.  Execution of the RETURN statement at the end of a subroutine returns execution of the program back to the statement following the GOSUB command. In this sample program, execution returns to line 110 after the RETURN command in line 170 is executed.  
    						
    							  35 Note: GOSUB routines can also be used to branch to other program areas, as in GOSUB #3 (branches to program area 3). Note, however, that a return must be made back to original program area using the RETURN command before an END command is executed. 5.5.10 Labels You have the possibility to assign label names to program lines. This feature allows an easier understanding of the program structure, especially GOTO and GOSUB statements.  We will modify the program of chapter 5.5 using labels:  10 *Start:S=0 20 RESTORE 30 INPUT N 40 IF N>5 THEN N=5 50 IF N=0 THEN GOTO *Finish 60 FOR I=1 TO N 70 READ X 80 S=S+X 90 NEXT I 100 GOSUB *Root 110 PRINT S;Y;Z 120 GOTO *Start 130 *Finish:END 140 *Root:REM SQR/CUBE ROOT 150 Y=SQR S 160 Z=CUR S 170 RETURN 180 DATA 9,7,20,28,36 Clear current total assigned to S Specifies read op. should begin with 1st data item Input the number of data items to be read Input of values greater than 5 is treated as 5 Jump to program end when input is zero This section is repeated the number of times specified by operator input in line 30   Branch to subroutine labeled Root Displays contents of variables S,Y,Z Jump to program begin Program end Remarks Square root calculation Cube root calculation Return to statement following the GOSUB Data read by READ statement in line 70  Label names follow the same rules as variable names, except that they are not limited to 15 characters.  
    						
    							  36  5.6 Operators The following are the operators used for calculations, which involves variables.  Arithmetic operators Signs Addition Subtraction Multiplication Division Power Integer division Integer remainder of integer division +,- + - * / ^ ¥ MOD Relational operators Equal to Does not equal Less than Grater than Less than or equal to Grater than or equal to = , >< < > =>, , >= Logical operators Negation Logical product Logical sum Exclusive OR NOT AND OR XOR Operators String operator Concatenation +  Relational operators Relational operations can be performed only when the operators are both strings or both numeric values. With strings, character codes are compared one-by-one from the beginning of the strings. This is to say that the first position of string A is compared to the first position of string B, the second position of string A with the second position of string B, etc. The result of the comparison is based upon the character codes of the first difference between the strings detected, regardless of the length of the strings being compared.  EXAMPLES: STRING A STRING B RESULT ABC ABC A=B ABC ABCDE A3 -1 returned because 10>3 is true 20 PRINT 7>1 0 returned because 7
    						
    							  37  Logical Operators The operands of logical operations are truncated to integers and the operation is performed bit-by-bit to obtain the result.  X Y X AND Y X OR Y X XOR Y NOT X NOT Y 0 0 0 0 0 1 1 0 1 0 1 1 1 0 1 0 0 1 1 0 1 1 1 1 1 0 0 0  String Operators Strings may be concatenated using a + sign. The result of the operation (including intermediate results) may not exceed 255 characters.  EXAMPLE: A$=”AD”+”1990” The above example results in the string “AD1990” being assigned to variable A$.  Order of Operations Arithmetic, relational and logical operations are performed in the following order of precedence: 1. ( , ) 2. Scientific function 3. Power 4. Sign (+, -) 5. *, /, ¥, MOD 6. Addition and subtraction 7. Relational operators 8. NOT 9. AND 10. OR, XOR  Operations are performed from left to right when the order of precedence is identical. 5.7 Constants and Variables 5.7.1 Constants The following shows the constants included in the sample program of page 33:  PROGRAM 20 R=15 30 INPUT “H=”;H 40 V=PI*R^2*H 50 PRINT “V=”;V CONSTANTS 15 “H=” 2 “V=”  Of these, 15 and 2 are numeric constants, while “H=” and “V=” are string constants.  
    						
    							  38  5.7.2 Variables Numeric Variables The following shows the numeric variables included in the sample program on page 33:  PROGRAM 20 R=15 30 INPUT “H=”;H 40 V=PI*R^2*H NUMERIC VARIABLES R H V  Numeric variables are so named because their contents are handled as numbers. Numeric variable names can be up to 15 characters long, and are used within programs to store calculation results or constants in memory. In the sample program, the value 15 is stored in H, while V, which is the result of the calculation, holds the value that represents the volume of the cylinder. As can be seen, assignment to a variable is performed using the “=” symbol. This differs from an equal sign in that it declares that what is to the right should be assigned to what is to the left. Actually, a variable can be thought as a kind of box as illustrated below.   String Variables Another type of variable is known as a string variable, which is used to store character string data. String variable names are indicated by “$” following the name.  EXAMPLE: 10 A$=”AD” Assigns “AD” to string variable A$ 20 INPUT “YEAR=”;B$ Assigns keyboard input to variable B$ 30 C$=A$+B$ Assigns combination of A$ and B$ to C$ 40 PRINT C$ Displays contents of C$ 50 END  In the above program example, entering a year such as 1990 in line 20 results in a display of AD1990 in line 40. Note: Strings cannot be assigned to numeric variables such as A, and numeric values cannot be assigned to string variables such as A$.  Array Variables Both numeric variables and string variables can store only one data item per variable. Because of this, large amounts of data are better-handled using array variables (usually referred to as simply “arrays”). Before an array variable can be used within a program, a DIM statement must appear at the beginning of the program to “declare” to the computer that an array variable is to be employed.  V PI*R^2*H R 15  
    						
    							  39  EXAMPLE: Declare array variable A for storage of 9 numeric data items. 10 DIM A (8)  Note: a declared value of 8 makes possible to store 9 data items.    EXAMPLE: Recall value stored in element 4 of array A Y=A(4) Or X=4:Y=A(X)  The value that specifies an element in an array (4 above) is called a subscript.  Until now, the only arrays covered have been those formed by a single line of elements or “boxes”. These are known as “one-dimensional” arrays. Arrays may also contain more than one dimension with elements connected vertically and horizontally into two-dimensional and three-dimensional arrays.  EXAMPLE: DIM A (2,3)   The declaration in this example sets up an array of three lines and four columns, making it capable of storing 12 different values.  As with simple variables, arrays can also be declared to hold strings by using the “$” symbol following the array variable name.  A(0) A(1) A(2) A(3) A(4) A(5) A(6) A(7) A(8) A(0,0) A(0,1) A(0,2) A(0,3) A(1,0) A(1,1) A(1,2) A(1,3) A(2,0) A(2,1) A(2,2) A(2,3)  
    						
    							  40  5.7.3 Summary Variable types The three following types of variable are available for use with this unit. 1. Numeric variables (up to 12-digit mantissa) A, a, NUMBER, POINTS 2. String variables (up to 255 characters) A$, STRING$ 3. Array variables Numeric array A(10), XX(3,3,3)  String array A$(10), ARRAY$(2,2)  Variable names Variable names can consist of upper, lower case or numeric characters, but a numeric character cannot be used in the first position of the variable name (i.e. 1AE, 3BC$ are illegal). Reserved words (see page 75) cannot be used as the leading characters of a variable name (i.e. RUNON, LIST1$ are illegal). The maximum length of a variable name is 15-character.  Arrays 1. Arrays are declared by DIM statements. 2. Elements described by subscripts, which are integer greater than 0. Fractions are disregarded. 3. The number of dimensions is limited by stack capacity. 4. The maximum value of subscripts is limited by memory capacity.  
    						
    All Casio manuals Comments (0)