The University of Alabama in Huntsville>
ECE Department
CPE 197 01
Spring 2001
Sample Test III Solution
1. 6, number is 128 the last time through
2. a. 4, 6, 8, 10, 12, 14, 16,
b. Change != to <=, Move n = n + 2; after the cout statement
3. #include
using namespace std;
int main()
{
int n;
int sumpos = 0;
int sumneg = 0;
cin >> n;
while (cin)
{
if (n > 0)
sumpos++;
else if (n < 0)
sumneg++;
cin >> n;
}
cout << "The number of positive integers is " << sumpos << endl;
cout << "The number of negative integers is " << sumneg << endl;
4. 1 3 6 10 15
5. size - value, length - reference, initial - value
6. void Test(int, int, int); // function prototype
int main()
{
int a;
int b;
int c;
.
.
.
Test (a, c, b); // function call
// a, c, and b are arguments
Test (b, a, c); // function call
// b, a, and c are arguments
.
.
.
}
// function definition follows
void Test (int d, // parameter
int e, // parameter
int f // parameter)
{
int g; // local variable
int h; // local variable
.
.
.
}
7. T
8. First call to Test Second call to Test
Parameter Argument Parameter Argument
1. ____d______ _____a_____ 1. ____d______ _____b_____
2. ____e______ _____c_____ 2. ____e______ _____a_____
3. ____f______ _____b_____ 3. ____f______ _____c_____
9. The answers are 12 10 3
10. PrintMax(/* in */ int num1,
/* in */ int num2)
11. void SkipToBlank()
{
char ch;
cin.get(ch)
while (ch != ' ')
{
cin.get(ch);
}
12. #include
using namespace std;
void Rotate(int&, int&, int&);
int main ()
{
int num1;
int num2;
int num3;
cin >> num1 >> num2 >> num3;
cout << "The values before the call to Rotate are "
<< num1 << ' ' << num2 << ' ' << num3 << endl;
Rotate (num1, num2, num3);
cout << "The values after the call to Rotate are "
<< num1 << ' ' << num2 << ' ' << num3 << endl;
return 0;
}