CSC 242 study cards

Ace your homework & exams now with Quizwiz!

Which of the following expression is equivalent to (x > 1).

!(x <= 1)

The not equal comparison operator is __________.

!=

Suppose two strings are declared as string s1 = "ABC" and string s2 = "DEFG". Which of the following is an incorrect expression?

"ABC" + "DEFG"

A preprocessor directive begins with a symbol __________.

#

Which of the following is the correct expression of character a?

'a'

Which of the following is the correct expression that evaluates to true if the number x is between 1 and 100 or the number is negative?

((x < 100) && (x > 1)) || (x < 0)

Which of the following is not a valid boolean expression.

(x =< 5) & (x>=5)

What is y after the following statement is executed? x = 0; y = (x > 0) ? 10 : -10;

-10

-15 % 4 is _____

-3

_________ are secondary storage

-CD -floppy disk -hard disk

C++ is ____________.

-a high-level programming language -an object-oriented language

Which of the following are correct names for variables according to the naming conventions adopted by this book?

-radius -findArea

The extension name of a C++ source code file is

.cpp

Suppose x is 1. What is x after x -= 1?

0

5 % 2 is _____

1

What is 1 % 2?

1

What is the output of the following code? inline void print(int i) { cout << i << endl; } int main() { print(1); return 0; }

1

pow(4.0, 1 / 2) returns __________.

1

What is the output of the following code: int list[] = {1, 2, 3, 4, 5, 6}; for (int i = 1; i < 6; i++) list[i] = list[i - 1]; for (int i = 0; i < 6; i++) cout << list[i] << " ";

1 1 1 1 1 1

How many times will the following code print "Welcome to C++"? int count = 0; do { cout << "Welcome to C++"; } while (++count < 10);

10

How many times will the following code print "Welcome to C++"? int count = 0; while (count++ < 10) { cout << "Welcome to C++"; }

10

What is the value in count after the following loop is executed? int count = 0; do { cout << "Welcome to C++"; } while (count++ < 9); cout << count;

10

How many times will the following code print "Welcome to C++"? int count = 0; do { cout << "Welcome to C++"; } while (count++ < 10);

11

What is result of 45 / 4?

11

What is sum after the following loop terminates? int sum = 0; int item = 0; do { item++; sum += item; if (sum >= 4) continue; } while (item < 5);

15

Suppose void nPrint(char ch, int n) { while (n > 0) { cout << ch; n--; } } What is k after invoking nPrint('a', k)? int k = 2; nPrint('a', k);

2

What is the output of the following code? int number = 8; if (number < 8) cout << 1 << endl; else cout << 2 << endl;

2

sqrt(4) returns _______.

2

If you declare an array double list[] = {3.4, 2.0, 3.5, 5.5}, the highest index in array list is __________.

3

The following program displays __________. #include <iostream> using namespace std; int main() { cout << 1 + 2 << endl; return 0; }

3

What will be displayed when the following code is executed? int number = 6; while (number >= 0) { number -= 3; cout << number << " "; }

3 0 -3

Suppose a string is declared as string s = "abcd". What is s.length()?

4

What is sum after the following loop terminates? int sum = 0; int item = 0; do { item++; sum += item; if (sum > 4) break; } while (item < 5);

6

ceil(5.5) evaluates to _____.

6.0

One byte has ________ bits

8

___________ is called a stream insertion operator for sending output to the console.

<<

The assignment operator in C++ is __________.

=

Which of the following loops prints "Welcome to C++" 10 times?

A: for (int count = 1; count <= 10; count++) { cout << "Welcome to C++" << endl; } B: for (int count = 0; count < 10; count++) { cout << "Welcome to C++" << endl; }

Suppose you define a C++ as follows: int main() { } The source code should be stored in a file named

Any name with extension .cpp

What is the output of the following code? char ch = 'F'; if (ch >= 'A' && ch <= 'Z') cout << ch << endl;

F

If you read a string input: PROGRAMMING IS FUN using the following code, what will be is s? cout << "Enter a string:"; string s; cin >> s;

PROGRAMMING

____________ are instructions to the computer

Programs & Software

Analyze the following two code fragments. (i) int x = 5; if (0 < x) && (x < 100) cout << "x is between 1 and 100"; (ii) int x = 5; if (0 < x && x < 100) cout << "x is between 1 and 100";

The first fragment has a syntax error.

Analyze the following code: #include <iostream> using namespace std; int main() { int x[5]; int i; for (i = 0; i < 5; i++){ x[i] = i; cout << x[i] << " "; } return 0; }

The program displays 0 1 2 3 4.

Analyze the following code: bool even = false; if (even = true) { cout << "It is even!"; }

The program runs and displays It is even!.

Analyze the following code: #include <iostream> using namespace std; int main() { int n = 10000 * 10000 * 10000; cout << "n is " << n << endl; return 0; }

The result of 10000 * 10000 * 10000 is too large to be stored in an int variable n. This causes an overflow and the program continues to execute because C++ does not report errors on overflow.

Analyze the following code. int x = 0; if (x > 0); { cout << "x"; }

The symbol x is always printed

What is 1.0 + 1.0 + 1.0 + 1.0 + 1.0 == 5.0?

There is no guarantee that 1.0 + 1.0 + 1.0 + 1.0 + 1.0 == 5.0 is true.

What is 1.0 + 1.0 + 1.0 == 3.0?

There is no guarantee that 1.0 + 1.0 + 1.0 == 3.0 is true.

The keyword in C++ are all in lowercase.

True

True or False: C++ is an object-oriented programming language.

True

True or false: this assignment statement is correct i = 1 = j = 1 = k = 1;

True

_____ are valid identifiers

_RE4

Suppose a string is declared as string s = "abcde". What is s[0]?

a

A variable that is declared inside a function is called ________ variable.

a local

Each time a function is invoked, the system stores parameters and local variables in an area of memory, known as _______, which stores elements in last-in first-out fashion.

a stack

What is the representation of the third element in an array called a?

a[2]

The following code displays ________. cout << "a" << setw(6) << left << "abc";

aabc

What is the exact output of the following code? double area = 3.5; cout << "area"; cout << area;

area3.5

Suppose a string is declared as string s = "abcde". What is s.at(2)?

c

You should fill in the blank in the following code with. #include <iostream> using namespace std; ________ getGrade(double score) { if (score >= 90.0) return 'A'; else if (score >= 80.0) return 'B'; else if (score >= 70.0) return 'C'; else if (score >= 60.0) return 'D'; else return 'F'; } int main() { cout << "Enter a score: "; double score; cin >> score; cout << "The grade is "; cout << getGrade(score) << endl; return 0; }

char

Which of the following assignment statements is correct to assign character 5 to c?

char c = '5';

Which of the following assignment statements is correct?

char c = 100;

To improve readability and maintainability, you should declare _________ instead of using literal values such as 3.14159.

constants

What is the correct way to display Welcome to C++ on the console?

cout << "Welcome to C++";

Which of the following statement prints smith\exam1\test.txt?

cout << "smith\\exam1\\test.txt";

The signature of a function consists of the function name, parameter list and return type.

false

The signature of a function consists of ____________.

function name and parameter list

What will be the output of the following code? #include <iostream> using namespace std; int j = 1; int main() { int i = 2; cout << "i is " << i << " j is " << j << endl; return 0; }

i is 2 j is 1

What is the output after the following loop terminates? int number = 25; int i; bool isPrime = true; for (i = 2; i < number && isPrime; i++) { if (number % i == 0) { isPrime = false; } } cout << "i is " << i << " isPrime is " << isPrime << endl;

i is 6 isPrime is 0

Suppose cond1 and cond2 are two Boolean expressions. When will this if condition be true? if (cond1 && cond2) ...

in case cond1 is true and cond2 is true

To declare an int variable x with initial value 200, you write

int x = 200;

The following code displays ___________. double temperature = 50; if (temperature >= 100) cout << "too hot" << endl; else if (temperature <= 40) cout << "too cold" << endl; else cout << "just right" << endl;

just right

Computer can execute the code in ____________.

machine language

The following code displays ______________. #include <iostream> using namespace std; void maxValue(int value1, int value2, int max) { if (value1 > value2) max = value1; else max = value2; } int main() { int max = 0; maxValue(1, 2, max); cout << "max is " << max << endl; return 0; }

max is 0

One megabytes are roughly ____________.

one million bytes

Arguments to functions always appear within __________.

parentheses

The __________ function returns a raised to the power of b.

pow(a, b)

What the output of the following code: for ( ; ; ) cout << "Welcome to C++" << endl;

prints out Welcome to C++ forever

Which of the following is not a function in C++?

random

To check whether a string s starts with a capitial letter, use the Boolean expression _________.

s[0] >= 'A' && s[0] <= 'Z'

The compiler checks _______.

syntax errors

To return an uppercase letter from char variable ch, use

toupper(ch)

A function can be declared with no parameters

true

A statement block begins with an open brace { and ends with a closing brace.

true

In a for statement, if the continuation condition is blank, the condition is assumed to be ______.

true

True or false: A C++ program block starts with an open brace ({) and ends with a closing brace (}).

true

You can always convert a for loop to a while loop.

true

You can always convert an if statement to a switch statement.

true

You can always write a program without using break or continue in a loop.

true

You can assign a character value to an int, or an int to char.

true

You may have a return statement in a void function

true

Suppose your function does not return any value, which of the following keywords can be used as a return type?

void

Assume x = 4, Which of the following is true?

x != 5

Assume x is 0. What is the output of the following statement? if (x > 0) cout << "x is greater than 0" << endl; else if (x < 0) cout << "x is less than 0" << endl; else cout << "x equals 0" << endl;

x equals 0

Assume x is 0. What is the output of the following statement? if (x > 0) printf("x is greater than 0"); else if (x < 0) printf("x is less than 0"); else printf("x equals 0");

x equals 0

What is the output of the following code? #include <iostream> using namespace std; void f(double &p) { p += 2; } int main() { double x = 1; double y = 1; f(x); f(y); cout << "x is " << x; cout << " y is " << y << endl; return 0; }

x is 3 y is 3

Analyze the following code. #include <iostream> using namespace std; int main() { int x[3]; cout << "x[0] is " << x[0]; return 0; }

x[0] has an arbitrary value.

Analyze the following code. int x = 0; int y = ((x < 100) & (x > 0)) ? 1: -1;

y becomes -1 after the code is executed.

Will the following program terminate? int balance = 10; while (true) { if (balance < 9) break; balance = balance - 9; }

yes


Related study sets

HyperText Transfer Protocol (HTTP)

View Set

SOCL 3371 Final Exam - Valasik - Fall 2014

View Set

PREPU - Chapter 31: Assessment and Management of Patients With Hypertension

View Set

BIOS 1610 EXAM 3, homework assignment quizzes

View Set

#8 - questions - Managing Cisco Devices

View Set

A&P: Ch 13 Cardiovascular System P1

View Set

Chapters 11, 12, 13, 14 Reading Questions

View Set