Problems 1, 2, 3, and 4 Problem 5:Construct a logical expression to represent each of the following conditions:
b. number is divisible by 2 but not by 3
(number % 2 == 0) and (number % 3 != 0)
c. angle is between ¹ and 2¹
(pi < angle) and ( angle < 2 * pi)
d. response is either 'Y' or 'y'
(response == 'Y') or (response == 'y')
e. ch is a digit
('0' <= ch) and (ch <= '9')
f. tired but not done
tired and not done
Problem 6:
int min3(int x, int y, int z){ if ((x <= y) and (x <= z )) return x; if ((y <= x) and (y <= z )) return y; return z; }
Problem 7:
bool GetCircleData(int& x, int& y, int& radius){ cout << "Enter circle data: x y radius" << endl; cin >> x >> y >> radius; return (radius >= 0); }
Problem 8:
void extremes(int& min, int& max, int A[], int n){ min = A[0]; // start min and max with values that occur in the array max = A[0]; for (int J = 1; J < N; J++){ if (A[J] < min) min = A[J]; else if (A[J] > max) max = A[J]; } }
Last Updated: November 16, 1997 12:17 pm by
Harriet Fell
College of Computer Science, Northeastern University
360 Huntington Avenue #161CN,
Boston, MA 02115
Internet: fell@ccs.neu.edu
Phone: (617) 373-2198 / Fax: (617) 373-5121
The URL for this document is: http://www.ccs.neu.edu/home/fell/COM1100/HW/Exercises1Solution.html