j. (–b + (b * b – 4 * a * c)) / (2 * a) 15. x = 101 y = 28 z = 28 w = 117.5 t = 29.25 17. a. -40 b. 11.5 c. 17.75 d. 18.7 e. 20 f. 88.25 g. 4.0 19. a and c are correct 21. a. int num1; int num2; b. cout << "Enter two numbers separated by spaces." << endl; c. cin >> num1 >> num2; d. cout << "num1 = " << num1 << "num2 = " << num2 << "2 * num1 – num2 = " << 2 * num1 – num2 << endl; 23. A correct answer is: #include <iostream> namespace std; const char = '*'; const int PRIME = 71; int main() { int count, sum; double x; int newNum; //declare newNum = 1; sum = + PRIME; x = 25.67; // x = 25.67; newNum = count * 1 + 2; //newNum = count * ONE + 2; sum++; //(x + sum)++; sum = sum + //sum + count = sum; x = x + sum * count; // x = x + sum * COUNT; sum += 3; //sum += 3--;
using namespace std; //Line 2 11. The statement in Line 2 should be: using namespace std; //Line 2 13. Either include the statement: using namespace aaa; before the function main or refer to the identifiers x and y in main as aaa::x and aaa::y, respectively. 15. a. Heelo Thlre b. Giamond Dold c. Ca+ J+va 17. Regular exercise Regular exercise and low fat diet 33 8 8 health insurance insurance Regular exercise can reduce health insurance $$$$. $ocial Nedia!! 14 Social Media!! Chapter 8 1. a. true; b. true; c. true; d. false; e. false; f. false; g. false; h. false; i. true; j. false; k. false; l. false 3. a. This declaration is correct. b. Array size must be positive. A correct answer is: int testScores[10]; c. This declaration is correct. d. Array size must be a positive integer not a range. A correct answer is: int list100[100]; e. gpa is an array of size 50. The expression [50] should be after gpa. The correct statement is: double gpa[50]; f. LENGTH must be declared as integral, such as int . A correct statement is: const int LENGTH = 26; g. This declaration is correct. 5. 0 to 98 7. 0 1 4 9 16 32 1 4 32 36
21. In a public inheritance, the public members of the base class are private members of the derived class. They can be accessed by the member functions (and friend functions) of the derived class. The protected members of the base class are private members of the derived class. They can be accessed by the member functions (and friend functions) of the derived class. The private members of the base class are hidden in the derived class. They cannot be directly accessed in the derived class. They can be accessed by the member functions (and friend functions) of the derived class through the public or protected members of the derived class. 23. The protected members of a base class can be directly accessed by the member functions of the derived class, but they cannot be directly accessed in a program that uses that class. The public members of a class can be directly accessed by the member functions of any derived class as well as in a program that uses that class. 25. The members setX, y, and setY are protected members in class third. The private member x of class first is hidden in class third and it can be accessed in class third only through the protected and public members of class first. 27. Because the memberAccessSpecifier is not specified, it is a private inheritance. Therefore, all the members of the class first becomes private members in class second. 29. a. void two::setData(int a, int b, int c) { one::setData(a, b); z = c; } b. void two::print() const { one::print(); cout << z << endl; }