GeomCalc Documentation and Tutorial
GeomCalc Documentation and Tutorial
Introduction
The app GeomCalc is an example of a custom HP App for the HP Prime. For general information, please
visit this blog entry: http://edspi31415.blogspot.com/2018/02/hp-prime-intro-to-blank-custom-apps.html
Here I set the app’s angle to degrees mode. Note that I use the variable AAngle instead of the global
variable HAngle. The values for AAngle are slightly different than HAngle:
The last command is a message box containing the word Ready, to let the user know that the app is all
set to go.
START()
BEGIN
// Set app angle to degrees
AAngle:=2;
MSGBOX("Ready.");
END;
I want to leave some basic information about this app. I recommend that you use the PRINT command
rather than the TEXTOUT/WAIT/FREEZE. Alternatively, you can store a string in ANote.
I prefer using PRINT because I can print multiple lines with appropriate line breaks.
Info()
BEGIN
PRINT();
PRINT("GeomCalc");
PRINT("---------");
PRINT("EWS 2018-02-07");
PRINT("---------");
PRINT("Geometry areas and volumes");
END;
In this section, I set the variable I to a choice of one of ten options. The variable I is a global variable, so I
can use determine calculations. The INPUT command uses a dropdown box. The general format for a
single dropdown box is:
The message box at the end let’s the user know that the choice has been set, and can now proceed to
the calculation by pressing [Num].
Symb()
BEGIN
// Choose the calculation
// Global vars are used
INPUT({{I,{"Area: Circle",
"Area: Ellipse",
"Area: Trapezoid",
"Area: Circular Sector",
"Area: Regular Polygon",
"Volume: Sphere",
"Volume: Cylinder",
"Volume: Cone",
"Volume: Box",
"Volume: Ellipsoid"}}},
"Select Your Calculation");
MSGBOX("It's set!");
END;
The Num section – doing the calculation
When the [Num] is pressed, the user as asked to enter the arguments. The final result is displayed on
the terminal. Since global variables (including A-Z) is used, values are permanently stored until
changed. In this app, I store the area in the variable E and the volume in V.
There is no default selection, so I use ten IF-THEN structures than a CASE structure.
Num()
BEGIN
IF I==1 THEN
INPUT(R,"Area: Circle","Radius: ");
E:=π*R^2;
PRINT();
PRINT("Area: "+E);
END;
IF I==2 THEN
INPUT({A,B},"Area: Ellipse",
{"A: ","B: "});
E:=π*A*B;
PRINT();
PRINT("Area: "+E);
END;
IF I==3 THEN
INPUT({A,B,H},"Area: Trapezoid",
{"A: ","B: ","H: "});
E:=0.5*H*(A+B);
PRINT();
PRINT("Area: "+E);
END;
IF I==4 THEN
INPUT({θ,R},"Area: Circular
Sector",{"Angle (°): ",
"Radius: "});
E:=θ*π*R^2/360;
PRINT();
PRINT("Area: "+E);
END;
IF I==5 THEN
INPUT({N,S},"Area: Regular
Polygon",{"# sides: ",
"Length: "});
E:=N*S^2/(4*TAN(180/N));
PRINT();
PRINT("Area: "+E);
END;
IF I==6 THEN
INPUT(R,"Volume: Sphere","Radius: ");
V:=4/3*π*R^3;
PRINT();
PRINT("Volume: "+V);
END;
IF I==7 THEN
INPUT({R,H},"Volume: Cylinder",
{"Radius: ","Height: "});
V:=π*R^2*H;
PRINT();
PRINT("Volume: "+V);
END;
IF I==8 THEN
INPUT({R,H},"Volume: Cone",
{"Radius: ","Height: "});
V:=π*R^2*H/3;
PRINT();
PRINT("Volume: "+V);
END;
IF I==9 THEN
INPUT({A,B,C},"Volume: Box",
{"A: ","B: ","C: "});
V:=A*B*C;
PRINT();
PRINT("Volume: "+V);
END;
IF I==10 THEN
INPUT({A,B,C},"Volume: Ellipsoid",
{"A: ","B: ","C: "});
V:=4/3*π*A*B*C;
PRINT();
PRINT("Volume: "+V);
END;
END;
Putting It All Together
Symb()
BEGIN
// Choose the calculation
// Global vars are used
INPUT({{I,{"Area: Circle",
"Area: Ellipse",
"Area: Trapezoid",
"Area: Circular Sector",
"Area: Regular Polygon",
"Volume: Sphere",
"Volume: Cylinder",
"Volume: Cone",
"Volume: Box",
"Volume: Ellipsoid"}}},
"Select Your Calculation");
MSGBOX("It's set!");
END;
//Plot()
//BEGIN
// MSGBOX("Plot");
//END;
Num()
BEGIN
IF I==1 THEN
INPUT(R,"Area: Circle","Radius: ");
E:=π*R^2;
PRINT();
PRINT("Area: "+E);
END;
IF I==2 THEN
INPUT({A,B},"Area: Ellipse",
{"A: ","B: "});
E:=π*A*B;
PRINT();
PRINT("Area: "+E);
END;
IF I==3 THEN
INPUT({A,B,H},"Area: Trapezoid",
{"A: ","B: ","H: "});
E:=0.5*H*(A+B);
PRINT();
PRINT("Area: "+E);
END;
IF I==4 THEN
INPUT({θ,R},"Area: Circular
Sector",{"Angle (°): ",
"Radius: "});
E:=θ*π*R^2/360;
PRINT();
PRINT("Area: "+E);
END;
IF I==5 THEN
INPUT({N,S},"Area: Regular
Polygon",{"# sides: ",
"Length: "});
E:=N*S^2/(4*TAN(180/N));
PRINT();
PRINT("Area: "+E);
END;
IF I==6 THEN
INPUT(R,"Volume: Sphere","Radius: ");
V:=4/3*π*R^3;
PRINT();
PRINT("Volume: "+V);
END;
IF I==7 THEN
INPUT({R,H},"Volume: Cylinder",
{"Radius: ","Height: "});
V:=π*R^2*H;
PRINT();
PRINT("Volume: "+V);
END;
IF I==8 THEN
INPUT({R,H},"Volume: Cone",
{"Radius: ","Height: "});
V:=π*R^2*H/3;
PRINT();
PRINT("Volume: "+V);
END;
IF I==9 THEN
INPUT({A,B,C},"Volume: Box",
{"A: ","B: ","C: "});
V:=A*B*C;
PRINT();
PRINT("Volume: "+V);
END;
IF I==10 THEN
INPUT({A,B,C},"Volume: Ellipsoid",
{"A: ","B: ","C: "});
V:=4/3*π*A*B*C;
PRINT();
PRINT("Volume: "+V);
END;
END;
//SymbSetup()
//BEGIN
// MSGBOX("SymbSetup");
//END;
//PlotSetup()
//BEGIN
// MSGBOX("PlotSetup");
//END;
//NumSetup()
//BEGIN
// MSGBOX("NumSetup");
//END;
Info()
BEGIN
PRINT();
PRINT("GeomCalc");
PRINT("---------");
PRINT("EWS 2018-02-07");
PRINT("---------");
PRINT("Geometry areas and volumes");
END;
START()
BEGIN
// Set app angle to degrees
AAngle:=2;
MSGBOX("Ready.");
END;
//RESET()
//BEGIN
// MSGBOX("RESET");
//END;
Examples
I plan to post another example by next week, that one will involve plotting.
Eddie