# Solutions - Exercise Solutions Chapter 1 1 a true b false c...

This preview shows pages 1–5. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Exercise Solutions Chapter 1 1. a. true; b. false; c. false; d. false; e. false; f. true; g. false; h. false 2. Precondition: The value of x must be nonnegative. Postcondition: If the value of x is nonnegative, the function returns the positive square root of x ; otherwise, the program terminates. 3. a. O ( n 2 ) b. O ( n 3 ) c. O ( n 3 ) d. O ( n ) 4. 12 5. a. 43 b. 4 n + 3 c. O ( n ) 6. -51, -50, -49, -1, 0, 1, 49, 50, 51 7. #define NDEBUG 8. a. int sumSquares(int n) { int sum = 0; for(int j = 1; j <= n; j++) sum = sum + j * j; return sum; } b. This function is of the order O ( n ). 9. The black-box refers to testing the correctness of the program; that is, making sure that the program does what it is supposed to do. In black-box testing, you do not know the internal working of the algorithm or function. You know only what the function does. Black-box testing is based on inputs and outputs. 10. The white-box refers to testing the correctness of the program; that is, making sure that the program does what it is supposed to do. White-box testing relies on the internal structure and implementation of a function or algorithm. The objective is to ensure that every part of the function or algorithm is executed at least once. 11. a. Constructors have no type. Therefore, the statement: int AA(int, int); should be : 1 AA(int, int); b. Missing semicolon after } . c. There should be a : after the member access specifier public . (Replace ; with : after the label public .) 12. a. 6 b. 2 c. 2 d d. e void xClass::func() { u = 10; v = 15.3; } f e. g void xClass::print() { cout<<u<<" "<<v<<endl; } h f. xClass::xClass() { u = 0; v = 0; } g. x.print(); h. xCalss t(20, 35.0); 13. a. (i) Constructor at Line 1 (ii) Constructor at Line 3 (iii) Constructor at Line 4 b. CC::CC() { u = 0; v = 0; } c. CC::CC(int x) { u = x; v = 0; } d. CC::CC(int x, int y) { u = x; v = y; } CC::CC(double x, int y) 2 { u = y; v = x; } 14. a. int testClass::sum() { return x + y; } void testClass::print() const { cout<<"x = "<<x<<", y = "<<y<<endl; } testClass::testClass() { x = 0; y = 0; } testClass::testClass(int a, int b) { x = a; y = b; } b. (One possible solution. We assume that the name of the header file containing the definition of the class testClass is Exercise14Ch1.h.) #include <iostream> #include "Exercise5Ch1.h" using namespace std; int main() { testClass one; testClass two(4,5); one.print(); two.print(); return 0; } 3 Chapter 2 1. a. true; b. true; c. true; d. false; e. false; f. true; g. true; h. false; i. false; j. true; k. false; l. true; m. false; n. false 2. 3. Some of the data members that can be added to the class employeeType are: department, salary, employeeCategory (such as supervisor and president), and employeeID . Some the member functions are: setInfo , getSalary , getEmployeeCategory , and setSalary ....
View Full Document

{[ snackBarMessage ]}

### Page1 / 36

Solutions - Exercise Solutions Chapter 1 1 a true b false c...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online