Computer Science - Quizzes

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

Which of the following loops produces the output 1234123121 (1) for (int i = 5; i > 0; i--) { for (int j = 1; j < i; j++) cout << j << " "; cout << endl; } (2) for (int i = 1; i < 5; i++) { for (int j = 1; j < i; j++) cout << j << " "; cout << endl; } (3) int i = 0; while (i < 5) { for (int j = 1; j < i; j++) cout << j << " "; cout << endl; i++; } (4) int i =5; while (i > 0) { for (int j = 1; j < i; j++) cout << j << " "; cout << endl; i--; }f

1 and 4

The function time(0) returns____________.

the current time in seconds since midnight, January 1, 1970 GMT (the Unix time)

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

true

The keywords in C++ are all in lowercase. T/F

true

To run a C++ program, you have to first compile it. T/F

true

You can always assign a value of int type to a variable of long type without loss of information. T/F

true

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 beings with a symbol________.

#

Suppose you define a function in a header file named f.h. To use it in your program use_________.

#include "f.h"

Suppose you define a function in a header file named f.h. To use it in your program, use__________.

#include "f.h"

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

'4'

You can assign the value in ___________ to an int variable.

- 'x' - true - 93 - 98.3

Which of the following expression will yield 0.5?

- 1.0/2 - (double) 1/2 - 1/2.0

___________ are secondary storage.

- CD - hard disk - floppy disk

Programming style is important, because ______________.

- a good programming style makes a program more readable - a good programming style helps reduce programming errors

Which of the following is correct to display "Programming is fun" on the console?

- cout << "Programming is fun"; - cout << "Programming is fun" << endl;

Which of the following assignment statements are incorrect?

- i = 1 = j = 1 = k = 1; - i == j == k == 1;

Analyze the following statements.

- incline functions are appropriate for very short functions - incline functions execute faster than regular functions - incline functions use more memory than regular functions - incline functions and regular functions can perform the same function. The difference is in performance and memory use

You can cast a double value to _______.

- int - unsigned int - long - float - short

_________ are instructions to the computer.

- software - programs

25 % 1 is ________.

0

5 % 1 is ________.

0

What is 1 % 2?

1

What is sin(PI/2) for a constant PI = 3.14159?

1

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

1

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

10

Which of the following is a possible output for 50 * rand()?

100 0 50 500

The following loop displays ________________. for (int i = 1; i <= 10; i++) { cout << i << " "; i++; }

13579

What is the value of static_cast<double>(5)/2?

2.5;

What is max(min(3,6),2)?

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.size()?

4

What is the output for y? int y = 0; for (int i = 0; i < 10; ++i) { y+ = i; } cout << y;

45

What is the output of the following code? int count = 5; while (count > 0) { cout << count << " "; count--; }

5 4 3 2 1

pow(2.0,3.0) returns _____.

8.0 (2.0 to the power/exponent of 3.0)

The ASCII of 'a' is 97. What is the ASCII for 'c'?

99

_____________ are called stream insertion and stream extraction operators for sending output to the console and reading from the console, respectively.

<< and >>

___________ is an object-oriented programming language.

C# Python Java C++

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

F

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

False

____________ is a device to connect a computer to a local area network (LAN).

NIC

Does the function call in the following function cause compile errors? #include <iostream> #include <cmath> using namespace std; int main() { pow(2.0,4); return 0; }

No

Will the following program terminate? int balance = 10; { if (balance < 9) continue; balance = balance - 9; } Yes/No

No

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

The following program displays___________. #include <iostream> using namespace std; int main { cout<<"Programming"; cout<<"is" cout<<"fun"; return 0; }

Programmingisfun

Which of the loop statements always have their body executed at least once.

The do-while loop

Analyze the following code: #include <iostream> using namespace std; int xfunction(int n, long t) { cout << "int"; return n; } long xfunction(long n) { cout << "long"; return n; } int main() { cout << xfunction(5); return 0; }

The program displays long followed by 5

Analyze the following code: #include<iostream> using namespace std; intmain() { 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 in overflow.

Is 'a' larger than 'A'. T/F

True

The actual parameters of a function must match the formal parameters in type, order, and number.

True

The elements inside the for loop control are separated using semicolons instead of commas. T/F

True

The return value type do not contribute toward distinguishing one function from another, only the parameter list.

True

You can always convert a for loop to a while loop. T/F

True

You must have a return statement in a void function.

True

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

Yes

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

a

A variable defined inside a function is referred to as________.

a local variable

If a program compiles fine, but it produces incorrect result, then the program suffers __________.

a logic error

If a program compiles fine, but it terminates abnormally at runtime, then the program suffers __________.

a runtime error

A variable or a value listed in a call to a function is called

an argument

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

any name with extension .cpp

To add a to b and store result in b, you write (Note: C++ is case-sentitive)

b += a;

What is the output of the following code? #include <iostream> using namespace std; inline void p(char ch = 'b', int n =4) { while (n > 0) { cout << ch; n--; } cout << endl; } int main () { p(); return 0; }

bbbb

To declare a constant MAX_LENGTH inside a function with value 99.98, you write

const double MAX_LENGTH = 99.98;

A preprocessor directive ends with a semicolon. T/F

false

You can always assign a value of long type to a variable of int type without loss of precision. T/F

false

You can define a constant twice in a block. T/F

false

You can define a variable twice in a block. T/F

false

you must have a return statement in a void function

false

The signature of a function consists of ___________.

function name and parameter list

C++ allows you to declare functions w/ the same name. This is called_________.

function overloading

To check whether char variable ch is a digit, use the function

isdigit(ch)

Which of the following justifies the output to the left?

left

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

max is 0

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 2

What is the number of iterations in the following loop: for (int = 1; i <= n; i++) { // iteration }

n

What is the number of iterations in the following loop: for (int i = 1; i < n; i++) { // iteration }

n - 1

A character is stored in ________.

one byte

___________ is program that runs on a computer to manage and control a computer's activities.

operating system

If a parameter is a reference variable, this parameter becomes an alias for the original variable. This is referred to as_________.

pass by reference

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

prints out Welcome to C++ forever.

Which of the following are not the functions in C+++?

random rint

Suppose two strings are declared as string s1 = "ABC" and string s2 = "DEFG". Which of the following are correct expressions?

s1 + s2 "TEMP" + s1 s1 + s2 + "TEMP" s1 + "TEMP"

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

s1 > s2 s1 < s2 s1 >= s2 s1 == s2 s1 <= s2

Which of the following is a stream manipulator function?

setprecision(n) setw(width) fixed left showpoint

You can use ______to set the width of a print field.

setw(width)

Which of the following are functions of C++?

srand pow rand

You can assign a character value to an int, or an into to char. T/F

true

What is i after the following for loop int y = 0; for (int i = 0; i <10; ++i) { y+ = i; }

undefined

Which of the following statements are the same?

x = x - (x + 4)

What is the output of the following code? #include 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

What is x after the following statements? int x = 2; int y = 1; x * = y + 1;

x is 4

Is the following loop correct? for (; ; );

yes

What is the value of balance after the following code is executed? int balance = 10; while (balance >= 1) { if (balance < 9) break; balance = balance - 9; }

1

What is the output of the following fragment? for (int i = 0; i < 15; i++) { if (i % 4 == 1) cout << i << " "; }

1 5 9 13

-5 % 5 is ________.

0

A variable declared in the for loop control can be used after the loop exits. T/F

False

C++ was originally created by Bjarne Stroustrup at Bell Lab. T/F

True


Kaugnay na mga set ng pag-aaral

Diabetes and Osteoporosis Recitation

View Set

AP CSP Unit 1 Digital Info Study Guide

View Set

PED 1004 Chapter 5: Introduction to Jogging

View Set

Theories of Language Development

View Set

Chapter 3 Introduction to process technology

View Set

Human Nutrition (preparing for the final) Chapter 13, DHN 101 Final 2, DHN 101 EXAM 4

View Set