Comp. Programming: Ch. 1-3

¡Supera tus tareas y exámenes ahora con Quizwiz!

The mileage of the first car is calculated correctly, but the mileage of the second car is incorrect due to a logic error

The following code snippet is written to calculate the miles per gallon of two cars and print out both values. Based on the given code snippet, identify the correct statement: a) The output is correct, and there are no errors. b) The mileage of the first car is calculated correctly, but the mileage of the second car is incorrect due to a logic error c) The mileage of the second car is calculated correctly, but the mileage of the first car is incorrect due to a logic error d) The mileage of both cars is incorrect due to a logical error

It sets the variable x to zero

What is the meaning of x = 0; in C++? a) It checks whether x equals 0 b) It sets the variable x to zero c) It defines a variable named x and initializes it with 0 d) It is a syntax error since x is not always 0

d

What is the output of the following code snippet? int var1 = 10; int var2 = 2; int var3 = 20; var3 = var3 / (var % var2); cout << var3 << endl; a) 0 b) 4 c) 20 d) There will be no output due to a run-time error

c) The statement results in an error because the + operation cannot be performed on string literals

What is the result of the following statement/ string s = "New" + " " + "Jersey"? a) The string s has the following value: "New Jersey" b) The statement results in an error because the + operator can be used only with numbers c) The statement results in an error because the + operation cannot be performed on string literals d) The string s has the following value: "NewJersey"

used an undeclared variable

What is wrong with the following code snippet? int main ( ) { int size = 42; cost = 9.99; cout << "size = " << size << "cost = " << cost << endl; return 0; }

price is assigned decimal value

What is wrong with the following code snippet? int price; price = 9.42

A syntax error

What type of error can you identify in the following code snippet? int a = 10; int b = 20; int c = a + b; a) A logical error b) A syntax error c) A run-time error d) No errors; the code snippet is completely accurate

III, IV, & V

Which of the following C++ variable names are valid: I. 1st_instance II. basic_in_$ III. _emp_name_ IV. address_line1 V. DISCOUNT

a = 20

Which of the following is an assignment statement? a) int a = 20 b) a = 20 c) assign a = 20 d) assign 20 to a

d

Which of the following options is valid with reference to the code snippet? a) The value inside the variable r will be 0.326 b) The value inside the variable r will be 5.036 c) Variable r has to be defined as an integer as the % operator always return an integer d) The assignment statement for variable r is wrong, as the % operator expects integer values as operands

All four statements are valid

Which of the following statements are valid about strings? a) Only II and III are valid. b) Only III and IV are valid. c) Only I and III are valid. d) All four statements are valid.

Every executable C++ program has a main function

Which of the following statements are valid with respect to the main function in C++? a) The opening and closing parentheses after the function name main are optional b) A semicolon is required after the declaration "int main ( )." c) A semicolon is required after the closing curly braces in the main function d) Every executable C++ program has a main function

fabs(x);

Which of the following statements gives the absolute value of the floating-point number x = -25.50 in C++? a) abs (x); b) fabs (x); c) x.abs(); d)x.fabs();

+

Which operator is used to concatenate two or more strings? a) + b) % c) & d) ^

Software

a collection of programs that a computer executes

Compile-time error (aka syntax error)

a violation of the programming language rules that is detected by the compiler

run-time error

an error that causes a program to take an action that the programmer did not intend

Secondary Storage

provides storage that persists without electricity

Logic errors

run-time errors caused by logical flaws in the program

Embedded systems

small computers that are programmed to control automobile engines and cell phones

name is a string variable

Consider the following C++ statement: string name = "Harry" Which of the following is true? a) name is a string literal b) name is a string variable c)"Harry" is a string variable d) The statement contains a syntax error

Joel, Good morning

Assuming that the user inputs "Joel" at the prompt, what is the output of the following code snippet? a) The code snippet does not compile because the += operator cannot be used in this context b) Joel, Good morning c) , Good morning d) Joel


Conjuntos de estudio relacionados

Sports Management Exam 1 Study Guide

View Set

Physical Science Chapter 6 and 7

View Set

PEDS- Chapter 4 - "the point review"

View Set

Osteoarthritis vs. Rheumatoid Arthritis

View Set

ATI- PN Adult Medical Surgical Practice 2017 A

View Set

Abeka 5th Grade History Chapter 7

View Set

Биохимический анализ крови/ Белковый обмен

View Set

Modules, Packages, and Python Installation Package

View Set

Urine and Urine Sediment Images (identification) questions are reversed

View Set

Psychology Chapter 12 Study Guide

View Set