COMP 150 final

¡Supera tus tareas y exámenes ahora con Quizwiz!

Internally, the CPU consists of two parts:

The control unit and the arithmetic and logic unit

What does the term hardware refer to?

The physical components that a computer is made up of

When a program uses the setw manipulator, the iosetwidth header file must be included in a preprocessor directive:

false

To write data to a file, you define an object of this data type:

ofstream

A(n) ________ is a set of instructions that the computer follows to solve a problem.:

program

This statement causes a function to end:

return

A variable's _____ is the part of the program that has access to the variable:

scope

The value in this type of local variable persists between function calls

static

This is a dummy function that is called instead of the actual function it represents:

stub

An Integrated Development environment typically consists of

text editor, debugger, and compiler

A variable called "average" should be declared as an integer data type because it will probably hold data that contains decimal places:

false

These are used to declare variables that can hold real numbers:

floating point data types

_________ reads a line of input, including leading and embedded spaces, and stores it in a string object:

getline

A____ variable is declared outside all functions:

global

Assume that a program has the following string object definition: string name; Which of the following statements correctly assigns a string literal to the string object?

name = "Jane";

A loop that is inside another loop is called:

nested loop

When an if statement is placed within the conditionally-executed code of another if statement, this is known as:

nesting

Which of the following is NOT one of the five major components of a computer system?:

preprocessor

When used as parameters, these types of variables allow a function to access the parameters original argument:

reference

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

A character literal is enclosed in ______ quotation marks, whereas a string literal is enclosed in _____ quotation marks:

single, double

Windows 10 is an example of___________ software:

system

A preprocessor directive does not require a semicolon at the end:

true

A static variable that is defined within a function is initialized only once, the first time the function is called.

true

As a rule of style, when writing an if statement you should indent the conditionally-executed statements:

true

One reason for using functions is to break programs into manageable units, or modules.

true

You may define a ________ in the initialization expression of a for loop:

variable

This operator takes an operand and reverses the truth or falsehood:

!

Which of the following is a preprocessor directive?:

#include <iostream>

The _____ causes the contents of another file to be inserted into a program:

#include directive

Assume that x is an int variable. What value is assigned to x after the following assignment statement is executed? x = -3 + 4 % 6 / 5

-3

What will the following loop display? int x = 0; while (X < 5) { cout << x << endl; x++; }

0 1 2 3 4

Given the following function definition void calc (int a, int & b) { int c; c = a + 2; a = a * 3; b = c + a; } What is the output of the following fragment that invokes calc? (Note: all variables are of type int) x = 1; y = 2; z = 3; calc(x, y); cout << x << " " << y << " " << z << endl;

1 6 3

What will the value of x be after the following statements execute? int x = 0; int y = 5; int z = 4; x = y + z * 2;

13

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

15

What is the output of the following program? #include <iostream> using namespace std; void doSomething(int&); int main() { int x = 2; cout << x << endl; doSomething(x); cout << x << endl; return 0; } void doSomething( int& num) { num = 0; cout << num << endl; }

2 0 0

What is the output of the following program? #include <iostream> using namespace std; void doSomething(int); int main() { int x = 2; cout << x << endl; doSomething(x); cout << x << endl; return 0; } void doSomething( int num) { num = 0; cout << num << endl; }

2 0 2

How many times will the following loop display "Hello"? for(int i = 0; i<20; i++) cout << "Hello!" << endl;

20

The preprocessor executes after the compiler:

FALSE

A variable declaration announces the name of a variable that will be used in a program, as well as:

The type of data it will be used to hold

The while loop has two important parts: an expression that is tested for a true or false value, and:

a statement or block that is repeated as long as the expression is true

In a function header, you must furnish: data type of parameter, data type of return value, names of parameter variables, the name of the function,

all of the above

A variable whose value can be either true or false is of this data type:

bool

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

A function is executed when it is:

called

Which data type requires only one byte of storage?

char

For every opening brace in C++ there must be a:

closing brace

This is a variable that is regularly incremented or decremented each time a loop iterates.:

counter

A function __________ contains the statements that make up the function

definition

To read data from a file, you define an object of this data type:

ifstream

Something within a while loop must eventually cause the condition to become false, or a(x)_______results.:

infinite loop

In a for statement, this expression is executed only once:

initialization

Write a complete program that declares an integer variable, reads a value from the keyboard into that variable, and writes to standard output the square of that variable's value.

#include <iostream> using namespace std; int main() { float x; cin >> x; cout << ( x * x ) << endl; return 0; }

Write the necessary preprocessor directive to enable the use of the C++ string class.

#include<string>

These are operators that add and subtract one from their operands:

++ and --;

What will the value of x be after the following statements execute? int x; x=18/4;

4

Which line in the following program contains the prototype for the showDub function? 1 #include <iostream> 2 using namespace std; 3 4 void showDub(int); 5 6 int main() 7 { 8 int x = 2; 9 10 showDub(x); 11 cout << x << endl; 12 return 0; 13 } 14 15 void showDub(int num) 16 { 17 cout << (num * 2) << endl; 18 }

4

What is the output of the following program? #include <iostream> using namespace std; void showDub(int); int main() { int x = 2; showDub(x); cout << x << endl; return 0; } void showDub(int num) { cout << (num * 2) << endl; }

4 2

What will the following code display: int number = 6; int x = 0; x = number--; cout << x << endl;

6

The computers main memory is commonly known as

RAM

A(n) _____ is information that is passed to a function, and _______ is info that is received by a function:

argument, parameter

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

Three primary activities of a program are:

input, processing, and output

Look at the following function prototype. int myFunction(double); What is the data type of the function's return value?

int

Write the definition of an integer value-returning function add, which receives two integer parameters and returns their sum.

int add( int a, int b) { return a + b; }

Using C++ syntax, declare two integer variables named profitStartOfQuarter and cashFlowEndOfYear.

int profitStartOfQuarter; int cashFlowEndOfYear;

Given an int variable k that has already been declared, use a do-while loop to print a single line consisting of 97 asterisks. Use no variables other than k.

k = 0; do { cout << "*"; k++; } while (k < 97);

Given an int variable k that has already been declared, use a while loop to print a single line consisting of 97 asterisks.

k = 0; while( k < 97) { cout << "*"; k++; }

This type of variable is defined inside a function and is not accessible outside the function:

local

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 code? int w = 98; int x = 99; int y = 0; int z = 1; if (x >= 99) { if (x < 99) cout << y << endl; else cout <<z << endl; } else { if (x == 99) cout << x << endl; else cout << w << endl; }

1

Given the following code segment, what is the output after "result = "? int x = 1, y = 1, z = 1; y = y + z; x = x + y; cout << "result = " << (x < y ? y : x ) << endl;

3

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

3

Assuming x is 5, y is 6, and z is 8, which of the following is false? 1. x == 5; 2. 7 <= (x+2); 3. z < =4; 4. (1+x)!= y; 5. z >= 8; 6. x >= 0; 7. x <= (y * 2)

3 and 4

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

3*2

What is the ASCII value for H?

72

Assume that x is a double variable that has been given a value. Write a statement that prints it out with exactly 3 digits to the right of the decimal point no matter what how big or miniscule its value is.

cout << setprecision(3) << fixed << x << endl;

If you intend to place a block of statements within an if statement, you must place ___ around the block

curly braces

What is the value of the following expression? false || true

either +1 or true

The condition that is tested by a while loop must be enclosed in parentheses and terminated with a semicolon.

false

The following code correctly determines whether x contains a value in the range of 0 through 100, if (x >= 0 && <= 100)

false

You may nest while and do while loops but you may not nest for loops

false

You must furnish an argument with a function call.

false

the default section is required in a switch statement:

false

This is a variable usually a Boolean or an integer, that signals when a condition exists

flag

Given an int variable k that has already been declared, use a for loop to print a single line of 97 asterisks. Use no variables other than k.

for( k = 0; k < 97; k++) cout << "*";

To allow file access in a program you must #include this header file:

fstream

Given two integer variables num and highest, write an assignment statement that gives highest the same value that num has.

highest = num;

When C++ is working with an operator, it strives to convert the operands to the same type:

true

Convert this switch statement to an if/else if. switch(status) { case 200: cout << "OK (fulfilled) "; break; case 403: cout << " forbidden"; break; case 404: cout << " not found"; break; case 500: cout << " server error"; break; default : cout << " invalid code"; break;

if (status == 200) { cout << "OK (fulfilled)" << endl; } else if (status == 403) { cout << "forbidden" << endl;} else if (status == 404) { cout << "not found" << endl;} else if (status == 500) { cout << "server error" << endl;} else { cout << "invalid code" << endl;}

Write an if (any type) statement that adds 1 to the variable minors if the variable age is less than 18, adds 1 to the variable adults if age is 18 through 64, and adds 1 to the variable seniors if age is 65 or older.

if( age < 18) minors += 1; else if ( age >= 18 && age < 65 ) adults += 1; else seniors += 1;

Assume that a bool variable isQuadrilateral has been declared, and that an int variable, numberOfSides has been declared and initialized. Write a statement that assigns the value true if numberOfSides is exactly 4 and false otherwise.

if( numberOfSides == 4) isQuadrilateral = true; else isQuadrilateral = false;

Which is true about the following statement? cout << setw(4) << num4 << " ";

it allows four spaces for the value in the variable num4

Words that have a special meaning and may be used only for their intended purpose are known as:

key words

Assume that a program has the following variable definition char letter; Which of the following statements correctly assigns the character Z to the variable?

letter = 'Z';

What is the value of donuts after the following code executes? int donuts = 10; if (donuts != 10) donuts = 0; else donuts += 2;

12

In the C++ instruction, cookies = number % children; Given the following declaration statement int number = 38, children = 4, cookies; What is the value of cookies after the execution of the statement?

2

Assuming you are using a system with 1-byte characters, how many bytes of memory will the following string literal occupy? "William"

8

Which line of the compiler will cause a compiler error? 1 #include<iostream> 2 using namespace std; 3 4 int main() 5 { 6 int number = 5; 7 8 if (number >= 0 && <= 100) 9 cout << "passed.\n"; 10 else 11 cout <<"failed.\n"; 12 return 0; 13 }

8

Which value can be entered to cause the following code segment to display the message "That number is acceptable." int number; cin >> number; if (number > 10 && number < 100 ) cout << "That number is acceptable.\n"; else cout << "That number is not acceptable.\n";

99

This is used to mark the end of a complete C++ programming statement:

;

This operator is used in C++ to represent equality.

==

The ________ operator always follows the cin object, and the ________ operator follows the cout object:

>>, <<

__________ are used to translate each source code instruction into the appropriate machine language instruction:

Compilers

What will the following code display? cout << "Four\n" << "score\n"; cout << "and " << "\nseven"; cout << "\nyears" << "ago" << endl;

Four Score And seven Years ago

1.35 What will the following code display? cout << Monday; cout << Tuesday; cout << Wednesday;

MondayTuesdayWednesday

If you use a C++ key word as an identifier, your program will:

Not compile

You can use these to override the rules of operator precedence in a mathematical expression:

Parentheses

A CPU really only understands instructions that are written in machine language:

TRUE

In C++, key words are written in all lowercase letters:

TRUE

A set of well-defined steps for performing a task or solving a problem is known as a(n)

algorithm

Input values should always be checked for: division by zero, if division is taking place, reasonableness, appropriate range

all of the above

The _____ causes a program to wait until information is typed at the keyboard and the enter key is pressed:

cin object

Relational operators allow you to _______numbers:

compare

Write output statement that will display the following: (there is a blank line between the two) Harding University Bisons

cout << "Harding University" << endl; cout << " " << endl; cout << "Bisons" << endl;

Two variables num and cost have been declared and given values: num is an integer and cost is a double. Write a single statement that outputs num and cost to standard output. Print both values (num first, then cost), separated by a space on a single line that is terminated with a newline character. Do not output anything else.

cout << num << " " << cost << endl;

The_____ is used to display information on the computer's screen:

cout object

Mistakes that cause a running program to produce incorrect results are called

logic errors

Which statement is equivalent to the following? number += 1;

number = number +1;

This function in C++ allows you to identify how many bytes of storage on your computer system an integer data value requires:

sizeof

The statements written by the programmer are called

source code

In programming terms, a group of characters inside a set of quotation marks is called a:

string literal

In a C++ program, two slash marks (//) indicate:

the beginning of a comment

What would be the optimum C++ data type to store a whole number that will range from 0 to 200?

unsigned short

Which of the following expressions will determine whether x is less than or equal to y?

x <= y;

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

x*=2

This operator is known as the logical OR operator:

||

Of the following, which is a valid C++ identifier? June1997, myExtraLongVariableName, _employee_number, ___department

All the above are valid identifiers

Which line in the following program contains a call to the showDub function? 1 #include <iostream> 2 using namespace std; 3 4 void showDub(int); 5 6 int main() 7 { 8 int x = 2; 9 10 showDub(x); 11 cout << x << endl; 12 return 0; 13 } 14 15 void showDub(int num) 16 { 17 cout << (num * 2) << endl; 18 }

10

4 Look at the following program and answer the question that follows it: 1 //This program displays my gross wages. 2 //I worked 40 hours and I make $20.00 per hour. 3 #include<iostream> 4 using namespace std; 5 6 int main() 7 { 8 int hours; 9 double payRate, grossPay 10 11 hours = 40; 12 payRate = 20.0 13 grossPay = hours * payRate; 14 cout << "My gross pay is $" << grossPay << endl; 15 return 0; 16 } Question: Which line in this program cause output to be displayed on the screen?

14

After the execution of the following code, what will be the value of input_value 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;

15

ASCII is an acronym for:

American Standard Code for Information Interchange

This step will uncover any syntax errors in your program:

compiling

How would you consolidate the following declaration statements into one statement? int x = 7 int y = 16; int z = 28;

int x = 7, y = 16, z = 28;

The numeric data types in C++ can be broken into two general categories

integer and floating point

In any program that uses the cin object, you must include the ________:

iostream header file

The do while loop is a _________ loop that is ideal in situations where you always want the loop to iterate at least once:

posttest

The while loop is this kind of loop:

pre-test

When the increment operator precedes its operand as in ++num1, the expression is in this mode:

prefix

Programmer-defined names of memory locations that may hold data are:

variables

Write the definition of maxmin that is passed four int arguments. The function returns nothing but stores the larger of the first two arguments in the third argument it receives and the smaller of the first two arguments in its fourth argument. So, if you invoke maxmin(3, 7, x, y), upon return x will have the value 7 and y will have the value 3.

void maxmin( int a, int b, int & x, int & y) { if (a > b) { x = a; y = b;} else { x = b; y = a; } }

Write the definition of a function printLarger which as two int parameters and returns nothing. The function prints the larger value of the two parameters to standard output on a single line by itself. (For purposes of this exercise, the "larger" means "not the smaller".)

void printLarger( int a, int b) { if (a > b) cout << a << endl; else cout << b << endl; }


Conjuntos de estudio relacionados

US History 8: Post Test: Colonial America

View Set

Week 2: Intro to EKG/Cardiac Arrhythmias

View Set

RN Concept-Based Assessment Level 2 Online Practice B

View Set

MediaLab Hematology Practice Questions Part 2

View Set

Chapter 4 Single-Phase Isolation Transformers

View Set

9.29 MKT 310- Exam 2 (Homework Questions)

View Set