Ragsdale COMP test 1-3

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

6) Given a list of syntax errors from a compiler, a programmer should focus attention on which error(s), before recompiling? a. All the errors b. The first error only c. The middle error only d. The last error only

b. The first error only

1) Choose the statement(s) that generate(s) this output: I wishyou were here a. cout << "I wish" + "you were here"; b. cout << "I wish" << endl;cout << "you were here"; c. cout << "I wish";cout << "you were here" << endl; d. cout << "I wish" << ln << "you were here";

b. cout << "I wish" << endl;cout << "you were here";

19) C++ is _____. a. derived from Fortran b. derived from C c. derived from Python d. derived independently of any other language

b. derived from C

What is the output for x = 15? switch (x) {case 10:// Output: "First "break;case 20:// Output: "Second "break;default:// Output: "No match "break;} First Second First Second No match

No match

What is read into string myString for input "One-hit wonder". cin >> myString; One One- One-hit One-hit wonder

One-hit

For what values of x does the default case execute in the code below? x is declared as an integer. switch (x) {case 2:...break; case 3:...break;case 4:...break; default:... // When does this execute?} Only for value 5 Only for all values greater than 4 Only for values that are not 2, 3, or 4

Only for values that are not 2, 3, or 4

Which is best declared as a constant? The number of people in a car The number of feet in a yard The number of leaves on a tree The number of insects in a room

The number of feet in a yard

11) Which item converts a high-level language program to low-level machine instructions? a. Compiler b. Machine instruction c. Assembly language d. Memory

a. Compiler

An identifier can _____ . be a reserved word start with an underscore contain a period contain spaces

start with an underscore

Which expression doubles x? x += 2; x *= 2; x *= x; x *= x * 2;

x *= 2;

Which outputs "Negative" for values less than 0, otherwise outputs "Non-negative"? if (val > 0) {cout << "Non-negative";}else {cout << "Negative";} if (val >= 0) {cout << "Non-negative";}else {cout << "Negative";} if (val < 0) {cout << "Non-negative";}else {cout << "Negative";} if (val <= 0) {cout << "Negative";}else {cout << "Non-negative";}

if (val >= 0) {cout << "Non-negative";}else {cout << "Negative";}

Which expression fails to compute the area of a triangle having base b and height h (area is one-half base time height)? (1.0 / 2.0 ) * b * h (1 / 2) * b * h (b * h) / 2.0 0.5 * b * h

(1 / 2) * b * h

A restaurant gives a discount for children under 10. They also give the discount for adults over 55. Which expression evaluates to true if a discount should be given? (age < 10) && (age > 55) (age < 10) || (age > 55) (age >= 10) && (age <= 55) (age >= 10) || (age <= 55)

(age < 10) || (age > 55)

Which expression evaluates to false if x is 0 and y is 10? (x == 0) && (y == 10) (x == 0) && (y == 20) (x == 0) || (y == 10) (x == 0) || (y == 20)

(x == 0) && (y == 20)

Which expression for YYY correctly outputs that x is between 50-100? if (YYY) {// Output "50, 51, ..., 99, 100"} (x >= 50) || (x <= 100) 50 >= x <= 100 50 <= x <= 100 (x >= 50) && (x <= 100)

(x >= 50) && (x <= 100)

What possible values can x % 10 evaluate to? (x is an integer). 0..9 1..10 0..10 1..11

0..9

What is y after executing the statements? x = 4;y = x + 1;x = 3;y = y * 2;

10

What is the ending value of cost? int numApples = 3;double cost;cost = 1.2 * numApples; 3 3.2 3.6 4

3.6

What is the final value of y? int x = 77;int y = 4;if (x == 77) {y = y + 1;}if (x < 100) {y = y + 1;}if (x > 77) {y = y + 1;}y = y + 1; 5 6 7 8

7

What is the ending value of y? sqrt(u) returns the square root of u. pow(u, v) returns u raised to the power of v. x = 9.0;y = 4.0;y = pow(sqrt(x), sqrt(y)); 8.0 9.0 6561.0 Error: The sqrt functions cannot appear in the call to the pow function

9.0

What does the compiler do upon reaching this variable declaration? int x; Allocates a memory location for x Initializes x with the value -1 Converts variable x from a double to an integer Increments x's value by 1

Allocates a memory location for x

For which quantity is a double the best type? People in a household Boxes on a conveyor belt Planes above a city Height of a building

Height of a building

If the input is 5, what is the output? int x;cin >> x;if (x < 10) {cout << "Live "; }else if (x < 20) {cout << "long ";}else if (x < 30) {cout << "and ";}cout << "prosper!"; Live Live long Live prosper! The compiler will complain about a missing else statement

Live prosper!

If the input is -5, what is the output? If x less than 0Put "Low " to outputElse if x greater than 0Put "OK " to outputElse if x less than -3Put "Very low " to output Low Low Very low (Runs, but no output) Error: The compiler will complain about a missing else statement

Low

What value of x outputs "Junior"? if (x < 56) {// Output "Sophomore"}else if (x > 56) {// Output "Senior"}else {// Output "Junior"} Value 56 Values 57 or larger 55 or 57 No such value

Value 56

Which expressions for YYY and ZZZ will output "Young" for ages less than 20 and "Young Adolescent" for ages between 10 and 20? int u;cin >> u;if (YYY) {cout << "Young";if (ZZZ) {cout << " Adolescent";}} YYY: u < 20 ZZZ: u < 10 YYY: u < 20 ZZZ: u > 10 YYY: u > 20 ZZZ: u < 10 YYY: u > 20 ZZZ: u > 10

YYY: u < 20 ZZZ: u > 10

Given only int variables a and b, which is a valid expression? 4a + 3 a + ab a + -2 2 x 3

a + -2

14) Which is not a component of a computer? a. Clock b. Memory c. Processor d. Programmer

d. Programmer

24) Which is an example of a process? a. int b. y, 10 c. 15 d. x + y

d. x + y

What is the ending value of x? x = 160 / 20 / 4; 2 16 32 No value; runtime error

2

Which expression evaluates to 3.5? int x = 7;int y = 1; x * (1 / 2) (x / 2.0) x.0 / 2 (x / 2) * 1.0

(x/2.0)

What is the ending value of y? int x;int y;x = 2;y = ((x + 1) / 5) + (x / 2) ; 1 1.6 4.5 Error: Division not possible

1

Which is a correct scientific notation for the floating-point literal: 0.00001 0.1e-6 0.1e-5 1.0e-5 1.0e-6

1.0e-5

If the input is 12, what is the final value for numItems? int x;int numItems = 0;cin >> x;if (x <= 12) {numItems = 100;}else {numItems = 200;}numItems = numItems + 1; 100 101 200 201

101

Which is not a valid identifier? firstName first_name 1stName name1

1stName

2) What does this code output? cout << "I ";cout << "want pie." << endl; a. I want pie. b. "I ""want pie." c. I wantpie d. I wantpie e. I wantpie

a. I want pie.

15) A _____ is a computer component that stores files and other data. a. disk b. monitor c. keyboard d. processor

a. disk

7) If a program compiles without errors, the program is free from _____. a. syntax errors b. logic errors c. runtime errors d. semantic errors

a. syntax errors

21) Three sock types A, B, C exist in a drawer. Pulled socks are kept and not returned. Which is true? a. If the first two pulls are different socks, only one more pull is needed for a match b. If the first three pulls are different socks, only one more pull is needed for a match c. If the first two pulls are different socks, at least two more pulls are needed for a match d. If the first three pulls are different socks, at least two more pulls are needed for a match

b. If the first three pulls are different socks, only one more pull is needed for a match

18) In what year was the first book of C published? a. 1819 b. 1920 c. 1978 d. 2010

c. 1978

10) Which text most closely resembles the form in which one instruction is stored in a single location of a typical computer's memory? a. w = (x + y) * (y - z) b. w = x + 000111 - (y * 1110101) c. Add 34, #9, 25 d. (Mul 45, 2) + (Mul 33, 5) + (Mul 4, 8)

c. Add 34, #9, 25

20) Which is true? a. C came after C++ b. C++ came after C+ c. C++ came after C d. C++ came after C+ but before C

c. C++ came after C

9) In what component does a processor store the processor's required instructions and data? a. Mailbox b. Switch c. Memory d. Bit

c. Memory

16) RAM is an abbreviation that stands for: a. Real Analog Memory b. Ranged Access Memory c. Random Access Memory d. Random Abbreviated Memory

c. Random Access Memory

13) What is Moore's law? a. A processor used in cold weather is more likely to fail b. Every action has an equal and opposite reaction c. The capacity of ICs doubles roughly every 18 months d. Any given program will become obsolete

c. The capacity of ICs doubles roughly every 18 months

22) A sequence of instructions that solves a problem is called a(n) _____ . a. instruction b. process c. algorithm d. variable

c. algorithm

23) In an instruction like: z = x + y, the symbols x, y, and z are examples of _____. a. output b. visibles c. variables d. instructions

c. variables

8) A program should compute two times x. Which statement has a logic error? a. y = x + x; b. y = 2 * x; c. y = x * x; d. y = x * 2;

c. y = x * x;

Which declaration assigns a variable with 5 such that the value can not be later changed? const int = 5; int numItems = 5; int NUM_ITEMS = 5; const int NUM_ITEMS = 5;

const int NUM_ITEMS = 5;

12) What does a clock do? a. Stores the computer's programs b. Counts the number of instructions executed by a processor c. Interfaces with peripherals d. Determines the rate of execution for a processor's instructions

d. Determines the rate of execution for a processor's instructions

3) What will a compiler do for the following code? /* numItems = 2; /* Total items to buy */ rate = 0.5;*/ a. Ignore numItems = 2, but generate code for rate = 0.5. b. Generate code for numItems = 2, but ignore rate = 0.5. c. Ignore both statements. d. Generate an error.

d. Generate an error.

5) What will a compiler do for the following three lines of code? // x = 2; // width// y = 0.5// z = x * y; Total area a. Yield an error for line 1 (x = ...) b. Yield an error for line 2 (y = ...) c. Yield an error for line 3 (z = ...) d. Ignore all three lines

d. Ignore all three lines

4) Which is true for comments? a. The compiler converts comments into a series of machine instructions. b. The compiler translates comments into ASCII values. c. The compiler allocates memory for comments along with for variables. d. The compiler does not generate machine code for comments

d. The compiler does not generate machine code for comments

17) The _____ is a process that manages programs and interfaces with peripherals. a. clock b. BIOS c. integrated circuit d. operating system

d. operating system

Given x = 1, y = 2, and z = 3, how is the expression evaluated? In the choices, items in parentheses are evaluated first. (x == 5) || (y == 2) && (z == 5) false OR (true AND false) --> false OR false --> false false OR (true AND false) --> false OR true --> true (false OR true) AND false --> true AND false --> false (false OR true) AND false --> true AND false --> true

false OR (true AND false) --> false OR false --> false

The world population is over 7 billion. Which declaration uses the fewest bits while guaranteeing that worldPopulation can be assigned the value 7 billion without error? int worldPopulation; long worldPopulation; long long worldPopulation; long long long worldPopulation;

long long worldPopulation;

Which expressions for XXX, YYY, and ZZZ output "Great job" for scores above 90, and "Nice try" otherwise? Choices are in the form XXX / YYY / ZZZ. int score;cin >> score;if (XXX) {cout << YYY;}else {cout << ZZZ;} score < 91 / "Great job" / "Nice try" score < 91 / "Nice try" / "Great job" score > 90 / "Nice try" / "Great job" (Not possible for given code)

score < 91 / "Nice try" / "Great job"

Which expressions for YYY and ZZZ correctly output the indicated ranges? Assume int x's value will be 0 or greater. Choices are in the form YYY / ZZZ. if (YYY) {// Output "0-29"} else if (ZZZ) {// Output "30-39"}else {// Output "40+"} x < 29 / x >= 29 x < 30 / x >= 30 x < 30 / x < 40 x > 29 / x > 40

x < 30 / x < 40


Set pelajaran terkait

Chapter 14 Alcohol Addiction and Families

View Set

Systems Analysis and Design - Chapter 4

View Set

Chapter 22 MedSurg Exam 4 Review (Evolve Questions)

View Set

weather, climate and global warming

View Set