CSIS 10A MIDTERM EXAMName:

Worth 100 PointsOpen-book Open-noteNo Computer

Put down your answers on paper in an orderly and recognizable fashion.

1. Give the numerical value of each of the following C++ expressions (hint: they are all integers)

a) ______8 / 10b) ______16/ 4*2

c) ______8 + 4 / 2 d) ______5 % 3+ 6

e) ______25 % 7

2. Identify the following names as valid or invalid identifiers in C++:

a) jack_pot ______b) total$money ______

c) tax rate ______d) 2ndYear ______

e) SALARY ______

3. Convert the following numbers to ordinary decimal notation

a) -4.75E+03 ______b) 8.6026E-03 ______

c) –7.3342E-04 ______d) 2.0e+05 ______

4. Exactly ONE line in the following program has a C++ syntax error. Circle the error in that line, and explain what the error is and how to correct it:

#include<iostream>

using namespace std;

int main()

{

int yds, feat;

cout < "Enter number of yards: ";

cin > yards;

feat = yds * 3;

cout< yds < "yards = " < feat < " feet.";

system("pause");

return 0;

}

5 .Give the output of the following program fragment:

int k=6; m = 12;

k = k + m;

m = k - 2;

k = m - k;

cout < "k = " < k < "m = " < m < endl;

6. Consider the following statement:

if (x>15 )

if ( x 20)

cout < “Alright!”;

else

cout < “Hi!”;

else

if (x<5)

cout<"Low!";

a) What would be the output from the above statement when the value of x is 22?______

b) How about when the value of x is 17? ______

c) How about when the value of x is 2? ______

d) How about when the value of x is 8 ? ______

7. Give the output of the following program fragmentOUTPUT

for(int k= 40; k > 10; k = k - 10)

{

cout< k < " ";

}

cout < "Done"<endl;

8. What will be the output for the following code segment when

a)x=5, y=5______

b)x=4, y=6______

c)x=1, y=8______

if (x == y || y> 6)

y = 10;

else

x = 2;

cout < x < " " < y < endl;

9. What are the outputs of this code?

OUTPUT

string s1 = “Atlas”, s2 = “King”, s3;

s3 = s1 + s2;

cout < s1 < endl;

cout < s3 < endl;

s1 += s3 ;

cout < s1 < endl;

cout < s2 < endl;

10. Convert the following English descriptive statements to a LEGAL C++ conditional expression that gives true when the variable satisfies the description. For example, the statement "a is over 100" translates to C++ as (a > 100)

a)x is between 100 and 200 inclusive ______

b)x is above 100 or below 0 ______

c)x is greater than 0 but it is not 5 ______

11. (10 Points) Define a function named calcSize; the function is passed a character argument representing a size code and the function returns the size in inches (an integer) according to the following chart and sample function calls:

CodeSize in Inches
'S'26
'M'30
'L'34
any other 0 / cout<calcSize('S') will display 26
cout<calcSize('M') will display 30

Use the following schematic function definition, filling in the missing parts:

______calcSize(______size)

{

if ( ______)

return ______;

else if ( ______)

return ______;

else if ( ______)

return ______;

else

return ______;

}

12. (10 Points) Write a function getMin, which is passed 3 integer arguments and returns the smallest of the 3 arguments. For example the following example function calls

y = getMin(5, 1, 3); will store 1 in y

y = getMin(6, 4, 3); will store 3 in y

13. (10 Points) Give a trace and output for the following fragment if the input is:

116 15

x y y>10 OUTPUT

x = 0;

for(i=1; i<4; i++)

{

cout < " Enter a number:";

cin > y;

if(y 10 )

x = x + y;

else

x = x– y;

cout < x < " " < y < endl;

}

14. (10 Points) Show what is printed by the following program segment. (remember: integer arithmetic)

OUTPUT

int a =2, z = 16;

while (z >= a)

{

z -= a;

a += z / 2;

cout < a < z;

}

15. (10 Points) Write a program that asks the user to input a list of five numbers (integers). The program will count how many of the input numbers were over 100. For example, see the following sample execution:

Sample execution
(computer output bold, user input italics)
Enter five numbers:
500 50 90 150 175
There were 3 numbers over 100 / Your Program Here (assume all libraries are included)
int main()
{
}