MIDTERM CS181

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

What is the output of the following code segment? n =1; while ( n<=5) count << n << ' '; n++; 1 2 3 4 5 6 1 2 3 4 5 1 2 3 4 2 3 4 5 1 1...

(1 1...)

What will the following code display? int number = 6; int x = 0; x =--number; count << x << endl;

(5)

What will the following code display? int number = 6; ++number; count << number << endl; 6,5,7,0

(7)

What will the following code display? int number = 6; cout << ++number << endl; 6,5,7,0

(7)

What will the following code display? int number = 6; number++; count << number << endl; 6,5,7,0

(7)

What is the value of donuts after the following statement executes? int donuts = 10 ; if ( donuts = 1) donuts = 0; else donuts +=2; ( end ch 4)

0

what is the following code display? int numbers [4] = ( 99, 87); count << numbers [3] << endl;

0

What is the value of x after the following code executes? int x; x= 3/static_cast< int>( 4.5 +6.4)

0 ( 3/.11 = 0 bc int)

What is assigned to the variable result given the statement below with the following assumptions: x = 10, y = 7, and x, result, and y are all int variables. result = x >= y;

1

What will the following code display? #include < iostream> using namespace std; int main { int x = 2 count << getVaue(x) << endl; } int getValue( int num) { return num + 5; 7

7

What will the following code display? int numbers[] = { 99,87,65,55,101} for ( int i =1; i < 4; i++) count << numbers[i] << " ";

87 66 55

Arithmetic operators that share the same precedence have right to left associativity.

FALSE

Machine language is an example of a high-level language.

FALSE

A local variable and a global variable may not have the same name within a program. T or F ( ch 6 beginning )

False

If you want to know the length of the string that is stored in a string object, you can call the object's size member function. ( ch3 beg.)

False

The following statement will output $5.00 to the screen: cout << setprecision(5) << dollars << endl;

False

The scope of a variable declared in a for loop's initialization expression always extends beyond the body of the loop. True or False ( ch 5 beginning )

False

The value of result in the following expression will be 0 if x has the value of 12. result = x > 100 ? 0 : 1;

False

What will the following code display? cout << "Four\n" << "score\n"; cout << "and" << "\nseven"; cout << "\nyears" << " ago" << endl;

Four score and seven years ago

What will the following code display? cout << "Monday"; cout << "Tuesday"; cout << "Wednesday";

MondayTuesdayWednesday

When C++ is working with an operator, it strives to convert the operands(#s) to the same type.

TRUE

Control Unit

The _control unit_______ decodes an instruction and generates an electronic signal.

If the expression on the left side of the following is false, the expression on the right side will not be checked. (a>=b) &&(c==d)

True

The two parts of the CPU are

the Control Unit and the Arithmetic and Logic Unit

After the following code executes, what is the value of my_value if the user enters 0? if (x < y)

the compiler will interpret the semicolon as a null statement

Given the following declaration, where is the value 77 stored in the scores array? int scores[] = {83, 62, 77, 97, 86}

scores[2] ( scores array ( 0,1,2,3,4)

Character constants in C++ are always enclosed in

single quotation marks ( ' ' )

When the final value of an expression is assigned to a variable, it will be converted to

the data type of the variable

In the following statement, the characters Hello! are a(n) cout << "Hello!";

string literal

The range-based for loop in C++11 is designed to work with a built-in variable known as

the range variable

An array can store a group of values, but the values must be ( ch 7 begging)

the same data type

The purpose of a memory address is:

to identify the location of a byte in memory

As a rule of style, when writing an if statement you should indent the conditionally-executed statements.

true

Which statement correctly defines a vector object for holding integers?

vector< int> v;

Whereas < is called a relational operator, x < y is called a(n)

relational expression

This statement causes a function to end. (end, terminate, return, release, none)

return

What will be displayed after the following statements execute? int funny = 7; serious = 15; funny = serious = 15 ( if = serious % 2); if ( funny !=1) { funny = 0 serosu = 10 } else if ( funny == 2) { funny = 10; serious = 10; } else { funny = 1; serious = 1; } count << funny << " " << serious << endl; ( 39)

1 1

void calc ( int a, int& b) { int c; c = a +2; a =a + 3; b = c+ a; } what is the output of the following code segment that invokes calc(); int x =1; int y =2; int z =3; calc ( x,y): count << x << " " << y << " " << z << endl; 1 2 3 1 6 3 3 6 3 1 14 9 2 3 4 5

1 6 3

What is the value of x after the following code executes? int x = 0; int y = 5; int z = 4; x = x + y + z * 2;

13

After the following code executes, what is the value of my_value if the user enters 0? cin << my value; if ( my _ value > 5 ) my value = my value + 5 else if ( my_value > 2) my value = my value +10; else my_value = my_value + 15; ( ch 4)

15

Which of the following is NOT a valid C++ identifier? April2018 employee_number _1user 1user theLittleBrownFoxWhoRanAway

1user 9 ( variable type)

What will the following code display? #include < ionstream> using namespace std; void doSomething( int &); int main( ) { int x= 2; count << x<< endl; return 0; } void do something ( int & num) { num = 0; count << num << endl;

2 0 0

How many times will the following loop display "Hello world!"? for( int =0; i < 20; i++) count << " Hello World! " << endl; 20,19,21,an infinite number of times ( ch 5 ending )

20 ( okay the rule does apply if post fix you don't show how it's adding b/c of x = 0)

What will the following code display? int x = 23, y = 34, z = 45; cout << x << y << z << endl;

233445

What will the following code display? #include <iostream> using namespace std; void showdub(int) int main() { int x = 2 showDub(x); cout << x << endl; return 0; } void showdub(int num) { cout << ( num * 2) << endl; 2 2 4 2 2 4 4 4

4 2

What is the last legal subscript that can be used with the following array? int values[5];

4 ( subcripts 0,1,2,3,4)

In the following statement, which operator is used first? while ( x ++ < 10) ++ < neither; the expression is invalid cannot tell without the rest of the code

< (// operator is like < =)

The ________ operator always follows the cin object, and the ________ operator follows the cout object.

>>, <<

what is the following code display? const int SIZE = 5; double x[SIZE] for ( int i = 2; i <= SIZE; 1++) { x[i] = 0.0; }

An error will occur when the code runs. i'm guessing because of i

Which of the following best describes an operator? (An operator is a rule that must be followed when constructing a program. An operator allows you to perform operations on one or more pieces of data. An operator marks the beginning or end of a statement or is used to separate items in a list. An operator is a word that has a special meaning. An operator is a symbolic name that refers to a variable.)

An operator allows you to perform operations on one or more pieces of data.

Which of the following best describes an operator? An operator is a rule that must be followed when constructing a program. An operator allows you to perform operations on one or more pieces of data. An operator marks the beginning or end of a statement or is used to separate items in a list. An operator is a word that has a special meaning. An operator is a symbolic name that refers to a variable.

An operator allows you to perform operations on one or more pieces of data.

What is the output of the following code segment if the user enters 90 for the score? count << Enter your test score: " cin >> test_ score; if ( test_ score < 60) count << " You failed the test." << endl; if ( test_ score > 60) count << " You passed the test." else count " You need to study harder next time> " << endl;

You passed the test.

An Integrated Development Environment (IDE) typically consists of (TECD)

a text editor, a compiler, & a debugger

Which data type typically requires only one byte of storage?

char

The first step in writing a program is to (type the code clearly define what the program is to do visualize logical errors None of these ( ch 1 ending) )

clearly define what the program is to do

For every opening brace ({) in a C++ program, there must be a ( ch 2 beg.)

closing brace

Which step uncovers any syntax errors in your program?

compiling

Which line in the following program contains the header for the showDub function? void computerValue ( int value) ( ch 6 ending)

computeValue( 10);

Given the following header for a function named computeValue, which of the following is a valid call to the function? void computeValue(int value) (computeValue(10) computeValue(10); void computeValue(10); void computeValue(int x);)

computeValue(10); ( void evenOrOdd(int); //prototype void evenOrOdd(int num) //header = function evenOrOdd(val); //call )

Which of the following defines a double-precision floating-point variable named payCheck? ( ch 2 ending)

double payCheck;

A ________ variable is declared outside all functions. local, global, floating-point, counter, none

global

An array with no elements is

illegal in C++

In a for statement, this expression is executed only once: (the test null initialization validation none)

initialization

Arrays must be ________ at the time they are ________.

initialized, declared

Which line in the following program will cause a compiler error? #include <ionstream> using namespace std; int main() { const int MY_VAL =77; MY _ VAl = 99 cout << MY_VAL << endl; }

line 7

Data items whose values do NOT change while the program is running are

literals

Which statement is equivalent to the following? number = number * 2;

number *= 2;

When the increment operator precedes its operand, as ++num, the expression is in ________ mode. postfix,prefx,preminary, or none

prefix

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

program

When used as parameters, these types of variables allow a function to access the parameter's original argument: (reference floating-point counter undeclared None)

reference


Kaugnay na mga set ng pag-aaral

Combo with Anatomy Chapter 16 Spinal Cord and Spinal Nerves and 2 others

View Set

Chapter 1 American Government section 3

View Set

LL 03 - 1 朋友 单词 vocabulary

View Set

Ch 18: Kidney Clinical Assessment and Diagnostic Procedures jk

View Set

Visual Basic Mid Term study guide

View Set

Mental Health ATI Edition 11 Reveiw

View Set