49 Tutorial Series 4 Prime
49 Tutorial Series 4 Prime
This is the fourth issue of a series of tutorials for the Visit our dedicated HP Prime portal:
http://www.hp-prime.com
HP Prime, written by Edward Shore. This session will
cover CHOOSE and CASE. If you have programmed
with the HP 39g, 39g or 39gII, you will recognize the
programming as the HP Prime programming language
(HPPP) is similar. We are using the latest firmware in
this series, available on the website.
How to start?
1. Press Shift + 1 (Program).
3. Enter the name of the program. Pressing the ALPHA key twice will turn on
UPPERCASE ΑLPHA-LOCK. Pressing ALPHA, Shift, ALPHA will turn on lowercase
alpha-lock. To exit any lock, press the ALPHA key one more time. When you’re happy
with the name, press Enter.
EXPORT program_name(arguments)
BEGIN
commands and comments go here
END;
Each line containing a command generally must end with a semicolon (;). A
semicolon can by type by pressing ALPHA then the Plus key ( + ).
Comments can be typed. They are designated by two forward slashes. The slashes
are typed by pressing the Divide key ( ÷ ). Anything in the line following the two
slashes is ignored in running the program.
Choosing item 1 assigns the value of 1 to var, choosing item 2 assigns the value of 2
to var. IF INPUT(...) THEN
commands if values are entered
Access: Cmds, 6. I/O, 1. CHOOSE ELSE
commands if Cancel is pressed
END;
CASE: Allows for different test cases for one variable. Also includes a default scenario
(optional).
Default values can be assigned to values as an
CASE optional fifth argument for INPUT.
IF test 1 THEN do if true END;
IF test 2 THEN do if true END; INPUT(var, "Title", "Prompt",
... "Help", default value)
DEFAULT commands END;
Access: Cmds, 2. Branch, 3. CASE The type of variable maybe set to other than real
numbers. Just remember to store such type
Let's look at two programs to demonstrate both CHOOSE and CASE. before the INPUT command. For example, if you
want var to be a string, store an empty string:
var:=" ";
LOCAL L0:={9.80665,32.174},
L1:={1.225,.0765},
L2:={.47,1.05,1.15,.04},C,K,M,A,T;
CHOOSE(C,"Units","SI","English");
CHOOSE(K,"Type of Object","Sphere","Cube",
"Cylinder","Tear-Shaped");
INPUT({M,A},"Object",
{"M=","A="},{"Mass","Surface Area"});
T:=√((2*M*L0(C))/(L1(C)*A*L2(K)));
MSGBOX("Terminal Velocity="+T);
RETURN T;
END;
Examples:
EXPORT AREAC()
BEGIN
LOCAL C,R,S,θ,A;
CHOOSE(C,"Areas","1. Circle","2. Ring","3. Sector");
CASE
IF C==1 THEN A:=π*R^2; END;
IF C==2 THEN
INPUT(S,"Small Radius","r=");
A:=π*(R^2-S^2);
END;
IF C==3
INPUT(θ, "Angle", "θ=");
\\ Assume you are in the correct angle mode
IF HAngle==1 THEN
\\ Test Angle Mode
θ:=θ*π/180;
END;
A:=θ*R^2/2;
END;
END;
MSGBOX("Area is "+A);
RETURN A;
END;
Examples:
Circle: 19.6349540849
Ring: 12.5663706144
Sector: 2.45436926062