1.2 c
ADT BowlingBall is
Data
The radius and weight of the ball in lb./ft.3. The numbers
are floating point values > 0
Operations
Constructor
Initial Values: The radius and density of the bowling ball.
Process: Use the initial values to specify the ADT data.
Radius:
Input: None
Preconditions: None
Process: Retrieve the radius of the ball.
Output: return the radius.
Postconditions: None
Weight:
Input: None
Preconditions: None
Process: Compute the weight by multiplying the balls volume
by the balls density.
Output: return the weight.
Postconditions: None.
end ADT BowlingBall.
(2.2)
(2.6)
%
Input: Two integers u and v.
Preconditions: Integer
since operation u%0
is undefined.
Process: Compute the remainder from the long division.
Output: Return the integer r.
Postconditions None.
<Operator "!=" is not done>
(2.7)
(a) ADT Boolean is
Data
Logical values False and True.
Operations
Assume P and Q are boolean variables.
Binary Operators.
&& P&& Q Return the logical value P AND Q
|| P || Q Return the logical value P OR Q
Unary Operator
! !P Change the logical value of P.
end ADT Boolean
class Boolean
{
private:
int boolvalue;
public:
Boolean(void);
Boolean operator && (Boolean p, Boolean q);
Boolean operator || (Boolean p, Boolean q);
Boolean operator != (Boolean p);
};
For implementation of the operations
return p.boolvalue && q.boolvalue; //operation && return p.boolvalue || q.boolvalue; //operation || return !p.boolvalue; //operation !=
(2.10) The operation % is not defined for real numbers.
(2.13)
(2.15)
(2.16)
SUCC Input: Enumeration type variable v. Preconditions: v cannot be the last item in the list. Process: Identify the next item in the list after v. Output: Return the next item. Postconditions: None. <PRED is not done >