SYSC-135 Introduction to Programming - Fall 1999-2

 

Examination I

 

 

Name: ________________________________�������� ID:____________________________

 

 

There are 34 questions on this exam.� The number of points N each question is worth in indicated by [N] at the beginning of the question narrative.� You should read each question carefully before answering.� Write the correct answer in the space provided Unless otherwise indicated, there is one correct answer to each multiple-choice question.

If you must erase, do so completely.� Exam is closed book, closed notes.

 

 

QUESTIONS

 

1.[2] A(n) __________________________is a function that does not return a function value to its caller and is invoked as a complete, stand-alone statement.

 

2.� [21 The following series of steps is not an algorithm.� How would you correct it?

 

Putting on a Pair of Athletic Shoes

 

Step 1. Put on one shoe.

Step 2. Tie the laces.

Step 3. Repeat.

 

a)�� Exchange steps 2 and 3.

b)�� Exchange steps 1 and 2.

c)�� Change step I to "Put on both shoes."

d)�� Change step 3 to "Repeat once."

 

 

 

 

 

 

 

 

 

 

 

 

3.��� [3] Which of the following code segments could be used to skip the first two characters of an input line (they may or may not be whitespace characters) and input the integer value that comes next? (Variable dummy is of type char, and inputInt is of type int.)

 

a)������ cin >> dummy >> dummy >> inputInt;

b)������ cin.get(dummy);

cin.get(dummy);

cin >> inputInt;

c)��� � cin >> inputInt;

d)��� � cin.get('');

cin.get('');

cin >> inputInt;

e)��� � a and c above

 

4.��� [2] An assembler is a program that translates an assembly language program into a high-level language.

 

a) True

b) False

 

5.��� [21 Which of the following statements about the C++ main function is false?

 

a)��� Every program must have a function named main.

b)��� The word int in the function heading means that the main function returns an integer value (to the operating system).

c)��� The main function must call (invoke) at least one other function.

d)�������� Program execution begins with the first executable statement in the main function.

 

6.��� [2] Inside a computer, a single character such as the letter A usually is represented by a:

 

a)� bit

b)� word

c)� nibble

d)� byte

 

7.      [2] The implicit (automatic) conversion of a value from one data type to another is

called� ____________________.

 

 

8.��� [2] Which of the following terms describes the repetition of statements (instructions) while certain conditions are met?

 

a) subprogram

b) selection

c) sequence

d) looping

 

9.������ [4] Give a C++ arithmetic expression that multiplies the float variable currentSales by three percent, then adds a constant named BASE_PAY: ___________________________

 

 

10.���� [2] The expression int(someFloat) is an example of a(n) __________________operation.

 

11.���� [3] What is the output of the following program fragment? (alpha and beta are int variables.)

 

��������� alpha = 2463,

��������� beta = 72;

��������� cout << " 123456789" << endl

<< setw(5) << alpha << endl

<< setw(5) << beta << endl;

 

 

a) 123456789

2463

72

b) 123456789

����������� �������� 2463

����������� �������� 72

c) 123456789

����������� 24630

����������� 72000

d) 123456789

������������ 2463

���������������� 72

������� e)� none of the above

 

12.���� [2] In the "solve by analogy" technique, you solve a problem by modifying the solution to a similar problem.

 

a) True

b) False

 

13. [4] Exactly what is printed out when the following code is executed:

 

#include <iostream.h>

int main()

{

cout << (3-4) << "st Exam" << endl <<'/n'<< "How is it?�;

return 0;

}

Answer:

����������� ����������� _____________________________________________

����������� ����������� _____________________________________________

����������� ����������� _____________________________________________

����������� ����������� _____________________________________________

 

 

14.��������� (8] The following code reads in an integer then a float from an external file

"infile.dat", performs a calculation and produces output.� Fill in the two missing lines and indicate what will be printed out if the input data are: -7��� 1.2�� ?

 

#include <iostrearn.h>

float thing������ ��������������������� //THING prototype

int main��������� ��������������������� //MAIN function definition

{

��������������������� ��������������������� int x;

��������������������� ��������������������� float b, c;

��������������������� ��������������������� ifstream datafile;

��������������������� ��������������������� ______________��������������������� //open datafile

��������������������� ��������������������� ______________��������������������� //read in x then c

��������������������� ��������������������� b� = thing();

��������������������� ��������������������� b� = b * 2 + x + c;

��������������������� ��������������������� cout << endl << �x� =� � << x << " b = �� << b << � c = � <<� c,

}

float thing( )����� ����������������������� ����������������������� ����������������� //THING function definition

cout << "Entering thing " << endl;

return 4.4;

 

 

Output:

����������� ����������� _____________________________________________

����������� ����������� _____________________________________________

����������� ����������� _____________________________________________

����������� ����������� _____________________________________________

 

 

 

15.���� [2] Given the constant declaration

 

��������� const int FACTOR = 95;

 

��������� which of the following is not a valid use of FACTOR?

 

a)���� cout << FACTOR * 3;

b)���� FACTOR = 24;

c)������ cin >> FACTOR;

d)������ a and c above

e)���� band c above

 

16.���� [12] Match each of the following terms with the correct definition (I through 6) given below.� There is only one correct definition for each term.

 

a. named constant���� d. object code

b. algorithm���� e. compiler

c. syntax���� f variable

 

� (1)�� A place in memory where a data value that can be changed is stored.

� (2)�� A program that takes a program written in a high-level language and translates

����������� into machine code.

(3)�� Grammar rules.

(4)�� A step by step finite procedure for solving a problem.

(5)�� The machine code version of a program.

(6)�� A place in memory where a data value that cannot be changed is stored.

 

17.���� [4] Assuming the integer values a = 5, b = 2, c = 2, d = 6, e = 3 which of the following expressions evaluates to 6:

 

a.�������� d / b+1

b.�������� a + c /a

C.� a% c-l

d.����� (d++)- 1

 

 

18.���� [4] What is the output of the following program fragment?

 

��������� cout << "Barrel" << end];

��������� cout << , ; cout << "of";

��������� cout << "Laughs" << endl;

 

a)������ Barrel

ofLaughs

 

b)         Barrel

�������������� of Laughs

 

c)��� Barrel

of Laughs

 

d)��� Barrel

of

Laughs

 

e)         Barrel of

������ Laughs

 

19. [2] __________________________are the rules by which C++ operators are ordered.

 

20. [2] A(n) __________________ is a statement that stores the value of an

expression into a variable.

 

21. [2] _______________________is the formal rules governing how valid instructions

������ are written in a programming language.

 

22.���� [4] Given the three lines of input data

 

111 222 333

444 555 666

777 888 999

 

what value is read into gamma by the following code?

(All variables are of type int.)

 

cin >> alpha;

cin.ignore(500, '\n');

cin >> beta >> gamma;

 

a)��� 777

b)��� 555

c)��� 333

d)��� 444

e)         none of the above

 

23.���� [4] What will be the value of i and j after the C++ statements below have been executed?� Assume that i and j are declared int.

 

��������� i = 3;

j =5;

 

�� j = i +j + 3;

 

Answer:��� i =��������� �� j =

 

24.���� [2] Which of the following is the second step in the problem-solving phase of a computer program's life cycle?

 

a)������ Analyze the problem.

b)��� Test the solution on a computer.

c)������ Translate the general solution into code.

d)������ Write a general solution for the problem.

e)��� Test the general solution.

 

 

 

 

 

25.���� [2] Which of the following is a valid input statement?

 

a)��� cin >> studentAge;

b)��� cin << studentAge;

c)������ studentAge >> cin;

d)������ studentAge << cin;

e)��� a and c above

 

26.���� [2] The compiler is a program that translates a high-level language program into machine code.

 

a) True

b) False

 

27.���� [2] The single statement

 

��������� cin >> alpha >> beta'.

 

��������� may be used in place of the two statements

 

��������� cin >> alpha;

��������� cin >> beta;

 

a) True

b) False

 

 

28. [2] A(n) __________________________is a mechanism by which functions

����� communicate with each other.

 

29.���� [2] If m and n are type int variables and x is type float, the following assignment statements are not equivalent:

 

x = float (m) / n;������ x = float (m / n);

a.����� true���������� b. false

 

 

 

 

 

30.���� [2] Which of the following statements about C++ stream input is true?

 

a)������ When an integer data value is read into a float variable, the value is first converted into floating point form.

b)������ When an integer data value is read into a float variable, the float variable becomes an int variable.

c)��� It is an error to read an integer data value into a float variable.

d)������ Input of a floating point data value stops when a decimal point is encountered.

e)��� c and d above

 

31.���� [3] An input line consists of a person's first and last initials, separated by a blank:

 

��������� M H

 

Which of the following correctly inputs the person's initials into the char variables firstInit and lastInit?

 

a)��� cin >> firstInit >> lastlnit,'

b)��� cin >> firstInit >> '' >> lastInit;

c)��� cin >> firstInit;

cin.ignore(l, '\n');

cin >> lastInit;

d)��� b and c above

e)��� a and c above

 

32.���� [2] There is only one unique general solution (algorithm) for a given problem.

 

a) True

b) False

 

33.���� [2] The statement

 

��������� const int N = 25;

 

��������� is an example of an assignment statement.

a) True

b) False

 

 

 

 

 

 

 

 

 

 

34.���� [3] If testScore is an int variable containing the value 78, which output statement will produce the output

 

��������� 1234567890

Score: 78

 

 

a)��� cout<<"l234567890"<<endl

<< "Score: " << testScore << endl;

 

�� b) cout << "1234567890" << endl

<< "Score:" << " " << testScore << endl;

 

c)�� cout << "1234567890" << endl

<< "Score:" << setw(4) << testScore << endl;

d)��� a and b above

e)��� a, b, and c above