COSC 1436 Midterm

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

A floating-point number type defaults to being signed. True or False

True

A for loop is a pre-test loop. True or False

True

In C++ 11 and later versions you can pass a string object as argument to a file stream object's open member function. True or False

True

In C++ the following relationship regarding type size is always true for all platforms. sizeof(short) <= sizeof(int) <= sizeof(long) True or False

True

Literals are data items whose values do not change while the program is running. True or False

True

Relational operators produce boolean results. True or False

True

String objects have a member function named c_str that returns the contents of the object formatted as a null-terminated C-string. True or False

True

Syntax is the rules of grammar that must be followed when writing a program. True or False

True

System software is programs that manage the computer hardware and the programs that run on them. True or False

True

The # symbol is used to begin a preprocessor directive. True or False

True

The CPU has 2 main parts: The Control Unit Arithmetic Logic Unit True or False

True

The first character of an identifier must be an alphabetic character or an underscore ( _ ). True or False

True

What does the following code display? int i=0, j=0, k=0; k = (i && j++); cout << i << ", "<< j << ", "<< k; 0, 0, 0 0, 1, 0 0, 1, 1 1, 1, 1

0, 0, 0

The following statement displays: cout << 1 % 4; 0, 1, 4, 0.25

1

What will the following program segment display? int funny = 7, serious = 15; funny = serious % 2; if (funny != 1) { funny = serious = 0; } else if (funny == 2) { funny = serious = 10; } else { funny = serious = 1; } cout << funny << " " << serious << endl; 7 15 0 0 10 10 1 1

1 1

What does the following code segment display? int n = 1; while (n <= 5) cout << n << ' '; n++; 1 2 3 4 5 1 1 1 1... and on forever 2 3 4 5 6 1 2 3 4

1 1 1 1... and on forever

The following code segment displays 11 int num=4; int total=0; switch (num) { case 1: case 2: total+= 4; case 4: total += 1; case 8: total+= 6; default: total+= 4; } cout << total<< endl; True or False

True

The following code segment displays Hi : int x=2, y=1; if (x < y) ; cou<t<"Hi"; True or False

True

The following code segment displays: true int x=-1; if (x) cout<<"true"; else cout<<"false"; True or False

True

The following definitions in the same program is syntactically correct. int MyVar; int myVar; True or False

True

The following two relational statements will evaluate to the same result ? bool a, b, c, d; d = a || b && c; d = a || ( b && c ); True or False

True

The numeric data types in C++ can be classified into two general categories: integer and floating point. True or False

True

Unsigned integers always treat the sign bit as a magnitude part of the number. True or False

True

Using your knowledge of DeMorgan's Rule, will the following statements yield the same result? bool a, b, c; ( a && b || !c && !a); ! (!a || !b && c || a); True or False

True

Volatile memory is erased when the computer is turned off. True or False

True

You must have a definition for every variable you intend to use in a program. True or False

True

A Byte is made up of 16 consecutive bits. True or False

False

A While loop is a post test loop. True or False

False

A while loop cannot be used as a fixed iteration loop. True or False

False

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

False

Directives must end with a semicolon. True or False

False

In C++ the size of a type is always the same on different platforms. True or False

False

In a C++ program, two slash marks ( // ) indicates the start of a code block. True or False

False

Some variable do not need a type when defined. True or False

False

The constant 0x75A is base 8. True or False

False

The do-while loop is a pre-test conditional loop. True or False

False

The following code segment displays ada lovelace . bool george=(7 > 10); if (george) cout<<"ada "; else cout<<"lovelace"; True or False

False

The _________ causes a program to wait until information is typed at the keyboard and the Enter key is pressed. Output stream cin object cout object Preprocessor

cin object

Relational operators allow you to ________ numbers. add multiply compare average

compare

This statement may be used to cause a loop's current iteration to go to and then execute the loop test condition expression. break terminate exit continue

continue

A file ________ is a small holding section of memory that file-bound information is first written to. name number buffer segment

buffer

This loop is a good choice when you know how many times you want the loop to iterate (Fixed iteration) in advance of entering the loop. while do-while for infinite loop

for

To allow file access in a program, you must #include this header file. cfile iostream fstream iomanip

fstream

To read data from a file, you define an object of this data type. inputFile ifstream fstream ofstream

ifstream

In a for statement, this expression is executed only once. test incrementation initialization validation

initialization

If you place a semicolon after the test expression in a while loop, it is assumed to be a(n) pre-test loop post-test loop null statement infinite loop

null statement

To write data to a file, you define an object of this data type. ofstream ifstream fstream outputFile

ofstream

A file must be ________ before data can be written to or read from it. closed open buffered initialized

open

This operator increments the value of its operand, then uses the value in context. prefix increment postfix increment prefix decrement postfix

prefix increment

What does the following code display? for (int r = 0, e = 4; r < e; r++) { for (int c = 0; c < r; c++) cout << "$"; cout << endl; } $$$ $$ $ $$$ $$ $ $ $$ $$$ $ $$ $$$

$ $$ $$$

These can be used to override the rules of operator precedence in a mathematical expression.. [Brackets] (Parentheses) {Braces} None of the above

(Parentheses)

When this operator is used with string operands it concatenates them, or joins them together. & * % +

+

After execution of the following code, what will be displayed if the value 0 is entered at the keyboard at run time? cin >> input_value; if (input_value > 5) input_value = input_value + 5; else if (input_value > 2) input_value = input_value + 10; else input_value = input_value + 15; cout<<input_value; 15, 10, 25, 0

15

The statements in the body of a while loop may never be executed, whereas the statements in the body of a do-while loop will be executed: at least once at least twice as many times as the user wishes never

at least once

This manipulator is used to establish a field width for the value immediately following it. filedwidth() setField() setw() iomanip()

setw()

This may be used to write information to a file. cout object pen object output object stream insertion operator

stream insertion operator

This operator represents the logical AND. ++ || @@ &&

&&

These are operators that add and subtract one from their operands. plus and minus ++ and -- binary and unary conditional and relational

++ and --

What will the following loop display? int x = 0; while (x < 5) { cout << x << endl; x++; } 0 1 2 3 4 5 0 1 2 3 4 1 2 3 4 The loop will display numbers starting at 0, and never terminate by loop control.

0 1 2 3 4

What will the following program display? #include <iostream> using namespace std; int main() { int a = 0, b = 2, x = 4, y = 0; cout << (a == b) << " "; cout << (a != b) << " "; cout << (b <= x) << " "; cout << (y > a) << endl; return 0; } 0 1 1 0 0 0 1 0 1 1 0 1 1 0 0 1

0 1 1 0

What does the following code display ? int i=0; do { i++; if (i % 2) continue; if (i == 4) break; cout << i << " "; } while (true); 1, 2, 3, 4, 5, 6

2

How many times will the following loop display "Hello"? for (int i = 20; i > 0; i--) cout << "Hello!" << endl; 20 19 21 An infinite loop

20

What will the following code display? int x = 0; for (int count = 0; count < 3; count++) x += count; cout << x << endl; 0 1 2 0 6 3

3

In the following C++ statement, what will be executed first according to the order of precedence? result = 6 - 3 * 2 + 7 - 10 / 2 ; 6 - 3 3 * 2 2 + 7 7 - 10

3 * 2

What is the value of number after the following statements execute? int number = 10; number += 5; number -= 2; number *= 3; 39 3 32 undetermined

39

What is the value of average after the following code executes? double average; average = 1.0 + 2.0 + 3.0 / 3.0; 2.0 6.0 1.5 4.0

4.0

The ______ operator always follows the cin object, and the ______ operator follows the cout object. binary, unary ++, -- >>, << <<, >>

>>, <<

The following C++ expression produces a float result. 13 / 5 True or False

False

The following will compile: char c = "a"; True or False

False

This operator = is used in C++ to represent logical equality. True or False

False

The following statement: int x,y; if (x < y); The code will not compile. The compiler will interpret the semicolon as a null statement. The if statement will always evaluate to false. The if statement will always evaluate to true.

The compiler will interpret the semicolon as a null statement.

After the first character you may use alphabetic characters, numbers, or underscore characters. True or False

True

An algorithm is a set of well-defined steps for performing a task or solving a problem. True or False

True

Classic C-Strings end with the null terminator, the '\0" character. True or False

True

For bool data types, false is represented by 0 and true is represented by any non-zero number. True or False

True

The following code segment displays: This is true! Th-Thats all folks! int x = 5; if (x = 2) cout << "This is true! " ; else cout << "This is false! " ; cout << "Tha-Thats all folks!"; True or False

True

This operator || is the logical OR operator. True or False

True

When a relational expression is false, it produces the value of 0. True or False

True

The following code segment displays true: int i=0; if (i = 1) { cout<<"true"; } else { cout<<"false"; } True or False

True (= sets 1 equal to i, not check for equality)

What will the following segment of code display assuming the user enters a grade of 90 from the keyboard? unsigned int test_score; cout << "Enter a test score: "; cin >> test_score; if (test_score < 60); cout << "You failed the test! "; if (test_score > 60) cout << "You passed the test! "; else cout << "You need to study for the next test! "; You failed the test! You passed the test! You failed the test! You passed the test! You failed the test! You did poorly on the test!

You failed the test! You passed the test!

Assuming dataFile is a file stream object, the statement: dataFile.close(); is illegal in C++ closes a file rests a file pointer to the start of the file is platform dependent

closes a file

What value is displayed by the following code: int i = 0; i = i / i++; cout << i; 0 1 undefined depends on the compiler

depends on the compiler

If a loop is to execute exactly 20 times, which loop would be the best to use? do-while for while infinite

for

Assuming outFile is a file stream object and number is a variable, which statement writes the contents of number to the file associated with outFile? write(outFile, number); outFile >> number; outFile << number; number >> outFile;

outFile << number;

A for statement contains three expressions: initialization, test, and validation reversal update incrementation

update

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

x *= 2;


Ensembles d'études connexes

psychology chapter 5, 6, 7, 9 questions

View Set

Business Ethics Final Dash Spring 2021 ORU

View Set

Econ Final Study Guide (from midterms)

View Set

OSHA 30 Module 9 Materials Handling and Storage

View Set

Chapter 6: Deep Learning and Cognitive Computing

View Set

Chapter 10 Conception and Fetal Development

View Set

CH. 12 Health insurance providers

View Set