Chapter Programming 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12.
Chapter 8 Programming 1. Before Programming The programming function helps to make complex, often-repeated calculations quick and easy. Commands and calculations are executed sequentially, just like the manual calculation multistatements. Multiple programs can be stored under file names for easy recall and editing. File Name File Name Program Program File Name Program Select the PRGM icon in the Main Menu and enter the PRGM Mode. When you do, a program list appears on the display.
Programming Chapter 8 2. Programming Examples Example 1 To calculate the surface area and volume of three regular octahedrons of the dimensions shown in the table below Store the calculation formula under the file name OCTA. Length of One Side (A) A Surface Area (S) Volume (V) 7 cm cm2 cm3 10 cm cm2 cm3 15 cm cm2 cm3 The following are the formulas used for calculating surface area S and volume V of a regular octahedron for which the length of one side is known.
Chapter 8 Programming • Pressing 4 (SYBL) displays a menu of symbols that can be input. 4(SYBL) 1 2 3 4 • You can delete a character while inputting a file name by moving the cursor to the character you want to delete and pressing D. 3. Press w to register the file name and change to the program input screen. File name w • Registering a file name uses 17 bytes of memory. • The file name input screen remains on the display if you press w without inputting a file name.
Programming Chapter 8 uTo change modes in a program P.2 • Pressing 3 (MENU) while the program input screen is on the display causes a mode change menu to appear. You can use this menu to input mode changes into your programs. For details on each of these modes, see “Using the Main Menu”, as well as the sections of this manual that describe what you can do in each mode. 3(MENU) 1 P.6 2 3 4 • Pressing ! Z displays a menu of commands that can be used to change set up screen settings inside a program.
Chapter 8 Programming Surface Area S ... c*!9d*aAxw Volume V ............ !9c/d*aAMdw If you simply input the manual calculations shown above however, the calculator would execute them from beginning to end, without stopping. The following commands make it possible to interrupt a calculation for input of values and display of intermediate results. ? : This command pauses program execution and displays a question mark as a prompt for input of a value to assign to a variable.
Programming 1 Chapter 8 2 3 4 1 (EXE) or w hw (Value of A) Intermediate result produced by ^ w w baw w • Pressing w while the program’s final result is on the display re-executes the program. P.149 • You can also run a program while in the RUN Mode by inputting: Prog ”” w. • An error (Go ERROR) occurs if the program specified by Prog ”” cannot be found.
Chapter 8 Programming 3. Debugging a Program A problem in a program that keeps the program from running correctly is called a “bug,” and the process of eliminating such problems is called “debugging.” Either of the following symptoms indicates that your program contains bugs and that debugging is required.
Programming Chapter 8 5. Secret Function When inputting a program, you can protect it with a password that limits access to the program contents to those who know the password. Password protected programs can be executed by anyone without inputting the password. uTo register a password Example To create a program file under the name AREA and protect it with the password CASIO 1. While the program list is on the display, press 3 (NEW) and input the file name of the new program file.
Chapter 8 Programming uTo recall a program Example To recall the file named AREA which is protected by the password CASIO 1. In the program list, use f and c to move the highlighting to the name of the program you want to recall. 2. Press 2 (EDIT). 2(EDIT) 3. Input the password and press w to recall the program. • The message “Mismatch” appears if you input the wrong password. 6. Searching for a File You can search for a specific file name using any of the three following methods.
Programming Chapter 8 uTo find a file using file name search Example To use file name search to recall the program named OCTA 1. While the program list is on the display, press 3 (NEW) and input the name of the file you want to find. 3(NEW) OCTA 2. Press w to recall the program. • If there is no program whose file name matches the one you input, a new file is created using the input name.
Chapter 8 Programming 2. Recall the program. P.20 • The procedures you use for editing program contents are identical to those used for editing manual calculations. For details, see “Making Corrections”. • The following function keys are also useful when editing program contents. 1 (TOP) ........ Moves the cursor to the top of the program 2 (BTM) .......
Programming Chapter 8 As you can see, you can produce the TETRA program by making the following changes in the OCTA program. • Deleting c * (underlined using a wavy line above) • Changing d to b c (underlined using a solid line above) Let’s edit the program. 2(EDIT) eeeeDD cd![bc D Q Let’s try running the program. Length of One Side (A) Surface Area (S) Volume (V) 7 cm 84.87048957 cm2 40.42293766 cm3 10 cm 173.2050808 cm2 117.8511302 cm3 15 cm 2 397.7475644 cm3 389.
Chapter 8 Programming w w baw w 8. Deleting a Program There are two different ways to delete a file name and its program. • Specific program delete • All program delete uTo delete a specific program 1. While the program list is on the display, use f and c to move the highlighting to the name of the program you want to delete. 2. Press [ 1 (DEL). [1(DEL) 1 2 3 4 3. Press 1 (YES) to delete the selected program or 4 (NO) to abort the operation without deleting anything. uTo delete all programs 1.
Programming Chapter 8 [2(DEL•A) 1 2 3 4 2. Press 1 (YES) to delete all the programs in the list or 4 (NO) to abort the operation without deleting anything. P.37 • You can also delete all programs using the MEM Mode. See “Clearing Memory Contents” for details. 9. Useful Program Commands In addition to calculation commands, this calculator also includes a variety of relational and jump commands that can be used to create programs that make repeat calculations quick and easy.
Chapter 8 Programming Program Command Menu (COM) While the program menu is on the display, press 1 (COM) to display the program command menu. 1(COM) 1 (If) ............. If command 1 2 3 4 [ 1 2 3 4 [ 1 2 3 4 [ 2 (Then) ....... Then command 3 (Else) ........ Else command 4 (I•End) ...... IfEnd command [ 1 (For) .......... For command 2 (To) ........... To command 3 (Step) ....... Step command 4 (Next) ........ Next command [ 1 (Whle) ....... While command 2 (WEnd) .....
Programming Chapter 8 Jump Command Menu (JUMP) While the program menu is on the display, press 3 (JUMP) to display the jump command menu. 3(JUMP) 1 (Lbl) .......... Lbl command 1 2 3 4 [ 1 2 3 4 [ 2 (Goto) ....... Goto command 3 (⇒) ........... ⇒ (jump) command [ 1 (Isz) .......... Isz command 2 (Dsz) ......... Dsz command Press [ to return to the previous menu. Clear Command Menu (CLR) While the program menu is on the display, press [ 3 (CLR) to display the clear command menu.
Chapter 8 Programming 3(TABL) 1 (Tabl) ........ DispTable command 1 2 3 4 2 (G•Con) .... DrawTG-Con command 3 (G•Plt) ....... DrawTG-Plt command Conditional Jump Relational Operator Menu (REL) While the program menu is on the display, press [ [ 1 (REL) to display the conditional jump relational operator menu. [[1(REL) 1 (=) ............. Relational operator = 1 2 3 4 [ 1 2 3 4 [ 2 (G) ............. Relational operator G 3 (>) ............. Relational operator > 4 (<) .............
Programming Chapter 8 10. Command Reference k Command Index Break .................................................................................... 149 ClrGraph ............................................................................... 153 ClrList.................................................................................... 153 ClrText................................................................................... 153 DispTable .............................................................
Chapter 8 Programming [Square Brackets] ....... Square brackets are used to enclose items that are optional. Do not input the square brackets when inputting a command. Numeric Expressions . Numeric expressions (such as 10, 10 + 20, A) indicate constants, calculations, numeric constants, etc. Alpha Characters ....... Alpha characters indicate literal strings (such as AB). k Basic Operation Commands ? (Input Command) Function: Prompts for input of values for assignment to variables during program execution.
Programming Chapter 8 Description: 1. Operation of the carriage return is identical to that of the multi-statement command. 2. Using a carriage return in place of the multi-statement command makes the displayed program easier to read. k Program Commands (COM) If~Then Function: The Then-statement is executed only when the If-condition is true (nonzero). Syntax: If numeric expression _ : ^ Then _ : ^ Parameters: condition, numeric expression Description: 1.
Chapter 8 Programming If~Then~Else Function: The Then-statement is executed only when the If-condition is true (nonzero). The Else-statement is executed when the If-condition is false (0). Syntax: If numeric expression _ : ^ _ : ^ Then Else _ : ^ _ : ^ Parameters: condition, numeric expression Description: 1. The Then-statement is executed when the If-conditions is true (non-zero). 2.
Programming Chapter 8 For~To~Next Function: This command repeats everything between the For-statement and the Next-statement. The starting value is assigned to the control variable with the first execution, and the value of the control variable is incremented by one with each execution. Execution continues until the value of the control variable exceeds the ending value.
Chapter 8 Programming Description: 1. This command is basically identical to For~To~Next. The only difference is that you can specify the step. 2. Omitting the step value automatically sets the step to 1. 3. Making the starting value less than the ending value and specifying a positive step value causes the control variable to be incremented with each execution.
Programming Chapter 8 Description: 1. This command repeats the commands contained in the loop as long as its condition is true (non-zero). When the condition becomes false (0), execution proceeds from the statement following the WhileEnd-statement. 2. Since the condition comes after the While-statement, the condition is tested (checked) before the commands inside the loop are executed.
Chapter 8 Programming 3. A subroutine can be used in multiple locations in the same main routine, or it can be called up by any number of main routines. Main Routine A Subroutines D Prog ”D” Prog ”C” C E Prog ”E” Prog ”I” I J Prog ”J” Level 1 Level 2 Level 3 Level 4 4. Calling up a subroutine causes it to be executed from the beginning. After execution of the subroutine is complete, execution returns to the main routine, continuing from the statement following the Prog command. 5.
Programming Chapter 8 Example: For 2 → I To 10_ If I = 5_ Then ”STOP” : Stop_ IfEnd_ Next This program counts from 2 to 10. When the count reaches 5, however, it terminates execution and displays the message ”STOP.” k Jump Commands (JUMP) Dsz Function: This command is a count jump that decrements the value of a control variable by 1, and then jumps if the current value of the variable is zero.
Chapter 8 Programming 3. This command can be used in combination with conditional jumps and count jumps. 4. If there is no Lbl-statement whose value matches that specified by the Gotostatement, an error (Go ERROR) occurs. Example: ? → A : ? → B : Lbl 1 : ?→ X : A×X + B ^ Goto 1 This program calculates y = AX + B for as many values for each variable that you want to input. To quit execution of this program, press A.
Programming Chapter 8 Description: 1. The conditional jump compares the contents of two variables or the results of two expressions, and a decision is made whether or not to execute the jump based on the results of the comparison. 2. If the comparison returns a true result, execution continues with the statement following the ⇒ command. If the comparison returns a false result, execution jumps to the statements following the multi-statement command (:), display command (^), or carriage return (_).
Chapter 8 Programming Description: This command draws a statistical graph in accordance with conditions defined within the program. DrawGraph Function: This command draws a graph. Syntax: DrawGraph_ Description: This command draws a graph in accordance with the drawing conditions defined within the program. DispTable Function: These commands display numeric tables.
Programming Chapter 8 Send ( Function: This command sends data to an external device. Syntax: Send () (…ex. Send (List 1)) Description: 1. This command sends data to an external device. 2. The following types of data can be sent by this command.
Chapter 8 Programming 11. Text Display You can include text in a program by simply enclosing it between double quotation marks. Such text appears on the display during program execution, which means you can add labels to input prompts and results. Program Display ?→X ? ”X =” ? → X X=? • If the text is followed by a calculation formula, be sure to insert a display command (^) or multi-statement command (:) between the text and calculation.
Programming Chapter 8 Executing this program produces the result shown here. k Using Table & Graph Functions in a Program P.74 Table & Graph functions in a program can generate numeric tables and perform graphing operations. The following shows various types of syntax you need to use when programming with Table & Graph functions.
Chapter 8 Programming Executing this program produces the results shown here. Numeric Table Graph w k Using List Sort Functions in a Program P.82 These functions let you sort the data in lists into ascending or descending order. • Ascending order 1 SortA (2 List 1, List 2, List 3) Lists to be sorted (up to six can be specified) 1 321Q 2 K11 • Descending order SortD (List 1, List 2, List 3) Lists to be sorted (up to six can be specified) k Using Statistical Calculations and Graphs in a Program P.
Programming Chapter 8 The graph conditions that are required depends on the graph type. See “Changing Graph Parameters”. • The following is a typical graph condition specification for a scatter diagram or xy line graph. S-Gph1 DrawOn, Scatter, List1, List2, 1, Square_ In the case of an xy line graph, replace “Scatter” in the above specification with “xyLine”. • The following is a typical graph condition specification for a pie chart.
Chapter 8 Programming Example Program 1 !Z[[[1Q ClrGraph_ 1 S-WindAuto_ 2 K11 {1, 2, 3} → 2 List 1_ 3 1Q {1, 2, 3} → 3 List 2_ 4 3121Q 4 S-Gph1 5 DrawOn, 5 3111Q 6 Scatter, 6 312[1Q List1, List2, 1, 7 Square_ 8 DrawStat 7 3141Q 8 !W[41Q Executing this program produces the scatter diagram shown here.
Programming Chapter 8 • Regression statistical calculation 1 LinearReg List 1, List 2, List 3 Calculation type* 1 Frequency data (Frequency) y-axis data (YList) x-axis data (XList) 31[1[1Q * Any one of the following can be specified as the calculation type. LinearReg ....... linear regression Med-MedLine .. Med-Med calculation QuadReg ........ quadratic regression LogReg ........... logarithmic regression ExpReg ........... exponential regression PowerReg .......
Chapter 8 Programming 162