Multiple Choice Questions Flashcards
. ________ is the physical aspect of the computer that can be seen
a) hardware
b) Software
c) Operating system
d) Application programming
Hardware
some hardware components of a computer include: CPU, memory, hard disk, printer, and communication devices
__________ is the brain of a computer.
a) Hardware
b) CPU
c) Memory
d) Disk
CPU
the CPU retrieves instructions from the memory and executes them
One byte has __ bits
a) 4
b) 8
c) 12
d) 16
8
A computers _____ is volatile; that is, any information stored in it is lost when the systems power is turned off
a) Floppy disk
b) Flashdisk
c) CD-ROM
d) memory
Memory
The memory of the computer is used to store data and program instructions for the CPU to execute. The memory is volatile, so when power is turned off information is lost. That is why information is stored in storage devices.
Computers can execute the code in ______
a) machine language
b) assembly language
c) high-level language
d) none of the above
Machine Language
Machine language is a computers native language, a set of built in primitive instructions
ex. adding two numbers would look something like
1101101010011010
_____ translates high level language program into machine language program
a) An assembler
b) A compiler
c) CPU
d) the operating system
A compiler
_____ is an operating system
a) Java
b) C++
c) Windows
d) Visual basics
Windows
An operating system is an important program that manages and controls a computers activities
_______ is a program that runs on a computer to manage and control a computers activities
a) Operating System
b) C++
c) interpreter
d) Complier
Operating System
an example of an operating system is Windows
Which of the following statements is the correct way to displau Welcome to C++ on the console?
A) cout «_space;“Welcome to C”;
B) cout»_space; “Welcome to C”;
C) cout < “Welcome to C”;
D) cout «_space;‘Welcome to C’
cout «_space;“Welcome to C”;
Which of the following preprocessor directive is correct?
A) import iostream
B) #include <iostream>
C) include <iostream>
D) #include iostream</iostream></iostream>
include <iostream></iostream>
a compiler preprocessor directive that tells the compiler to include the iostream library in the program. It is needed to support console input and output
Every statement in C ends with ________, which is called a statement terminator
A) a semicolon (;)
B) a comma (,)
C) a peiod (.)
D) an asteisk (*)
A semicolon ;
a statement is a complete and separate instruction that preforms some action.
A block is enclosed inside __________.
A) Parentheses
B) Braces
C)Brackets
D) Quotes
Braces
a block is a set of statements that are grouped together and treated as one unit
Which of the following statements is correct?
A) Every line in a program must end with a semicolon
B) Every statement in a program must end with a semicolon
C) Every comment line must end with a semicolon
D) Every function must end with a semicolon
E) Every preprocessor directive must end with a semicolon
Every statement in a program must end with a semicolon
What is the output of the following code?
cout «_space;“1 + 2 +3” «_space;endl;
cout «1 +2 +3 «_space;endl;
A) 1 + 2 + 3 followed by 6
B) “6” followed by 6
C) 1 + 2 + 3 followed by 1 + 2 + 3
D) 6 followed by 6
1 + 2 + 3 followed by 6
cout «_space;“1 + 2+ 3” «_space;endl;
cout «_space;1 +2 + 3 «_space;endl;
anything in quotation marks is displayed exactly as seen.
Since the next line is not in quotation marks, it will be calculated and the answer will be displayed.
___________ is called a stream insertion operator for sending output to the console.
A) a semicolon (;)
B) a comma (,)
C) a peiod (.)
D) an asteisk (*)
E) «
«
The «_space;is used to insert data into the output stream.
C++ compiler translates C++ source code into _________.
A) Java code
B) machine code
C) C code
D) another high-level language code
Machine code
The computer can only read machine code, so the compiler takes everything in C++ language and translates it into machine language so the computer can execute it.
Suppose you create a C as follows, the source code should be stored in a file named ___________.
int main()
{
}
A) Test.cpp
B) Test.doc
C) Test.txt
D) Test.java
E) Any name with extension .cpp
Any name with extension .cpp
When naming the source code it is really only being named for your use. You can call it anything you want, just maker sure it is followed by .cpp
If a program compiles fine, but it produces incorrect result, then the program suffers
__________.
A) a compilation/syntax eror
B) a runtime eror
C) a logic error
a logic error
A logic error is when the program does not run the way it was intended. These errors are really hard to identify.
include <iostream></iostream>
The following code has _______.
using namespace std;
int main()
{
cout «_space;“Welcome to C++ «_space;endl;
return 0;
}
A) a compilation/syntax eror
B) a runtime eror
C) a logic error
A compilation/ syntax error
A compiler/ syntax error is one detected by the compiler. You can see that there is a missing quotation mark, a mistake made by the programmer.
____________ is the assignment operator.
A ==
B :=
C =
D =:
=
the assignment operaotr is used to assign a value to a variable.
ex.
int x=5
the assignment operator is used to assign the value of 5 to the variable x
To assign a value 1 to variable x, you write
1 = x;
B x = 1;
C x := 1;
D 1 := x;
E x == 1;
x=1;
Which of the following types can be used to define a floating-point numbers?
A) int
B) shot
C) long
D) double
double
use when the variable can be a decimal number
To improve readability and maintainability, you should declare a _________ for PI instead of
using literal values such as 3.14159.
A) variable
B) function
C) constant
D) class
constant
declaring a constant allows you to create a value that cannot be changed throughout the program.
ex. declaring a constant for pi
const double pi = 3.14159;
now, anytime you use pi in your program its value that was initialized will be used.
To declare a constant MAX_LENGTH inside a function with value 99.98, you write
A)const MAX_LENGTH = 99.98;
B) double MAX_LENGTH = 99.98;
C) const double MAX_LENGTH = 99.98;
const double MAX_LENGTH = 99.98;
this statement is declaring a constant variable called MAX_LENGTH. This number will stay the same throughout the entire program i=since it is a constant. It can also be a decimal number since it is a double type
What is the result of (4 + 1) * ((5 - 2) / 2)?
A) 4
B) 5
C) 5.0
D) 7.5
E) 5.5
5
(3/2) is 1.5 but since the function used 3 and not 3.0 the answer is rounded down to 1. The rest of the equation makes the answer equal to 5.
Which of the following are correct ways to declare variables? Please select all that apply.
A) int length; int width;
B) int length, width;
C) int length; width;
D) int length, int width;
int length; int width;
this declares integer variables named length and width. you can also split this into two separate lines and the same thing would happen.
int length, width;
this function also declares two variables int length and int width.
include <iostream></iostream>
Analyze the following code.
using namespace std;
int main()
{
int month = 09;
cout «_space;“month is “ «_space;month;
return 0;
}
A) The program displays month is 09
B) The program displays month is 9
C) The program displays month is 9.0
D) The program has a syntax error, because 09 is an incorrect literal value.
The program has a syntax error, because 09 is an incorrect literal value.
What is result of 45 / 4?
A) 10
B) 11
C) 11.25
D) 12
11
the answer is rounded down since 45.0 was not used
25 % 1 is _____.
A 1
B 2
C 3
D 4
E 0
0
if you divide 25 by 1 there is 0 remaining.
The __________ function returns a raised to the power of b
A power(a, b)
B exponent(a, b)
C pow(a, b)
D pow(b, a)
pow (a,b)
To write 2.1 ^ 2.4 in C++, use _____
A pow(2.4, 2.1)
B pow(2.1, 2.4)
C 2.1 * 2.4
D 2.1 * 2.1
pow(2.1, 2.4)
pow(2.0, 3) returns __________.
A 9
B 8
C 1
D 0
8
What is x after the following statements?
int x = 2;
int y = 1;
x *= y + 1;
A x is 1.
B x is 2.
C x is 3.
D x is 4.
4
The statement x* = y+1 multiplies the value of x by the result of y+1
(basically a trick is do the math but ignore the = sign)
Suppose x is 1. What is x after x+=2?
A) 0
B) 1
C) 2
D) 3
E) 4
3
ignore = sign and solve
invoking time(0) returns____
A) the hour, minute, and second of the current time.
B) the elapsed time in milliseconds since Midnight, Jan 1, 1970 GMT.
C) the elapsed time in seconds since Midnight, Jan 1, 1970 GMT.
D) the elapsed time in minutes since Midnight, Jan 1, 1970 GMT.
the elapsed time in seconds since Midnight, Jan 1, 1970 GMT.
The time function is defined in the ________ header file.
A time
B ctime
C cctype
D cstdlib
E cmath
ctime
What will be the output of the following code?
int i 1;
int j = i++;
cout «_space;“i is “ «_space;i;
cout «_space;” and j is “ «_space;j;
A) i is 1 and j is 1
B) i is 1 and j is 2
C) i is 2 and j is 1
D) i is 2 and j is 2
i is 2 and j is 2
i is initialized to the value 1. then it assigns i to j and it increments the value of i by 1. since i is not a constant its value is changed to 2
Are the following four statements equivalent?
number 1;
number = number 1;
number++;
++number;
A) yes
B) no
yes
The equal comparison operator is __________.
A <>
B !
C ==
D =
==
the equal comparison operator is used to compare two values. It checks to see if both numbers on each side of the operator are equal.
Which of the following is incorrect?
A The word tue is a C keyword
B The word tue is a Boolean literal
C The word true is same as value 1
D The word true is same as value 0
The word true is same as value 0
true is assigned to 1
false is assigned to 0
What is 1 + 1 + 1 + 1 + 1 == 5?
A tue
B false
C There is no guarantee that 1 + 1 + 1 + 1 + 1 == 5 is tue.
true
the equal comparison operator checks both signs of the equal signs
Which of the following code displays the area of a circle if the radius is positive.
A if (radius ! 0) cout «_space;radius * radius * 3.14159;
B if (radius > 0) cout «_space;radius * radius * 3.14159;
C if (radius <= 0) cout «_space;radius * radius * 3.14159;
if (radius > 0 cout «_space;radius * radius * 3.14159;
this function is preformed if radius is greater than 0
What is the output of the following code?
int x = 0;
if (x < 4)
{
x = x + 1;
}
cout «_space;“x is “ «_space;x «_space;endl;
A x is 0
B x is 1
C x is 2
D x is 3
E x is 4
x is 1
the if statement check to see if x is less then 4, since it is the statement is preformed
Analyze the following code.
bool even = false;
if (even)
{
cout «_space;“It is even!”;
}
A The code displays: It is even!
B The code displays nothing.
C The code is wrong. You should replace if (even) with if (even == true)
D The code is wrong. You should replace if (even) with if (even = true)
The code displays nothing.
int the if statement the condition ‘even’ is evaluated. since ‘even’ is false , the statement is not executed
Suppose isPrime is a boolean variable, which of the following is the correct and best
statement for testing if isPrime is true.
A) if (isPrime = true)
B) if (isPrime == true)
C) if (isPrime)
D) if !isPrime = false)
E) if !isPrime == false)
if (isPrime)
What is the output of the following code?
int number =8;
if (number < 8)
cout «_space;1 «_space;endl;
else
cout «_space;2 «_space;endl;
A 1
B 2
C nothing
D 1 2
E 2 1
2
the fist if statement is not met, it then moves onto the next else statement and the code displays 2