//////////////////////////////////////////////////////////
program #1
Gaddis PseudoCode: File Name: p1_empty_program.fprg
----------------------
----------------------
hpprime source code: File: p1_empty_program.hpprgm
//--------------------- comentary
INTEGER := 0; // Declaration for integer
DECIMAL := 0.0; // Declaration for real
TEXT := ""; // Declaration for string
BOOLEAN := FALSE; // Declaration default for boolean
p1_empty_program(); // function prototype
EXPORT p1_empty_program() // visible program
BEGIN // program body
return "Done";
END;
//---------------------
//////////////////////////////////////////////////////////
program #2
Gaddis Pseudocode: File Name: p2_comment.fprg
// This is a comment =)
hpprime source code: File: p2_comment.hpprgm
//---------------------
INTEGER := 0;
DECIMAL := 0.0;
TEXT := "";
BOOLEAN := FALSE;
p2_comment();
EXPORT p2_comment()
BEGIN
// This is a comment =)
return "Done";
END;
//---------------------
//////////////////////////////////////////////////////////
program #3
Gaddis Pseudocode: File Name: p3_output_data.fprg
Display "hello world"
hpprime source code: File: p3_output_data.hpprgm
//---------------------
INTEGER := 0;
DECIMAL := 0.0;
TEXT := "";
BOOLEAN := FALSE;
p3_output_data();
EXPORT p3_output_data()
BEGIN
print("hello world"); wait;
return "Done";
END;
//---------------------
//////////////////////////////////////////////////////////
program #4
Gaddis Pseudocode: File Name: p4_input_data.fprg
Declare Real number
Display "input a real number"
Input number
Display "the number is ", number
hpprime source code: File: p4_input_data.hpprgm
//---------------------
INTEGER := 0;
DECIMAL := 0.0;
TEXT := "";
BOOLEAN := FALSE;
p4_input_data();
EXPORT p4_input_data()
BEGIN
local number := DECIMAL;
print("input a real number"); wait;
input( number );
print("the number is " + number); wait;
return "Done";
END;
//---------------------
//////////////////////////////////////////////////////////
program #5
Gaddis Pseudocode: File Name: p5_data_types.fprg
Declare Integer idz
Declare Real idd
Declare String idt
Declare Boolean idb
Display "Input integer number"
Input idz
Display "the integer is ", idz
Display "input decimal number"
Input idd
Display "the decimal is ", idd
Display "input a text"
Input idt
Display "the text is ", idt
Display "input boolean value"
Input idb
Display "the boolean value is ", idb
hpprime source code: File: p5_data_types.hpprgm
//---------------------
INTEGER := 0;
DECIMAL := 0.0;
TEXT := "";
BOOLEAN := FALSE;
data_types();
EXPORT p5_data_types()
BEGIN
local idz := INTEGER;
local idd := DECIMAL;
local idt := TEXT;
local idb := BOOLEAN;
print("input integer number"); wait;
input(idz);
print("the integer is " + idz); wait;
print("input decimal number"); wait;
input(idd);
print("the decimal is " + idd); wait;
print("input a text"); wait;
input(idt);
print("the text is " + idt); wait;
print("input boolean value"); wait;
input(idb);
print("the boolean value is " + idb); wait;
return "Done";
END;
//---------------------
//////////////////////////////////////////////////////////
program #6
Gaddis Pseudocode: File Name: p6_assignment.fprg
Declare Integer idz
Declare Real idd
Declare String idt
Declare Boolean idb
Set idz = 5
Set idd = 4.999
Set idt = "Hello World"
Set idb = true
Display "the integer is ", idz
Display "the decimal is ", idd
Display "the text is ", idt
Display "the boolean value is ", idb
Set idb = false
Display "the boolean value is ", idb
hpprime source code: File: p6_assignment.hpprgm
//---------------------
INTEGER := 0;
DECIMAL := 0.0;
TEXT := "";
BOOLEAN := FALSE;
p6_assignment();
EXPORT p6_assignment()
BEGIN
local idz := INTEGER;
local idd := DECIMAL;
local idt := TEXT;
local idb := BOOLEAN;
idz := 5;
idd := 4.999;
idt := "Hello World";
idb := true;
print("the integer is " + idz); wait;
print("the decimal is " + idd); wait;
print("the text is " + idt); wait;
print("the boolean value is " + idb); wait;
return "Done";
END;
//---------------------
//////////////////////////////////////////////////////////
program #7
Gaddis Pseudocode: File Name: p7_if_then_block.fprg
Declare String answer
Display "Is there something you need to do? (y/n)"
Input answer
If answer == "n" Then
Display "Stop lying!"
End If
Display "Go do it"
hpprime source code: File: p7_if_then_block.hpprgm
//---------------------
INTEGER := 0;
DECIMAL := 0.0;
TEXT := "";
BOOLEAN := FALSE;
p7_if_then_block();
EXPORT p7_if_then_block()
BEGIN
local answer := TEXT;
print("Is there something you need to do? (y/n)"); wait;
input(answer);
if (answer == "n") Then
print("Stop lying!"); wait;
end;
return "Done";
END;
//---------------------
//////////////////////////////////////////////////////////
program #8
Gaddis Pseudocode: File Name: p8_if_then_else_block.fprg
Declare Integer age
Display "How old are you?"
Input age
If age >= 18 Then
Display "Go vote!"
Else
Display "Sorry, not yet"
End If
hpprime source code: File: p8_if_then_else_block.hpprgm
//---------------------
INTEGER := 0;
DECIMAL := 0.0;
TEXT := "";
BOOLEAN := FALSE;
p8_if_then_else_block();
EXPORT p8_if_then_else_block()
BEGIN
local age := INTEGER;
print("How old are you?"); wait;
input(age);
if (age >= 18) Then
print("Go vote!"); wait;
else
print("Sorry, not yet"); wait;
end;
return "Done";
END;
//---------------------
//////////////////////////////////////////////////////////
program #9
Gaddis Pseudocode: File Name: p9_while_loop_block.fprg
Declare Integer n
Set n = 1
While n <= 20
Display n
Set n = n + 1
End While
hpprime source code: File: p9_while_loop_block.hpprgm
//---------------------
INTEGER := 0;
DECIMAL := 0.0;
TEXT := "";
BOOLEAN := FALSE;
p9_while_loop_block();
EXPORT p9_while_loop_block()
BEGIN
local n := INTEGER;
n := 1;
while (n <= 20) do
print(n); wait;
n := n+1;
end;
return "Done";
END;
//---------------------
//////////////////////////////////////////////////////////
program #10
Gaddis Pseudocode: File Name: p10_for_loop_block.fprg
Declare Integer n
For n = 1 To 20
Display n
End For
hpprime source code: File: p10_for_loop_block.hpprgm
//---------------------
INTEGER := 0;
DECIMAL := 0.0;
TEXT := "";
BOOLEAN := FALSE;
p10_for_loop_block();
EXPORT p10_for_loop_block()
BEGIN
local n := INTEGER;
n := 1;
for n from 1 to 20 step 1 do
print(n); wait;
end;
return "Done";
END;
//---------------------
//////////////////////////////////////////////////////////
program #11
Gaddis Pseudocode: File Name: p11_do_loop_block.fprg
Declare Integer age
Display "Enter a valid AGE [1, ...100]"
Do
Input age
While age < 1 or age > 100
hpprime source code: File: p11_do_loop_block.hpprgm
//---------------------
INTEGER := 0;
DECIMAL := 0.0;
TEXT := "";
BOOLEAN := FALSE;
p11_do_loop_block();
EXPORT p11_do_loop_block()
BEGIN
local age := INTEGER;
print("Enter a valid AGE [1, ...100]"); wait;
repeat
input(age); wait;
until NOT((age < 1) or (age > 100));
print(age); wait;
return "Done";
END;
//---------------------
//////////////////////////////////////////////////////////
program #12
Gaddis Pseudocode: File Name: p12_array_squares.fprg
Declare Integer n
Declare Integer squares[10]
// This loop fills the array with squares. So, squares[3] will be 9. The first subscript (array element number) starts at zero. So, we loop from 0 to 9.
For n = 0 To 9
Set squares[n] = n ^ 2
End For
// This loop will print all the array elements that were assigned in the last loop.
For n = 0 To 9
Display squares[n]
End For
hpprime source code: File: p12_array_squares.hpprgm
//---------------------
INTEGER := 0;
DECIMAL := 0.0;
TEXT := "";
BOOLEAN := FALSE;
p12_array_squares();
EXPORT p12_array_squares()
BEGIN
local n := INTEGER;
local squares:= [INTEGER,INTEGER,INTEGER,INTEGER,INTEGER,INTEGER,INTEGER,INTEGER,INTEGER,INTEGER]; // 10 integer elements
for n from 1 to 10 step 1 do // fix range +1
squares[n]:= ((n-1) ^ 2); // fix n-1 only right side
end;
for n from 1 to 10 step 1 do
print(squares[n]); wait;
end;
return "Done";
END;
//---------------------
//////////////////////////////////////////////////////////
program #13
Gaddis Pseudocode: File Name: p13_string_functions.fprg
Declare String name
Declare Integer n
Display "input a text"
Input name
For n = 0 To len(name)-1
Display substring(name, n, 1)
End For
hpprime source code: File: p13_string_functions.hpprgm
//---------------------
INTEGER := 0;
DECIMAL := 0.0;
TEXT := "";
BOOLEAN := FALSE;
p13_string_functions();
EXPORT p13_string_functions()
BEGIN
local name := TEXT;
local n := 0;
print("input a text"); wait;
input(name); wait;
for n from 1 to dim(name) step 1 do // fix range
print(mid(name, n, 1)); wait;
end;
return "Done";
END;
//---------------------
//////////////////////////////////////////////////////////
program #14
Gaddis Pseudocode: File Name: p14_circle_area.fprg
Module main()
Declare Real x
Display "Input the radius of the circle"
Input x
// The following will call the Circle function using the value the user entered.
// Notice that this variable is called 'x' while the function uses 'Radius'. The value of 'x' is passed to the function.
Display "Area is ", sub_circle(x)
End Module
Function Real sub_circle(Real radius)
// This function has one parameter called Radius. It acts like a local variable that is assigned when the function is called.
Declare Real Area
Set Area = Pi * radius ^ 2
// This function returns the contents of the Area variable.
Return Area
End Function
hpprime source code: File: p14_string_functions.hpprgm
//---------------------
INTEGER := 0;
DECIMAL := 0.0;
TEXT := "";
BOOLEAN := FALSE;
p14_circle_area();
sub_circle();
EXPORT p14_circle_area()
BEGIN
local x := DECIMAL;
print("Input the radius of the circle"); wait;
input(x); wait;
print("Area is " + sub_circle(x)); wait;
return "Done";
END;
EXPORT sub_circle(radius)
BEGIN
local area := DECIMAL;
area := (PI * radius ^ 2);
return area;
END;
//---------------------
//////////////////////////////////////////////////////////