Q1: Write (militaryTime t AMPM), where t is an integer from 1 to 12 (inclusive) and AMPM is either 0 to represent morning or 1 to represent afternoon/evening. The function will convert the hours of the day from standard to military time.
(militaryTime 5 0) returns 5
(militaryTime 8 1) returns 20
(militaryTime 12 0) returns 0
(militaryTime 12 1) returns 12
Q2: Write (xor a b) that represents the exclusive-or logical operator, which returns true if either a or b is true, but not both. In this program, a and b are boolean expressions (they can be either true or false). Q1: Write (militaryTime t AMPM), where t is an integer from 1 to 12 (inclusive) and AMPM is either 0 to represent morning or 1 to represent afternoon/evening. The function will convert the hours of the day from standard to military time.
(militaryTime 5 0) returns 5
(militaryTime 8 1) returns 20
(militaryTime 12 0) returns 0
(militaryTime 12 1) returns 12
Q2: Write (xor a b) that represents the exclusive-or logical operator, which returns true if either a or b is true, but not both. In this program, a and b are boolean expressions (they can be either true or false). Q1: Write (militaryTime t AMPM), where t is an integer from 1 to 12 (inclusive) and AMPM is either 0 to represent morning or 1 to represent afternoon/evening. The function will convert the hours of the day from standard to military time.
(militaryTime 5 0) returns 5
(militaryTime 8 1) returns 20
(militaryTime 12 0) returns 0
(militaryTime 12 1) returns 12
Q2: Write (xor a b) that represents the exclusive-or logical operator, which returns true if either a or b is true, but not both. In this program, a and b are boolean expressions (they can be either true or false). Q1: Write (militaryTime t AMPM), where t is an integer from 1 to 12 (inclusive) and AMPM is either 0 to represent morning or 1 to represent afternoon/evening. The function will convert the hours of the day from standard to military time.
(militaryTime 5 0) returns 5
(militaryTime 8 1) returns 20
(militaryTime 12 0) returns 0
(militaryTime 12 1) returns 12
Q2: Write (xor a b) that represents the exclusive-or logical operator, which returns true if either a or b is true, but not both. In this program, a and b are boolean expressions (they can be either true or false). Q1: Write (militaryTime t AMPM), where t is an integer from 1 to 12 (inclusive) and AMPM is either 0 to represent morning or 1 to represent afternoon/evening. The function will convert the hours of the day from standard to military time.
(militaryTime 5 0) returns 5
(militaryTime 8 1) returns 20
(militaryTime 12 0) returns 0
(militaryTime 12 1) returns 12
Q2: Write (xor a b) that represents the exclusive-or logical operator, which returns true if either a or b is true, but not both. In this program, a and b are boolean expressions (they can be either true or false).
3 answers
For example, for Q2, exclusive OR, the truth table is:
P Q P.xor.Q
T T F
T F T
F T T
F F F
The pseudocode looks something like:
if (P and Q) or (~P and ~Q) reutrn false
else return true.
Would you suggest some code or pseudocode for Q1?
In case you don't already know, Scheme uses the prefix notation, similar to some older HP calculators.
Unless someone else here is familiar with Scheme, you will have to consult your textbook or a Scheme tutorial for the syntax. You can also download the compiler for testing.
Feel free to post your code for discussion if you wish.