Comp Sci 2250 final
This operator takes an operand and reverses its truth and falsehood
!
Example of a preprocessor directive
#include <iostream>
What is a literal
A literal is some data that's presented directly in the code, rather than indirectly through a variable or function call. Here are some examples, one per line:
what is the difference between an application and a utility program
Application program: Programs that allow a user to perform specific tasks on a computer - Word processing, playing a game, preparing taxes, browsing the Web, and so forth Utility program: Type of software that performs a specific task, usually related to managing or maintaining the computer system Many utilities are built into operating systems (for finding files, viewing images, backing up files, etc.)
Function prototypes are required in the language (T,F)
False
Local variables are initialized to zero by default
False
T/F the scope of a variable declared in a for loops initialization expression always extends beyond the body of the loop
False
The preprocessor executes after the compiler T/F
False
You must furnish an argument with a function call. T/F
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
This is a statement that causes a function to execute
Function call
What will this print if the user types John Clites<Enter>? string x; cin >> x; cout << "Hello" << setw(8) << x ;
Hello John
these are data items whose values dont change while the program is running
literals
This type of variable is defined inside a function and is not accessible outside the function.
local
--number on top
minus 1
To write data to a file you define an object of this data type
ofstream
A file must be _____ before data can be written to or read from
opened
Which statement writes the contents of number to a file Outfile
outfile << number
When a variable is assigned a number that is too large for its data type, it:
overflows
The do while loop is a _____ loop that is ideal in situations where you always what the loop to iterate at least once
post-test
A statement that starts with a # is called
preprocessor directive
This statement causes a function to end
return
number++ in cout
same number
Given the fragment below, what will happen if the user types 2<enter> and 3<enter> instead of 2 3 <enter>? int x, y; cout << "Give 2 numbers: "; cin >> x >> y; cout << x << " " << y;
same output
The _____ of a variable is limited to the block in which it is declared
scope
The ________ of a variable is limited to the block in which it is declared.
scope
This manipulator is used to establish a field width for the value immediately following it.
setw
The total number of digits that appear before and after the decimal point is sometimes referred to as:
significant digits and precision
A character literal is enclosed in ________ quotation marks, whereas a string literal is enclosed in ________ quotation marks.
single, double
In the process of translating a source file into an executable file, which of the following is the correct sequence?
source code, preprocessor, modified source code, compiler, object code, linker, executable code
a group of characters inside a set of quotation marks is called
string literal
When the final value of an expression is assigned to a variable, it will be converted to:
the data type of the variable
At the heart of a computer is its central processing unit. The CPU's job is:
to fetch instructions, to carry out the operations commanded by the instructions, to produce some outcome or resultant information.
You may define a _____ in the initialization expression for a loop
variable
When a relational expression is false, it has the value ________.
zero
When an expression is false what is its value
zero
1. Given this program, list all potential errors. #include <iostreams> int main( ) { int x, y cout >> "Give age"; cin << x; cout << "Hello" << x << end;
#include <iostreams> should be iostream using namespace std; missing int main( ) { int x, y ; missing cout >> "Give age"; use << instead of >> cin << x; opposite of above cout << "Hello" << x << end; should be endl return 0; missing
This operator represents the logical AND
&&
What will the following code display? int x = 0, y = 1, z = 2; cout << x << y << z << endl;
012
What is assigned to the variable a given the statement below with the following assumptions: x = 10, y = 7, and z, a, and b are all int variables. a = x >= y;
1
What is the output of the following statement? cout << 4 * (15 / (1 + 3)) << endl;
12
What is the value of cookies after the execution of the following statements? int number = 38, children = 4, cookies; cookies = number % children;
2
What will the value of x be after the following statements execute? int x; x = 18 % 4;
2
What will this print if the user types 3.1526 <Enter>? float x; cin >> x; cout << setprecision(2) << x << endl << fixed << x;
3.2 3.15
What will the value of x be after the following statements execute? int x; x = 18.0 / 4;
4
What will this print? int x=10; cout << sizeof(x);
4
1.What is the value of average after the following code executes? double average; average = 1.0 + 2.0 + 3.0 / 3.0;
4.0
Given the fragment below, what will happen if the user types 2 3<enter> instead of entering one number at a time? int x, y; cout << "Give first number: "; cin >> x; cout << "Give second number: "; cin >> y; cout << x << " " << y;
Before being able to enter the prompt for Give second number: 2 3 will be displayed
_____ are used to translate each source code instruction into the appropriate machine language instructions
Compilers
What are the internal parts of the cpu
Control unit and the arithmetic and logic unit
In any program that uses the cin object, you must include the ________.
iostream header file
Give examples of high level languages.
Java, C++, Pascal
What is iostream
Library for standard input/output or the header for the library
What is linker doing
Links libraries and pieces of your program
What will the following code display? cout << "Monday"; cout << "Tuesday"; cout << "Wednesday";
MondayTuesdayWednesday
The compilers main memory is known as
RAM
What does ignore(10,'\n'); do?
Skip the next 10 characters in the current input buffer, or until new line
If you need to take your program to a different computer, would you take the source or the executable?
Source if completely different computer
What will the following code display? int number = 7; cout << "The number is " << "number" << endl;
The number is number
What does the term hardware refer to
The physical components that a computer in made of
What will happen if a program attempts to open a file, for writing that doesnt exist
The system will create an empty file of the specified name, no error
Global variables are initialized to zero by default
True
In c++ key words are written in all lowercase letters T/F
True
T/F An initialization expression may be omitted from the loop if no initialization is required
True
T/F Multiple rational expressions cannot be placed in the test condition of a for loop
True
T/F The update expression of a for loop can contain more than one statement
True
You may use the exit( ) function to terminate a program, regardless of which control mechanism is executing
True
________ represent storage locations in the computers memory
Variables
++number on top
add 1
in C++ the = operator indicates
assignment
in c++ the = sign means
assignment
In c++ two slash marks // indicates
beginning of a comment
Without this statement appearing in a switch construct, the program "falls through" all of the statements below the one with the matching case expression.
break
This manipulator causes the field to be left-justified with padding spaces printed to the right.
left
A function is executed when it is
called
What does the statement dataFile.close() do
closes file
The function, pow(x, 5.0), requires this header file.
cmath
Write a statement to print: The result of 7/2 is 3.5 where 7, 2 come from integer variables x, y and 3.5 is from dividing x by y.
cout << "The result of " << x << "/" << y << " is " << static_cast<double>(x)/y;
To use the rand( ) function, you must #include this header file in your program.
cstdlib
exit() function requires which library and how many parameters does it take
cstdlib, 1
Order from top to bottom a. global variables/constants b. main function c. function prototypes d. include directives e. additional functions
d,a,c,b,e
int x=0; { cout<<"wow"; } while(x); what type of loop
definite
A function ________ contains the statements that make up the function
definition
You must have a _______ for every variable that you use in a program
definition
The programming process consists of several steps, which include
design , creation , testing , and debugging
It is a good programming practice to ________ your functions by writing comments that describe what they do
document
int x=0; while(x<0) { cout<<0; x++; } what type of loop
error
while( ) cout<<0; what type of loop
error
A variable, usually boolean or an integer that signals when a condition exists
flag
This is a variable, usually a boolean or an integer, that signals when a condition exis
flag
To allow file access in a program you must #include which header
fstream
header file included to allow file access in a program
fstream
This is a collection of statements that performs a specific task
function
An example of a secondary storage device
hard disk
Given int main() { int x=11; cout << "X is " << x << endl; return 0; } List all dentifiers: keywords: operators: manipulators: delimiters: literals:
identifiers: main x cout keywords: int operators: = << manipulators: endl delimiters: () {} ; literals: 11 "X is" 0
To read data from a file you define an object of this data type
ifstream
for (;;) cout<<"wow"; what type of loop
infinite
for (int i=0; i<10; i+1) cout<<"wow"; what type of loop
infinite
while (1) cout << "wow"; what type of loop
infinite
a for statement contains three expressions
initialization, test and update