Docsity

CS 101 Pledged Test 1 - Spring 1998, Exams of Computer Science

Toggle sidebar
bg1
CS 101 Pledged Test 1 Spring 1998
Pledged Page 1 of 4
This pledged test is closed-book, closed-notes. All answers must be written on the answer sheet.
In the questions that follow you are sometimes asked to give the output of a code segment. If you believe
the code segment does not produce any output, write NONE.
1. What is your intended major?
2. What base ten integer is represented by the eight bit two’s complement number 01001011?
3. Write down the eight-bit, two’s complement representation of the base ten number -47.
4. For each of the following C++ constant values identify its base and its type.
(a) 7L
(b) 00101100
(c) 800
(d) 0x98
(e) 17.4
5. Does a syntax rule or a semantic rule specify program form?
6. Does a syntax rule or a semantic rule specify program behavior?
7. Which one of the following is not a legal character for a C++ identifier?
(a) period
(b) uppercase alphabetic
(c) underscore
(d) uppercase alphabetic
(e) digit
8. True or False An object can have a value.
9. True or False An object can have member functions.
10. True or False The objects "1" and ’1’ have the same type.
11. True or False The ^ is the C++ exponentiation operator.
12. What return value(s) for functions main() and ApiMain() indicate success?
13. Suppose the following definitions are in effect.
int i = 8;
int j = 4;
float a = 1.0;
float b = 4.0;
For each of the following expressions give the computed value and its type.
(a) j / i
(b) a / b
(c) 4 % 3
(d) 1 + 2 * 3
(e) 4 / 8 * 2.0
pf3
pf4

Partial preview of the text

Download CS 101 Pledged Test 1 - Spring 1998 and more Exams Computer Science in PDF only on Docsity!

This pledged test is closed-book, closed-notes. All answers must be written on the answer sheet.

In the questions that follow you are sometimes asked to give the output of a code segment. If you believe the code segment does not produce any output, write NONE.

  1. What is your intended major?
  2. What base ten integer is represented by the eight bit two’s complement number 01001011?
  3. Write down the eight-bit, two’s complement representation of the base ten number -47.
  4. For each of the following C++ constant values identify its base and its type.

(a) 7L (b) 00101100 (c) 800 (d) 0x (e) 17.

  1. Does a syntax rule or a semantic rule specify program form?
  2. Does a syntax rule or a semantic rule specify program behavior?
  3. Which one of the following is not a legal character for a C++ identifier?

(a) period (b) uppercase alphabetic (c) underscore (d) uppercase alphabetic (e) digit

  1. True or False An object can have a value.
  2. True or False An object can have member functions.
  3. True or False The objects "1" and ’1’ have the same type.
  4. True or False The ^ is the C++ exponentiation operator.
  5. What return value(s) for functions main() and ApiMain() indicate success?
  6. Suppose the following definitions are in effect. int i = 8; int j = 4; float a = 1.0; float b = 4.0; For each of the following expressions give the computed value and its type. (a) j / i (b) a / b (c) 4 % 3 (d) 1 + 2 * 3 (e) 4 / 8 * 2.
  1. Indicate why the following statement is not a valid C++ expression. [0 + 1 * (3 - 3) + 5] / 2
  2. Give the preprocessor statement that allows a program to perform standard input and output requests.
  3. True or False The following statements produce the same output. cout << "1" << endl; cout << ’1’ << endl; cout << 1 < endl;
  4. Suppose i is an int object. What must be true about i for the following statement not to compile? i = 7;
  5. Write a definition that initializes a string object s such that when it is displayed it produces a 1.
  6. Write a statement that sends a message to SimpleWindow object W to display itself.
  7. Write a statement that sends RectangleShape object R a message to display itself.
  8. True or False The and operator has greater precedence than the or operator.
  9. True or False The not operator has greater precedence than the addition operator.
  10. True or False The relational operators have greater precedence that the logical operators.
  11. Write a statement that decreases the value of object k by 1 without using the assignment operator =.
  12. Name the three looping constructs in C++.
  13. Name the two conditional constructs in C++.
  14. In showing that a for statement can be rewritten as a code segment using a while statement, we surrounded our answer by matching curly braces. Why?
  15. What do we call a loop that has a test expression that is always true?
  16. Which parts of a for statement are optional?
  17. What keyboard character indicates that there is no more input?
  18. Suppose there are no more values available for extraction from the input stream fin. What is the output of the following code segment? ifstream fin("scores.dat"); if (fin >> c1) { cout << 1 << endl; } else { cout << 2 << endl; }
  19. The action of a for statement executes a minimum of how many times?
  20. Write a statement that extracts to object c the next nonblank character from the standard input stream.
  21. Write a statement that extracts to object c the next character from the standard input stream.
  1. Do the following two correct code segments have the same effect on the object P? If so, answer “yes”. If not, explain why. (a) if (m < 5) { if (n < 10) { P = true; } else { P = false; } } (b) if ((m < 5) && (n < 10)) { P = true; } else { P = false; }
  2. Give a truth table for logical operands P, Q, and R. A table entry is true when P is true and Q is false. A table entry in the table is also true when P is false and Q and R have different values. The remaining table entries are all false.
  3. Complete a program that performs the following task. A user is to be prompted for a integer value sum that is supposed to be in the interval 0 … 24. If the value of sum is not in the proper interval, the only actions that should take place are displaying an error message and returning control back to the operating system. If the value for sum is in the proper interval, the user should be prompted for a number of dimes d, a number of nickels n, and a number of pennies p. If the monetary value of the coins provided by the user equals sum, display the message yes, otherwise display the message no.