Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Mistakes that allow a program to run, but cause it to produce erroneous results

ID: 3806156 • Letter: M

Question

Mistakes that allow a program to run, but cause it to produce erroneous results are called

QUESTION 1

logic errors.

syntax errors.

compiler errors.

linker errors.

none of the above.

2 points   

QUESTION 2

A ________ variable is declared outside all functions.

global

static

constant

local

counter

2 points   

QUESTION 3

You may define a(n) ________ in the initialization expression of a for loop.

operator

variable

constant

new data type

new keyword

2 points   

QUESTION 4

High-level programming languages include

C++ and Java.

C++ and JavaScript.

C++ and Visual Basic.

all of the above.

A and B, but not C.

2 points   

QUESTION 5

The statements in the body of a do-while loop are executed

until the test condition becomes true.

at least once.

exactly once.

forever until the user hits the break key.

only if the test condition is initially true.

2 points   

QUESTION 6

In a for statement, the ________ expression is executed only once.

initialization

update

repeat

validate

test

2 points   

QUESTION 7

The code int x = 0; while (s[x] != 0) { x++;}

computes the length of the C-string s into the variable x.

sets the variable x to the ASCII code of the last character in the C-string s.

sets the variable x to point to the last character in the C-string s.

sets the value of the variable x to 0.

None of the above

2 points   

QUESTION 8

The ________ statement causes other program statements to execute only under certain conditions.

logical

cin

if

cout

relational

2 points   

QUESTION 9

At the heart of a computer is its central processing unit. The CPU's job is to

produce some result.

fetch instructions.

carry out the operations commanded by the instructions.

do all of the above.

do none of the above.

2 points   

QUESTION 10

To access an array element, use the array name and the element's

data type.

value.

size declarator.

subscript.

name.

2 points   

QUESTION 11

We can measure the complexity of an algorithm that solves a computational problem by determining the number of ________ for an input of size n.

variables it uses

operations it performs

basic steps it requires

times it loops

output statements it has

2 points   

QUESTION 12

IDE stands for

initial development error.

internal direct execution.

integrated development environment.

internal data engine.

interactive data entry.

2 points   

QUESTION 13

A software package that includes a text editor, compiler, debugger, and assorted utilities for creating, testing, and running software is called

a software utility package (SUP).

an operating system.

a low-level programming language.

a high-level programming language.

none of the above.

2 points   

QUESTION 14

An array of 10 integers named myArray can have its contents displayed with which of the following statements?

cout << myArray[0-9];

cout << myArray;

cout << myArray[10];

cout << myArray[];

none of the above

2 points   

QUESTION 15

If you leave out the size declarator in an array declaration

the array size defaults to 100 elements.

you must furnish an initialization list.

the array cannot be created.

the array will contain no elements.

the value of each array element is set to a default value of 0.

2 points   

QUESTION 16

A(n) ________ is a set of instructions that tells the computer how to solve a problem.

linker

variable

operator

program

compiler

2 points   

QUESTION 17

The statement cout << setw(4) << num4 << " ";

outputs the value stored in num4 four times.

outputs the value of num4 rounded to 4 decimal places.

outputs the first 4 digits of the number stored in num4.

outputs "setw(4)" before the value in the variable num4.

does none of above.

2 points   

QUESTION 18

Which of the following statements is not valid C++ code?

float num1 = &ptr2;

int ptr = &num1;

int ptr = int *num1;

All of the above are valid.

All of the above are invalid.

2 points   

QUESTION 19

To use the sqrt() function, or other mathematical library functions, you must #include the ________ header file in your program.

algebra

mathlib

iostream

iomanip

cmath

2 points   

QUESTION 20

The ________ statement executes one block of statements if a test condition is true, and another block if the condition is false.

switch

if

trailing else

if/else

if/else if

2 points   

QUESTION 21

The following 4 lines of C++ code, use strings.
string firstName; // Define a string object
char lastName[7]; // Define a C-string
firstName = "Abraham"; // Assign a value to the string object
lastName = "Lincoln"; // Assign a value to the C-string

Which of the following statements is /are true?

The string object is assigned a value correctly, but the C-string is not.

The 2 string definitions are correct, but the 2 assignment statements are wrong.

The C-string is assigned a value correctly, but the string object is not.

The string object is defined incorrectly because no size is given for it.

All 4 lines of code are correct.

2 points   

QUESTION 22

Words with a special meaning that may be used only for their intended purpose are known as

keywords.

single purpose words..

programmer-defined identifiers.

syntax words.

none of the above.

2 points   

QUESTION 23

The ________ directive causes the contents of another file to be inserted into a program.

#getfile

#include

#insert

#library

none of the above

2 points   

QUESTION 24

What literal(s) appear in the following C++ statement?
int number = 4 + 8;

12

4

8

number

both B and C

2 points   

QUESTION 25

The ________ object causes data to be input from the keyboard.

dataIn

standard input

cin

cout

keyboard buffer

2 points   

QUESTION 26

An array can store a group of values, but the values must be

constants.

declared at the time the array is created.

all the same data type.

numeric, not characters or strings.

none of the above.

2 points   

QUESTION 27

The expression 5 % 2 evaluates to

1

2

2.5

5.2

10

2 points   

QUESTION 28

The linear search is adequate for searching through ________ arrays, but not through ________ ones.

char, string

any regular, vector

int, double

ascending, descending

small, large

2 points   

QUESTION 29

The ________ statement causes a loop to terminate early.

break

stop

continue

terminate

quit

2 points   

QUESTION 30

You may use the type pointer to a structure as the type of a

structure member.

function return type.

function parameter.

All of the above

None of the above

2 points   

QUESTION 31

A static local variable is one

whose value never changes.

with the same name as a global variable.

whose value is retained between function calls.

whose scope is limited to the function it is defined in.

that is reinitialized each time the function it is defined in is called.

2 points   

QUESTION 32

To locate a value that is in an ordered array of 50 items, linear search must examine at most ________ values.

1

6

25

50

51

2 points   

QUESTION 33

A sorting algorithm can be used to arrange a set of ________ in ________ order.

strings, ascending

numeric values, descending

strings, descending

numeric values, ascending

All of the above.

2 points   

QUESTION 34

The ________ coordinates the computer's operations by fetching the next instruction and using control signals to regulate the other major computer components.

control unit

arithmetic and logic unit (ALU)

traffic controller

instruction manager

operating system

2 points   

QUESTION 35

A pointer may be initialized with

the address of an existing object of the appropriate type.

the value of a floating-point variable.

the value of a floating-point constant.

All of the above

None of the above

2 points   

QUESTION 36

What will the following statement do if x equals 17 and answer = 20?
answer = x > 100 ? 0 : 1;

Assign 0 to answer.

Assign 1 to answer.

Assign 17 to answer.

Assign 0 to x.

Assign 1 to x.

2 points   

QUESTION 37

Assume that str1 and str2 are objects of the string class. The proper expression to use when comparing them for equality is

str1 == str2.

str1 = str2.

str1.compare(str2).

strcmp(str1, str2).

None of the above

2 points   

QUESTION 38

The default section of a switch statement performs a similar task as the ________ portion of an if/else if statement.

body

else if

trailing else

conditional test

break

2 points   

QUESTION 39

In C++ numeric global variables are ________ by default and numeric local variables are ________ by default.

not initialized, initialized to zero

initialized to zero, not initialized

initialized to zero, initialized to zero

not initialized, not initialized

None of the above

2 points   

QUESTION 40

An overloaded function is one

that call other functions.

that has too many parameters.

that attempts to do too much in a single function.

that has the same name as another function.

that does different things depending on who calls it.

2 points   

QUESTION 41

Which statements convert the string "10" to the integer value 10?

istringstream istr("10"); int x; istr >> x;

int x = stoi("10");

int x = str("10"):

ostringstream ostr("10"); int x; ostr >> x;

None of the above

2 points   

QUESTION 42

What value will be assigned to the variable number by the following statement?
int number = 7.8;

7.8

7

8

None of the above.

It's unpredictable. That's the problem.

2 points   

QUESTION 43

An operation that copies a value into a variable is called a(n) ________ operation.

cout

declaration

assignment

copy

equals

2 points   

QUESTION 44

A ________ is a program module whose purpose is to test other modules by calling them.

pseudocode routine

stub

driver

dummy program

main function

2 points   

QUESTION 45

Operator associativity is either left to right or

right to left.

inside to outside.

top to bottom.

front to back.

nothing else; it is always left to right.

2 points   

QUESTION 46

If a variable occupies more than one byte of memory, its address is

the average of the addresses used to store the variable.

the address of the last byte of storage allocated to it.

general delivery.

the address of the first byte of storage allocated to it.

None of the above

2 points   

QUESTION 47

Relational operators allow you to ________ numbers.

multiply

compare

verify

add

average

2 points   

QUESTION 48

Which of the following expressions will evaluate to 2.5?

static_cast<double>(5 / 2)

static_cast<double>(5) / 2

5 / static_cast<double>(2)

All three of the above

Both B and C, but not A

2 points   

QUESTION 49

Which of the following is/are valid C++ identifiers?

department_9

aVeryLongVariableName

last-name

All of the above are valid identifiers.

Both A and B are valid identifiers, but C is not.

2 points   

QUESTION 50

To use files in a C++ program you must include the ________ header file.

file

iostream

fstream

Both A and B.

Both B and C.

2 points   

Click Save and Submit to save and submit. Click Save All Answers to save all answers.

logic errors.

syntax errors.

compiler errors.

linker errors.

none of the above.

Explanation / Answer

Answers of Qu. 1 to 4:

Mistakes that allow a program to run, but cause it to produce erroneous results are called

a) Logic Errors

b) Syntax Error

c) Compiler Errors

d) Linker Errors

e) None

a) Logic errors

A logic error is a mistake in a program's source code that results in incorrect behaviour. It is a type of runtime error that may simply produce the wrong output or may cause a program to crash while running.

Syntax error is an error in the source code of a program. Since computer programs must follow strict syntax to compile correctly, any aspects of the code that do not conform to the syntax of the programming language will produce a syntax error.

Syntax errors are small grammatical mistakes, sometimes limited to a single character.

Linker error means that your code compiles correctly, but the required function or library is missing.

A ________ variable is declared outside all functions.

a) Global

b) Static

c) Constant

d) Local

e) Counter

A local variable is a variable that is declared inside a function. It can only be used in the function where it is declared.

A global variable is a variable that is declared outside functions. It can be used in all functions.

a) Operator

b) Variable

c) Constant

d) New data type

e) counter

You may define a(n) ________ in the initialization expression of a for loop.

Answer: b) Variable

As the scope of variable is limited to loop only so you can initialized it in the initialization expression of a for loop.

High-level programming languages include

a) C++ and Java

b) C++ and JavaScript

c) C++ and Visual Basic

d) All of the above

e) A and B, but not C

Answer:

d) All of the Above i.e. C++, Java, JavaScript, Visual Basic.

High level programming languages are machine-independent programming language.