The University of Alabama in Huntsville Electrical & Computer Engineering CPE 197 02 Spring 2001 Test 3 Solution 1. The loop is executed for number - 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 for a total of 10 times. 2. a. 2 3 4 5 6 7 8 9 10 11 b. number = 1; while (number < 11) { cout << number << endl; number++; } 3. #include ifstream indat; indat.open("input.dat"); int score; int sum = 0; int count = 0; float average; indat >> score; while (indat) { if (score >= 0 && score <= 100) { count++; sum = sum + score; } indat >> score; } average = float(sum)/count; 4. 2 1 4 2 1 3 2 1 2 2 1 1 5. size and length are reference parameters, initial is a value parameter 6. a. void Test(int, int, int); b. In the function call Test(a, c, b), a, c, and b are the arguments. In the function call Test(b, a, c), b, a, and c are the arguments. c. The variables a, b, and c are local to main. The variables g and h are local to Test. d. void Test(int d, int e, int f) { int g; int h; . . . } is a function definition e. In the function Test, d, e, and f are parameters. f. Test (a, c, b); and Test(b, a, c) are function calls. 7. First call parameter argument s d t e Second call parameter argument s e t d 8. In function Test, the variables equal 5 9 In the main function after the first call, the variables equal 5 14 In function Test, the varaibles equal 5 9 In the main function after the second call, the varialbes equal 15 5 9. True 10. False 11. True 12. False 13. False 14. void rocket_sim(/* in */ float thrust, /* inout */ float& weight, /* in */ int timeStep, /* in */ int totalTime, /* out */ float& velocity, /* out */ bool& outOfFuel) 15. void CountUpper(int& upCount) { upCcount = 0; char ch; cin >> ch; while (ch != '\n') { if (isupper(ch)) upCount++ cin >> ch; } } 16. void Rotate(/* inout */ int& firstValue, /* inout */ int& secondValue, /* inout */ int& thirdValue, /* inout */ int& fourthValue) { int temp; temp = firstValue; firstValue = secondValue; secondValue = thirdValue; thirdValue = fourthValue; fourthValue = temp; } 17. 1 2 5 3 4