Free Essay

C++ Chap1-8 Quiz Summary

In: Computers and Technology

Submitted By mtryshy
Words 10107
Pages 41
http://cplusplus-answers.blogspot.com/search?q=10552

1
Marks: 1
Characters or symbols that perform operations on one or more operands are:
Choose one answer. | a. Syntax | | | b. Op codes | | | c. Operators | | | d. Program ops | | | e. None of the above | |
Correct
Marks for this submission: 1/1.
Question2
Marks: 1
Programmer-defined names of memory locations that may hold data are:
Choose one answer. | a. Operators | | | b. Variables | | | c. Syntax | | | d. Operands | | | e. None of the above. | |
Correct
Marks for this submission: 1/1.
Question3
Marks: 1
Which of the following best describes an operator?
Choose one answer. | a. An operator is a rule that must be followed when constructing a program. | | | b. An operator allows you to perform operations on one or more pieces of data. | | | c. An operator marks the beginning or ending of a statement, or is used to separate items in a list. | | | d. An operator is a word that has a special meaning. | | | e. An operator is a symbolic name that refers to a variable. | |
Correct
Marks for this submission: 1/1.
Question4
Marks: 1
What does the term hardware refer to?
Choose one answer. | a. The relative difficulty of programming | | | b. The physical components that a computer is made of | | | c. The way a computer's storage space is organized | | | d. The logical flow of instructions | | | e. None of the above. | |
Correct
Marks for this submission: 1/1.
Question5
Marks: 1
The computer's main memory is commonly known as:
Choose one answer. | a. The hard disk | | | b. The floppy disk | | | c. RAM | | | d. Secondary storage | | | e. None of the above | |
Correct
Marks for this submission: 1/1.
Question6
Marks: 1
The programming process consists of several steps, which include:
Choose one answer. | a. Input, Processing, and Output | | | b. Key Words, Operators, and Punctuation | | | c. Design, Creation, Testing, and Debugging | | | d. Syntax, Logic, and Error Handling | | | e. None of the above | |
Incorrect
Marks for this submission: 0/1.
Question7
Marks: 1
The purpose of a memory address is:
Choose one answer. | a. To identify the location of a byte in memory | | | b. To prevent multitasking | | | c. To obtain an algorithm | | | d. To improve the effectiveness of high-level languages | | | e. None of the above | |
Correct
Marks for this submission: 1/1.
Question8
Marks: 1
An Integrated Development Environment typically consists of:
Choose one answer. | a. A text editor | | | b. A compiler | | | c. A debugger | | | d. All of the above | | | e. None of the above | |
Correct
Marks for this submission: 1/1.
Question9
Marks: 1
At the heart of a computer is its central processing unit. The CPU's job is:
Choose one answer. | a. To fetch instructions | | | b. To carry out the operations commanded by the instructions | | | c. To produce some outcome or resultant information | | | d. All of the above | | | e. None of the above | |
Correct
Marks for this submission: 1/1.
Question10
Marks: 1
The ________ decodes an instruction and generates electrical signals.
Choose one answer. | a. Arithmetic and Logic Unit | | | b. Main memory | | | c. BIOS | | | d. Control Unit | | | e. None of the above | |
Correct
Marks for this submission: 1/1.

Started on | Friday, 26 April 2013, 03:40 PM | Completed on | Friday, 26 April 2013, 04:00 PM | Time taken | 19 mins 58 secs | Grade | 9 out of a maximum of 10 (90%) |
Question1
Marks: 1
_____________ represent storage locations in the computer's memory.
Choose one answer. | a. Literals | | | b. Variables | | | c. Comments | | | d. Integers | | | e. None of the above | |
Incorrect
Marks for this submission: 0/1.
Question2
Marks: 1
Of the following, which is a valid C++ identifier?
Choose one answer. | a. June1997 | | | b. _employee_number | | | c. ___department | | | d. myExtraLongVariableName | | | e. All of the above are valid identifiers. | |
Correct
Marks for this submission: 1/1.
Question3
Marks: 1
For every opening brace in a C++ program, there must be a:
Choose one answer. | a. String literal | | | b. Function | | | c. Variable | | | d. Closing brace | | | e. None of the above | |
Correct
Marks for this submission: 1/1.
Question4
Marks: 1
In a C++ program, two slash marks ( // ) indicate:
Choose one answer. | a. The end of a statement | | | b. The beginning of a comment | | | c. The end of the program | | | d. The beginning of a block of code | | | e. None of the above | |
Correct
Marks for this submission: 1/1.
Question5
Marks: 1
The numeric data types in C++ can be broken into two general categories:
Choose one answer. | a. numbers and characters | | | b. singles and doubles | | | c. integer and floating point | | | d. real and unreal | | | e. None of the above | |
Correct
Marks for this submission: 1/1.
Question6
Marks: 1
These are data items whose values do not change while the program is running.
Choose one answer. | a. Literals | | | b. Variables | | | c. Comments | | | d. Integers | | | e. None of the above | |
Correct
Marks for this submission: 1/1.
Question7
Marks: 1
You must have a ___________ for every variable you intend to use in a program.
Choose one answer. | a. purpose | | | b. definition | | | c. comment | | | d. constant | | | e. None of the above | |
Correct
Marks for this submission: 1/1.
Question8
Marks: 1
The ______ is/are used to display information on the computer's screen.
Choose one answer. | a. Opening and closing braces | | | b. Opening and closing quotation marks | | | c. cout object | | | d. Backslash | | | e. None of the above | |
Correct
Marks for this submission: 1/1.
Question9
Marks: 1
A statement that starts with a # is called a:
Choose one answer. | a. Comment | | | b. Function | | | c. Preprocessor directive | | | d. Key word | | | e. None of the above. | |
Correct
Marks for this submission: 1/1.
Question10
Marks: 1
The _____ causes the contents of another file to be inserted into a program.
Choose one answer. | a. Backslash | | | b. Pound sign | | | c. Semicolon | | | d. #include directive | | | e. None of the above | |
Correct
Marks for this submission: 1/1.

1
Marks: 1
When this operator is used with string operands it concatenates them, or joins them together.
Choose one answer. | a. & | | | b. * | | | c. % | | | d. + | | | e. None of the above | |
Correct
Marks for this submission: 1/1.
Question2
Marks: 1
You want the user to enter the length, width, and height from the keyboard. Which cin statement is correctly written?
Choose one answer. | a. cin << length, width, height; | | | b. cin.get(length, width, height); | | | c. cin >> length >> width >> height; | | | d. cin >> length, width, height; | | | e. cin << length; width; height; | |
Incorrect
Marks for this submission: 0/1.
Question3
Marks: 1
This function tells the cin object to skip one or more characters in the keyboard buffer.
Choose one answer. | a. cin.ignore | | | b. cin.jump | | | c. cin.hop | | | d. cin.skip; | | | e. None of the above | |
Correct
Marks for this submission: 1/1.
Question4
Marks: 1
What is the value stored at x, given the statements: int x; x = 3 / static_cast<int>(4.5 + 6.4);
Choose one answer. | a. .3 | | | b. 0 | | | c. .275229 | | | d. 3.3 | | | e. None of these | |
Correct
Marks for this submission: 1/1.
Question5
Marks: 1
___________reads a line of input, including leading and embedded spaces, and stores it in a string object.
Choose one answer. | a. cin.get | | | b. getline | | | c. cin.getline | | | d. get | | | e. None of these | |
Correct
Marks for this submission: 1/1.
Question6
Marks: 1
You can use these to override the rules of operator precedence in a mathematical expression.
Choose one answer. | a. [Brackets] | | | b. (Parentheses) | | | c. {Braces} | | | d. The escape character \ | | | e. None of these | |
Correct
Marks for this submission: 1/1.
Question7
Marks: 1
The _________ causes a program to wait until information is typed at the keyboard and the Enter key is pressed.
Choose one answer. | a. Output stream | | | b. cin object | | | c. cout object | | | d. Preprocessor | | | e. None of the above | |
Correct
Marks for this submission: 1/1.
Question8
Marks: 1
You want to read in an integer. Which library do you need to include?
Choose one answer. | a. cstdlib | | | b. cmath | | | c. cstring | | | d. iostream | | | e. iomanip | |
Correct
Marks for this submission: 1/1.
Question9
Marks: 1
In any program that uses the cin object, you must include the ___________.
Choose one answer. | a. compiler | | | b. iostream header file | | | c. linker | | | d. >> and << operators | | | e. None of the above | |
Correct
Marks for this submission: 1/1.
Question10
Marks: 1
The ______ operator always follows the cin object, and the ______ operator follows the cout object.
Choose one answer. | a. binary, unary | | | b. conditional, binary | | | c. >>, << | | | d. <<, >> | | | e. None of the above | |
Correct
Marks for this submission: 1/1.

1
Marks: 1
This operator represents the logical AND.
Choose one answer. | a. ++ | | | b. || | | | c. && | | | d. @ | | | e. None of these | |
Correct
Marks for this submission: 1/1.
Question2
Marks: 1
This operator takes an operand and reverses its truth or falsehood.
Choose one answer. | a. || | | | b. relational | | | c. arithmetic | | | d. ! | | | e. None of these | |
Correct
Marks for this submission: 1/1.
Question3
Marks: 1
This is a variable, usually a boolean or an integer, that signals when a condition exists.
Choose one answer. | a. relational operator | | | b. arithmetic operator | | | c. flag | | | d. float | | | e. None of these | |
Correct
Marks for this submission: 1/1.
Question4
Marks: 1
When an if statement is placed within the conditionally-executed code of another if statement, this is known as:
Choose one answer. | a. complexity | | | b. overloading | | | c. nesting | | | d. validation | | | e. None of these | |
Correct
Marks for this submission: 1/1.
Question5
Marks: 1
This statement lets the value of a variable or expression determine where the program will branch to.
Choose one answer. | a. switch | | | b. select | | | c. associative | | | d. scope | | | e. None of these | |
Correct
Marks for this submission: 1/1.
Question6
Marks: 1
When a relational expression is false, it has the value _____.
Choose one answer. | a. one | | | b. zero | | | c. zero, one, or minus one | | | d. less than zero | | | e. None of these | |
Correct
Marks for this submission: 1/1.
Question7
Marks: 1
If you place a semicolon after the statement if (x < y)
Choose one answer. | a. The code will not compile. | | | b. The compiler will interpret the semicolon as a null statement. | | | c. The if statement will always evaluate to false. | | | d. All of the above. | | | e. None of these. | |
Incorrect
Marks for this submission: 0/1.
Question8
Marks: 1
Relational operators allow you to ____________ numbers.
Choose one answer. | a. add | | | b. multiply | | | c. compare | | | d. average | | | e. None of these | |
Correct
Marks for this submission: 1/1.
Question9
Marks: 1
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;
Choose one answer. | a. 10 | | | b. 7 | | | c. The string "x >= y" | | | d. 1 | | | e. 0 | |
Correct
Marks for this submission: 1/1.
Question10
Marks: 1
Input values should always be checked for
Choose one answer. | a. Appropriate range | | | b. Reasonableness | | | c. Division by zero, if division is taking place | | | d. All of these | | | e. None of these | |
Correct
Marks for this submission: 1/1.

1
Marks: 1
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:
Choose one answer. | a. at least once | | | b. at least twice | | | c. as many times as the user wishes | | | d. never | | | e. None of these | |
Correct
Marks for this submission: 1/1.
Question2
Marks: 1
You may define a __________ in the initialization expression of a for loop.
Choose one answer. | a. constant | | | b. function | | | c. variable | | | d. new data type | | | e. None of these | |
Correct
Marks for this submission: 1/1.
Question3
Marks: 1
The while loop is this type of loop.
Choose one answer. | a. post-test | | | b. pre-test | | | c. infinite | | | d. limited | | | e. None of these | |
Correct
Marks for this submission: 1/1.
Question4
Marks: 1
The while loop has two important parts: an expression that is tested for a true or false value, and:
Choose one answer. | a. a statement or block that is repeated as long as the expression is true | | | b. a statement or block that is repeated only if the expression is false | | | c. one line of code that is repeated once, if the expression is true | | | d. a statement or block that is repeated once, if the expression is true | |
Correct
Marks for this submission: 1/1.
Question5
Marks: 1
A for statement contains three expressions: initialization, test, and
Choose one answer. | a. update | | | b. reversal | | | c. null | | | d. validation | | | e. None of these | |
Correct
Marks for this submission: 1/1.
Question6
Marks: 1
The do-while loop is a __________ loop that is ideal in situations where you always want the loop to iterate at least once.
Choose one answer. | a. post-test | | | b. pre-test | | | c. infinite | | | d. null-terminated | | | e. None of these | |
Correct
Marks for this submission: 1/1.
Question7
Marks: 1
In a for statement, this expression is executed only once.
Choose one answer. | a. test | | | b. null | | | c. initialization | | | d. validation | | | e. None of these | |
Correct
Marks for this submission: 1/1.
Question8
Marks: 1
If you place a semicolon after the test expression in a while loop, it is assumed to be a:
Choose one answer. | a. pre-test loop | | | b. post-test loop | | | c. null statement | | | d. infinite loop | | | e. None of these | |
Correct
Marks for this submission: 1/1.
Question9
Marks: 1
This operator increments the value of its operand, then uses the value in context.
Choose one answer. | a. prefix increment | | | b. postfix increment | | | c. prefix decrement | | | d. postfix decrement | | | e. None of these | |
Correct
Marks for this submission: 1/1.
Question10
Marks: 1
These are operators that add and subtract one from their operands.
Choose one answer. | a. plus and minus | | | b. ++ and -- | | | c. binary and unary | | | d. conditional and relational | | | e. None of these | |
Correct
Marks for this submission: 1/1.

Midterm
1
Marks: 1
Assume that x is an int variable. What value is assigned to x after the following statement is executed?

x = -3 + 4 % 6 / 5 ;
Choose one answer. | a. 0 | | | b. 1 | | | c. 2 | | | d. -3 | | | e. 7 | |
Correct
Marks for this submission: 1/1.
Question2
Marks: 1
These operators connect two or more relational expressions into one, or reverse the logic of an expression.
Choose one answer. | a. relational | | | b. logical | | | c. irrational | | | d. negation | | | e. supplementary | |
Incorrect
Marks for this submission: 0/1.
Question3
Marks: 1
What is the output of the following statement?

cout << 4 * (15 / (1 + 3)) << endl;
Choose one answer. | a. 15 | | | b. 12 | | | c. 63 | | | d. 72 | | | e. None of the above | |
Incorrect
Marks for this submission: 0/1.
Question4
Marks: 1
When a relational expression is false, it has the value of
Choose one answer. | a. one | | | b. zero | | | c. zero, one or minus one | | | d. less than zero | | | e. two | |
Correct
Marks for this submission: 1/1.
Question5
Marks: 1
Input values should always be checked for
Choose one answer. | a. appropriate range | | | b. resonableness | | | c. division by zero, if division is taking place | | | d. all of these | | | e. none of these | |
Correct
Marks for this submission: 1/1.

6
Marks: 1
When an if statement is placed within the conditionally executed code of another if statement, this is known as:
Choose one answer. | a. complexity | | | b. overloading | | | c. nesting | | | d. validation | | | e. instantiation | |
Correct
Marks for this submission: 1/1.
Question7
Marks: 1
This function tells the cin object to skip one or more characters in the keyboard buffer.
Choose one answer. | a. cin.ignore | | | b. cin.jump | | | c. cin.hop | | | d. cin.skip | | | e. cin.fail | |
Correct
Marks for this submission: 1/1.
Question8
Marks: 1
In the following statement, what will be executed first according to the order of precedence?

result = 6 - 3 * 2 + 7 - 10 / 2 ;
Choose one answer. | a. 6 -3 | | | b. 3 * 2 | | | c. 2 + 7 | | | d. 7 - 10 | | | e. 10 / 2 | |
Correct
Marks for this submission: 1/1.
Question9
Marks: 1
Given the following,

int number = 38; int children = 4; int cookies = 0;

cookies = number % children;

What is the value of cookies after execution of the statement:
Choose one answer. | a. 2 | | | b. 0 | | | c. 9 | | | d. 0.5 | | | e. None of the above | |
Correct
Marks for this submission: 1/1.
Question10
Marks: 1
In a C++ program, two slash marks indicate:
Choose one answer. | a. The end of the statement | | | b. The beginning of a comment | | | c. The end of the program | | | d. The beginning of a block of code | | | e. None of the above | |
Correct
Marks for this submission: 1/1.

11
Marks: 1
Programmer defined names of memory locations that may hold data are:
Choose one answer. | a. Operators | | | b. Variables | | | c. Syntax | | | d. Operands | | | e. None of the above | |
Correct
Marks for this submission: 1/1.
Question12
Marks: 1
What is the modulus operator?
Choose one answer. | a. + | | | b. * | | | c. & | | | d. % | | | e. // | |
Correct
Marks for this submission: 1/1.
Question13
Marks: 1
A character literal is enclosed in _____ quotation marks, whereas a string literal is enclosed in _____ quotation marks.
Choose one answer. | a. double, single | | | b. triple, double | | | c. open, closed | | | d. single, double | | | e. double, double | |
Correct
Marks for this submission: 1/1.
Question14
Marks: 1
In any program that uses the cin object, you must include the _______________.
Choose one answer. | a. compiler | | | b. iostream header file | | | c. linker | | | d. >> and << operators | | | e. cout object | |
Correct
Marks for this submission: 1/1.
Question15
Marks: 1
Relational operators allow you to _______ numbers.
Choose one answer. | a. add | | | b. multiply | | | c. divide | | | d. compare | | | e. average | |
Correct
Marks for this submission: 1/1.

16
Marks: 1
The function, pow(x, 5.0) requires this header file:
Choose one answer. | a. calclab | | | b. cmath | | | c. cstring | | | d. iostream | | | e. iomanip | |
Correct
Marks for this submission: 1/1.
Question17
Marks: 1
If you place a semicolon after the statement if (x < y)
Choose one answer. | a. the code will not compile | | | b. the compiler will interpret the semicolon as a null statement | | | c. the if statement will always evaluate to false | | | d. the compiler will generate a syntax error | | | e. the program will terminate with a run time error | |
Correct
Marks for this submission: 1/1.
Question18
Marks: 1
Which data type typically requires only one byte of storage?
Choose one answer. | a. long | | | b. int | | | c. char | | | d. float | | | e. double | |
Correct
Marks for this submission: 1/1.
Question19
Marks: 1
To use the rand() function, you must #include this header file in your program:
Choose one answer. | a. iostream | | | b. iomanip | | | c. iorand | | | d. cstdlib | | | e. string | |
Correct
Marks for this submission: 1/1.
Question20
Marks: 1
Mistakes that cause a running program to produce incorrect results are called:
Choose one answer. | a. Syntax errors | | | b. Logic errors | | | c. Compiler errors | | | d. Linker errors | | | e. None of the above | |
Correct
Marks for this submission: 1/1.

21
Marks: 1
This step will uncover any syntax errors in your program
Choose one answer. | a. Editing | | | b. Compiling | | | c. Linking | | | d. Executing | | | e. None of the above | |
Correct
Marks for this submission: 1/1.
Question22
Marks: 1
1 #include <iostream>
2 using namespace std;
3 int main()
4 {
5 int fred;
6 int barney;
7
8 cout << "Please input two integers\n";
9 cin >> fred ; barney ;
10 cout << "You entered: " << fred << barney << endl;
11 return 0;
}

Which line has the syntax error?
Choose one answer. | a. 5 | | | b. 6 | | | c. 8 | | | d. 9 | | | e. 11 | |
Correct
Marks for this submission: 1/1.
Question23
Marks: 1
For every opening brace in a C++ program, there must be a:
Choose one answer. | a. String literal | | | b. Function | | | c. Variable | | | d. Closing brace | | | e. Semi-colon | |
Correct
Marks for this submission: 1/1.
Question24
Marks: 1
This operator takes an operand and reverses its truth or falsehood.
Choose one answer. | a. || | | | b. // | | | c. ! | | | d. ++ | | | e. == | |
Correct
Marks for this submission: 1/1.
Question25
Marks: 1
The __________ causes a program to wait until information is typed at the keyboard and Enter key is pressed:
Choose one answer. | a. Output stream | | | b. cin object | | | c. cout object | | | d. Preprocessor | | | e. space bar | |
Correct
Marks for this submission: 1/1.

1
Marks: 1
This is a collection of statements that performs a specific task.
Choose one answer. | a. infinite loop | | | b. variable | | | c. constant | | | d. function | | | e. None of these | |
Correct
Marks for this submission: 1/1.
Question2
Marks: 1
A function can have zero to many parameters, and it can return this many values.
Choose one answer. | a. zero to many | | | b. no | | | c. only one | | | d. a maximum of ten | | | e. None of these | |
Correct
Marks for this submission: 1/1.
Question3
Marks: 1
A function __________ contains the statements that make up the function.
Choose one answer. | a. definition | | | b. prototype | | | c. call | | | d. expression | | | e. parameter list | |
Correct
Marks for this submission: 1/1.
Question4
Marks: 1
A function is executed when it is
Choose one answer. | a. defined | | | b. prototyped | | | c. declared | | | d. called | | | e. None of these | |
Correct
Marks for this submission: 1/1.
Question5
Marks: 1
Functions are ideal for use in menu-driven programs. When a user selects a menu item, the program can ________ the appropriate function.
Choose one answer. | a. call | | | b. prototype | | | c. define | | | d. declare | | | e. None of these | |
Correct
Marks for this submission: 1/1.
Question6
Marks: 1
In a function header, you must furnish
Choose one answer. | a. data type(s) of the parameters | | | b. data type of the return value | | | c. the name of function | | | d. names of parameter variables | | | e. All of these | |
Correct
Marks for this submission: 1/1.
Question7
Marks: 1
When used as parameters, these types of variables allow a function to access the parameter's original argument.
Choose one answer. | a. reference | | | b. floating-point | | | c. counter | | | d. undeclared | | | e. None of these | |
Correct
Marks for this submission: 1/1.
Question8
Marks: 1
These types of arguments are passed to parameters automatically if no argument is provided in the function call.
Choose one answer. | a. Local | | | b. Default | | | c. Global | | | d. Relational | | | e. None of these | |
Correct
Marks for this submission: 1/1.
Question9
Marks: 1
This type of variable is defined inside a function and is not accessible outside the function.
Choose one answer. | a. global | | | b. reference | | | c. local | | | d. counter | | | e. None of these | |
Correct
Marks for this submission: 1/1.
Question10
Marks: 1
The value in this type of local variable persists between function calls.
Choose one answer. | a. global | | | b. internal | | | c. static | | | d. dynamic | | | e. None of these | |
Correct
Marks for this submission: 1/1.

-------------------------------------------------
Quiz #7 - updated
-------------------------------------------------
Review of attempt 1
-------------------------------------------------
Top of Form

Bottom of Form Started on | Tuesday, 11 June 2013, 10:50 PM | Completed on | Tuesday, 11 June 2013, 11:14 PM | Time taken | 23 mins 31 secs | Grade | 8 out of a maximum of 10 (80%) |
Question1
Marks: 2
A two-dimensional array can be viewed as ___________ and _____________.
Choose one answer. | a. rows, columns | | | b. arguments, parameters | | | c. increments, decrements | | | d. All of these | | | e. None of these | |
Correct
Marks for this submission: 2/2.
Question2
Marks: 2
The name of an array stores the __________ of the first array element.
Choose one answer. | a. memory address | | | b. value | | | c. element number | | | d. data type | | | e. None of these | |
Incorrect
Marks for this submission: 0/2.
Question3
Marks: 2
A two-dimensional array is like ______________ put together.
Choose one answer. | a. an array and a function | | | b. several identical arrays | | | c. two functions | | | d. two arrays of different types | | | e. None of these | |
Correct
Marks for this submission: 2/2.
Question4
Marks: 2
Unlike regular variables, these can hold multiple values.
Choose one answer. | a. constants | | | b. named constants | | | c. arrays | | | d. floating-point variables | | | e. None of these | |
Correct
Marks for this submission: 2/2.
Question5
Marks: 2
The individual values contained in array are known as
Choose one answer. | a. parts | | | b. elements | | | c. numbers | | | d. constants | | | e. None of these | |
Correct
Marks for this submission: 2/2.

-------------------------------------------------
Midterm #2
-------------------------------------------------
Review of attempt 1
-------------------------------------------------
Top of Form

Bottom of Form Started on | Wednesday, 12 June 2013, 09:35 AM | Completed on | Wednesday, 12 June 2013, 10:17 AM | Time taken | 41 mins 35 secs | Grade | 30 out of a maximum of 30 (100%) |
Page: 1 2 3 4 5 6 (Next)
Show all questions on one page
Question1
Marks: 1
What will the following code display?

int number = 6; cout << number++ << endl;
Choose one answer. | a. 6 | | | b. 5 | | | c. 7 | | | d. 0 | |
Correct
Marks for this submission: 1/1.
Question2
Marks: 1
The function pow(x, 5.0), requires this header file
Choose one answer. | a. cstlib | | | b. cmath | | | c. cstring | | | d. iostream | | | e. iomanip | |
Correct
Marks for this submission: 1/1.
Question3
Marks: 1
What will the following code display?

int number = 6; number++; cout << number << endl;
Choose one answer. | a. 6 | | | b. 5 | | | c. 7 | | | d. 0 | |
Correct
Marks for this submission: 1/1.
Question4
Marks: 1
What will the following code display?

int number = 6; cout << ++number << endl;
Choose one answer. | a. 6 | | | b. 5 | | | c. 7 | | | d. 0 | |
Correct
Marks for this submission: 1/1.
Question5
Marks: 1
This loop is a good choice when you know how many times you want the loop to iterate in advance of entering the loop.
Choose one answer. | a. do-while | | | b. while | | | c. for | | | d. infinite | | | e. None of these | |
Correct
Marks for this submission: 1/1.
6
Marks: 1
If you overload a function, which is true?
Choose one answer. | a. it collapses under to much weight | | | b. more than one function of that name exists in your program, but the parameter list are different | | | c. you cannot overload functions | | | d. two functions have the same parameter list | | | e. None of these | |
Correct
Marks for this submission: 1/1.
Question7
Marks: 1
For every opening brace in a C++ program, there must be a
Choose one answer. | a. Statement | | | b. Comment | | | c. Closing brace | | | d. Function | | | e. Variable | |
Correct
Marks for this submission: 1/1.
Question8
Marks: 1 in a for loop, this statement is executed only once
Choose one answer. | a. test | | | b. null | | | c. initializtion | | | d. validation | | | e. None of these | |
Correct
Marks for this submission: 1/1.
Question9
Marks: 1
This step will uncover any syntax errors in your program
Choose one answer. | a. Editing | | | b. Compiling | | | c. Linking | | | d. Executing | | | e. None of the above | |
Correct
Marks for this submission: 1/1.
Question10
Marks: 1
When the final value of an expression is assigned to a variable, it will be converted to :
Choose one answer. | a. The smallest C++ data type | | | b. The largest C++ data type | | | c. The data type of the variable | | | d. The data type of the expression | | | e. None of the above | |
Correct
Marks for this submission: 1/1.
11
Marks: 1
These are data items whose values do not change while the program is running.
Choose one answer. | a. Constants | | | b. Variables | | | c. Comments | | | d. Integers | | | e. #include | |
Correct
Marks for this submission: 1/1.
Question12
Marks: 1
______________ must be included in any program that uses the cout object
Choose one answer. | a. Opening and closing braces | | | b. Comments | | | c. Escape sequences | | | d. the header file iostream | | | e. // | |
Correct
Marks for this submission: 1/1.
Question13
Marks: 1
These type of arguments are passed to parameters automatically if no argument is provided in the function call.
Choose one answer. | a. local | | | b. remote | | | c. default | | | d. global | | | e. relational | |
Correct
Marks for this submission: 1/1.
Question14
Marks: 1
Programmer defined names of memory locations that may hold data are:
Choose one answer. | a. Operators | | | b. Variables | | | c. Syntax | | | d. Operands | | | e. None of the above | |
Correct
Marks for this submission: 1/1.
Question15
Marks: 1
This function tells the cin object to skip one or more characters in the keyboard buffer.
Choose one answer. | a. cin.ignore | | | b. cin.hop | | | c. cin.skip | | | d. cin.jump | | | e. cout.undo | |
Correct
Marks for this submission: 1/1.
16
Marks: 1
When a relational expression is false, it has the value of
Choose one answer. | a. one | | | b. zero | | | c. zero, one or minus one | | | d. less than zero | | | e. two | |
Correct
Marks for this submission: 1/1.
Question17
Marks: 1
The statements in the body of a while loop may never be executed, whereas the statements in body of a do-while loop will be executed
Choose one answer. | a. at least once | | | b. at least twice | | | c. as many times as the user wishes | | | d. never | | | e. forever | |
Correct
Marks for this submission: 1/1.
Question18
Marks: 1
A function can zero to many parameters, and it can return this many values?
Choose one answer. | a. zero to many | | | b. no | | | c. only one | | | d. a maximum of ten | | | e. None of these | |
Correct
Marks for this submission: 1/1.
Question19
Marks: 1
What is the output of the following statement?

cout << 4 * ( 15 / ( 1 + 3 )) << endl;
Choose one answer. | a. 15 | | | b. 12 | | | c. 63 | | | d. 72 | | | e. None of the above | |
Correct
Marks for this submission: 1/1.
Question20
Marks: 1
When used as parameters, these types of variables allow a function to access the parameter's original argument.
Choose one answer. | a. reference | | | b. floating-point | | | c. counter | | | d. undeclared | | | e. None of these | |
Correct
Marks for this submission: 1/1.
21
Marks: 1
Relational operators allow you ____________ numbers.
Choose one answer. | a. add | | | b. multiply | | | c. compare | | | d. average | | | e. None of these | |
Correct
Marks for this submission: 1/1.
Question22
Marks: 1
What is the modulus operator?
Choose one answer. | a. + | | | b. = | | | c. & | | | d. % | | | e. ++ | |
Correct
Marks for this submission: 1/1.
Question23
Marks: 1
What is the output of the following statement?

cout << 4 * (15 / (1 + 3)) << endl;
Choose one answer. | a. 15 | | | b. 12 | | | c. 63 | | | d. 72 | | | e. None of the above | |
Correct
Marks for this submission: 1/1.
Question24
Marks: 1
The operators that add and subtract one from their operands are?
Choose one answer. | a. plus and minus | | | b. ++ and -- | | | c. binary and unary | | | d. conditional and relational | | | e. pre-test and post-test | |
Correct
Marks for this submission: 1/1.
Question25
Marks: 1
What is the value stored at x, given the following statements?

int x; x = 3 / static_cast<int>( 4.5 + 6.4 );
Choose one answer. | a. 3 | | | b. .275229 | | | c. 3.3 | | | d. 0 | | | e. None of the above | |
Correct
Marks for this submission: 1/1.
26
Marks: 1
This type of variable is defined inside a function and is not accessible outside the function.
Choose one answer. | a. global | | | b. reference | | | c. local | | | d. counter | | | e. None of these | |
Correct
Marks for this submission: 1/1.
Question27
Marks: 1
A loop that is contained inside another loop is called
Choose one answer. | a. nested | | | b. infinite | | | c. pre-test | | | d. post-test | | | e. None of these | |
Correct
Marks for this submission: 1/1.
Question28
Marks: 1
Which of the following best describes an operator?
Choose one answer. | a. An operator is a rule that must be followed when constructing a program. | | | b. An operator allow you to perform operations on one or more pieces of data. | | | c. An operator marks the beginning or ending of a statement, or is used to separate items in a list. | | | d. An operator is a word that has a special meaning. | | | e. An operator is a symbolic name that refers to a variable. | |
Correct
Marks for this submission: 1/1.
Question29
Marks: 1
Which statement will read an entire line of input into the following string object?

string address;
Choose one answer. | a. cin << address; | | | b. cin address; | | | c. getline ( cin, address); | | | d. cin.get (address); | | | e. None of the above | |
Correct
Marks for this submission: 1/1.
Question30
Marks: 1
The purpose of a memory address is:
Choose one answer. | a. To identify the location of a byte in memory. | | | b. To prevent multitasking. | | | c. To obtain an algorithm. | | | d. To improve the effectiveness of high-level languages. | | | e. To eliminate redundant code. | |
Correct
Marks for this submission: 1/1.
1
Marks: 1
The _________ sort usually performs fewer exchanges than the ________ sort.
Choose one answer. | a. bubble, selection | | | b. binary, linear | | | c. selection, bubble | | | d. ANSI, ASCII | | | e. None of these | |
Correct
Marks for this submission: 1/1.
Question2
Marks: 1
A ________ search uses a loop to sequentially step through an array.
Choose one answer. | a. binary | | | b. unary | | | c. linear | | | d. relative | | | e. None of these | |
Correct
Marks for this submission: 1/1.
Question3
Marks: 1
The advantage of a linear search is its ____________.
Choose one answer. | a. complexity | | | b. efficiency | | | c. simplicity | | | d. speed | | | e. None of these | |
Correct
Marks for this submission: 1/1.
Question4
Marks: 1
A binary search begins with the _________ element of an array.
Choose one answer. | a. first | | | b. last | | | c. largest | | | d. middle | | | e. None of these | |
Correct
Marks for this submission: 1/1.
Question5
Marks: 1
Using a linear search to find a value that is stored in the last element of an array of 20,000 elements, ____________ element(s) must be compared.
Choose one answer. | a. 20,000 | | | b. only the first | | | c. only half | | | d. 2000 | | | e. None of these | |
Correct
Marks for this submission: 1/1.
Question6
Marks: 1
Data that is sorted in ascending order is ordered
Choose one answer. | a. from lowest to highest value | | | b. from highest to lowest value | | | c. always with a binary sort algorithm | | | d. always with a linear sort algorithm | | | e. None of these | |
Correct
Marks for this submission: 1/1.
Question7
Marks: 1
A ________ algorithm is a method of locating a specific item of information in a larger collection of data.
Choose one answer. | a. sort | | | b. search | | | c. standard | | | d. linear | | | e. None of these | |
Correct
Marks for this submission: 1/1.
Question8
Marks: 1
Regardless of the algorithm being used, a search through an array is always performed
Choose one answer. | a. from lowest to highest element | | | b. from highest to lowest element | | | c. beginning with the middle element | | | d. using a binary search | | | e. None of these | |
Correct
Marks for this submission: 1/1.
Question9
Marks: 1
A ________ search is more efficient than a ________ search
Choose one answer. | a. character, string | | | b. integer, double | | | c. binary, linear | | | d. linear, binary | | | e. None of these | |
Correct
Marks for this submission: 1/1.
Question10
Marks: 1
Array elements must be _________ before a binary search can be performed.
Choose one answer. | a. summed | | | b. set to zero | | | c. sorted | | | d. positive numbers | | | e. None of these | |
Correct
Marks for this submission: 1/1.

1. A binary digit is zero or one 2. What best defines a programming language
It allows us to express an algorithm 3. Which of these is not a programming language?
HTML
4. Which of the following is not true
An algorithm allows ambiguity 5. The programmer solves the problems of a user by expressing an algorithm in a programming language to make a program that can run on a computer. 6. Which statement is not true
Machine language can be used to write programs that can run on any machine 7. A compiler
Translate source code into executable code 8. The ability to a language to let a programmer develop a program on computer system that can be run on other systems is called: portability 9. The code that a programmer writes is called: source code 10. Compilers translate the instructions written by the programmer into: object code 11. The rules that govern the correct order and usage of the elements of a language are called the: syntax of the language 12. Words that have a special meaning in a programming language are called: key words 13. Which of the following is true?
There are no language rules regarding statements and line in general 14. A location in memory used for storing data and given a name in a computer program is called a: variable, because the data in the location can be changed. 15. Before a variable is used it must be: defined 16. The names defined in iostream are associated with which namespace? STD 17. Rearrange the following code so that it forms a correct program that prints out the letter Q:
// A SCRAMBLED program

#include <iostream> using namespace std; int main()
{
cout << "Q"; return 0;
}
18. Which of the following will not be recognized if iostream is not included in the program?: cout 19. Write a literal representing the integer value zero. : 0 20. Which of the following is not a legal identifier?: 7thheaven 21. Which is the best identifier for a variable to represent the amount of the money your boss pays you each month? Monthlypay 22. Write a declaration of a variable named number_of_children that can be used to hold the number of children in a family. int number_of_children; 23. Write a declaration for two integer variables, age and weight.: int age, weight; 24. Declare a character variable named c .: char c 25. How many bytes are needed to store: 'n' ? 1 26. How many bytes are needed to store: "n" ? 2 27. How many bytes are needed to store: '\n' ? 1 28. How many bytes are needed to store: "\n", ? 2 29. How many bytes are needed to store: "\\n" ? 3 30. How many bytes are needed to store: "" ? 1 31. Write a declaration for a variable temperature that can hold the current outdoor temperature, measured to the half degree (like 98.6 or 31.5).: float temperature; 32. 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 any thing else. cout << num << " " << cost <<endl; 33. The character escape sequence to force the cursor to go to the next line is: \n 34. The character escape sequence to force the cursor to advance forward to the next tab setting is: \t 35. The character escape sequence to represent a single quote is: \' 36. The character escape sequence to represent a double quote is: \" 37. The character escape sequence to represent a backslash is: \\ 38. How many spaces printed out by this statement: cout << "how" << "now" << "brown" << "cow" << "?"; : 0 39. How many spaces printed out by this statement: cout << "abc\ndef\tghi\njkl" << endl << endl << "mno\n\npqr\n"; : 6 40. Given: an int variable k , an int array currentMembers that has been declared and initialized, an int variable nMembers that contains the number of elements in the array, an int variable memberID that has been initialized, and a bool variable isAMember ,

isAMember = false; for(k=0; k<nMembers; k++) if(currentMembers[k] == memberID) isAMember = true;

41. Write a statement that reads a word from standard input into firstWord. Assume that firstWord. has already been declared as an char array large enough to hold a 50-letter word. : cin >> firstWord; 42. The exercise instructions here are LONG -- please read them all carefully. If you see an internal scrollbar to the right of these instructions, be sure to scroll down to read everything.

Declare and initialize the following variables:
A variable monthOfYear , initialized to the value 11
A variable companyRevenue , initialized to the value 5666777
A variable firstClassTicketPrice , initialized to the value 6000
A variable totalPopulation , initialized to the value 1222333 int monthOfYear=11; long companyRevenue=5666777; int firstClassTicketPrice=6000; long totalPopulation=1222333;

43. Write a declaration of an int variable year and initialize it to 365. int year = 365; 44. Given two integer variables num and highest, write a statement that gives highest the same value that num has.: highest=num; 45. Write a statement that prints the following to standard output: i= Just write one statement that generates the message above: do not generate any extraneous spaces. Do not declare variables, do not write a main() function, do not write a whole program. cout << "i="; 46. Given an integer variable count, write a statement that writes the value of count to standard output. cout << count; 47. Given three already declared int variables, i , j , and temp , write some code that swaps the values in i and j . Use temp to hold the value of i and then assign j 's value to i . The original value of i , which was saved in temp , can now be assigned to j . temp=i; i=j; j=temp; 48. Write the necessary preprocessor directive to enable the use of functions like sqrt and sin. : #include <cmath> 49. The area of a square is stored in a double variable named area . Write an expression whose value is length of one side of the square. : sqrt(area) 50. Write the necessary preprocessor directive to enable the use of the time function. : #include <ctime> 51. You are given an int variable k , an int array zipcodeList that has been declared and initialized, an int variable nZips that contains the number of elements in zipcodeList , and a bool variable duplicates .

Write some code that assigns true to duplicates if there are two adjacent elements in the array that have the same value, and that assigns false to duplicates otherwise.

Use only k , zipcodeList , nZips , and duplicates .
Answer:
duplicates=false; for (k=0; k<nZips-1; k++) if (zipcodeList[k]==zipcodeList[k+1]) { duplicates=true; break;
}

52. You are given two int variables j and k , an int array zipcodeList that has been declared and initialized, an int variable nZips that contains the number of elements in zipcodeList , and a bool variable duplicates .

Write some code that assigns true to duplicates if any two elements in the array have the same value, and that assigns false to duplicates otherwise.

Use only j , k , zipcodeList , nZips , and duplicates .
Answer:
duplicates=false; for (k=0; k<nZips; k++) for (j=0; j<k; j++) { if ( zipcodeList[j]==zipcodeList[k]) { duplicates=true; break; }
}

53. Given an int variable k , an int array incompletes that has been declared and initialized, an int variable nIncompletes that contains the number of elements in the array, an int variable studentID that has been initialized, and an int variable numberOfIncompletes ,
Answer:
numberOfIncompletes=0; for (k=0; k<nIncompletes; k++) if (incompletes[k] == studentID) numberOfIncompletes++; 54. Given a double variable named x that has been declared and given a value, let's use a binary search technique to assign an estimate of its square root to another double variable, root that has also been declared. Let's assume that x's value is greater than 1.0 -- that will simplify things a bit. Here's the general idea:

Since x>1, we know its square root must be between 1 and x itself. So declare two other variables of type double (a and b say) and initialize them to 1 and x respectively. So we know the square root must be between a and b. Our strategy is to change a and b and make them closer and closer to each other but alway make sure that the root we're looking for is between them. (Such a condition that must always hold is called an invariant.)

To do this we will have a loop that at each step finds the midpoint of a and b. It then squares this midpoint value and if the square of the midpoint is less than x we know that the root of x must be bigger than this midpoint: so we assign the midpoint to a (making a bigger and shrinking our a and b interval by half!)-- and we still can be sure that the root is between a and b. Of course if the midpoint's square is greater than x we do the opposite: we assign b the value of midpoint.

But when to stop the loop? In this exercise, just stop when the interval between a and b is less than 0.00001 and assign root the midpoint of a and b then.

We call this a binary search also because at each stage we cut the interval under consideration in half. Efficient as this method is, old Isaac Newton discovered an algorithm that is even more efficient and that's what the library function sqrt uses.

Answer: const double PRECISION = 0.00001; double a = 1; double b,mid; b=x; while ((b-a)>PRECISION)
{
root = (a+b)/2; if (root*root < x) a = root; else b=root;
}

55. Given an array arr of type int , along with two int variables i and j , write some code that swaps the values of arr[i] and arr[j] . Declare any additional variables as necessary.
Answer:
int temp=arr[i]; arr[i]=arr[j]; arr[j]=temp;

56. Write the definition of a function named isSorted that receives three arguments: an array of int, an int that indicates the number of elements of interest in the array, and a bool.

If the bool argument is true then the function returns true if and only if the array is sorted in ascending order. If the bool argument is false then the function returns true if and only if the array is sorted in descending order. In all other cases the function returns false.

You may assume that the array has at least two elements.
Answer:
bool isSorted(int a[], int n, bool status)
{
bool flag = true; if(status == true) { for (int i=0; i<n-1; i++) if (a[i] > a[i+1]) flag = false; } else { for (int i=n-1; i > 0; i--) if (a[i] > a[i-1]) flag = false; } return flag;
}

57. Assume you have a int variable n that has already been declared and initialized. Its value is the number of integers that need to be read in from standard input and printed out in sorted (ascending) order, each on a line by itself. Furthermore, there are no duplicates in the input and every number to be read is a non-negative value that is less than n's value.

In this exercise you may not use any array (or fancy STL collection such as a vector). You may declare a variable or two as needed. With these restrictions, read the n values and print them out as required onto standard output.
Answer:
int x=0;

for (int i=0; i<n; i++)
{
cin >> x; cout << i << "\n";
}
58. Write a fragment of code that reads in integers from standard input, until end-of-file and sends their (floating point) average to standard output. If no numbers are input, the message “no values to average” is printed instead (while loops, end-of-file processing, mixed-mode arithmetic, basic conditional)
Answer:
float number=-1; float count=0; float sum=0;

while(cin.eof()==false)
{
cin >> number; sum += number; count++;
}

if(number==-1)
{
cout << "no values to average";
}
else{ if (count>0) cout << sum/count;
}

59. You are given an array x of int elements along with an int variable n that contains the number of elements in the array. There are no duplicates in this array. You are also given an int variable m that has been declared. Assign to m the median value of the array.

NOTE: The median of a set of numbers is the number in the set such that there are as many numbers above that value as there are below. If the set has an even number of members, the median is the average of the pair of numbers such that there are as many numbers above the pair as there are below.

EXAMPLE 1: Given 5 8 1 9 7 the median is 7 because there are two numbers below (1 5) and two numbers above (8 9).

EXAMPLE 2: Given 3 7 1 4 6 9 the median is the average of 4 and 6 because there are two numbers above 4 and 6 (7 9) and two numbers below (3 1).
Answer:
int temp;

for (int i=0; i<n; i++)
{
for (int j=i+1; j<n; j++) { if (x[i]>x[j]) { temp=x[j]; x[j]=x[i]; x[i]=temp; } }
}

if (n % 2==0) m=(x[(n/2)-1] + x[(n/2)]) / 2; else m=x[n/2];

60. You are given an array x of string elements along with an int variable n that contains the number of elements in the array. You are also given a string variable mode that has been declared. Assign to mode the mode value of the array. (Assume there are no "ties".)

NOTE: The mode is the value that occurs most frequently.

EXAMPLE: Given "msft" "appl" "msft" "csco" "ibm" "csco" "msft", the mode is "msft" because it appears the most number of times in the list.
Answer:
string temp; string test; int count=1; int max=1;

for (int i=0; i<n; i++) for (int j=0; j<n; j++) if (x[i]>x[j]) { temp=x[i]; x[i]=x[j]; x[j]=temp; }

test = "-"; max=0; count=0;

for (int i=0; i<n; i++) { if (x[i]==test) { count++; if (count>max) { mode=test; max=count; } } else { test=x[i]; count=1; } } 61. Modify the solution to exercise 11186 so that it can handle duplicates in the input. Hint: change the bool array to an array of int. The instructions for 11186 are repeated below:

11186: In this exercise, you will write some code that reads n unique (no duplicates!) non-negative integers, each one less than fifty (50). Your code will print them in sorted order without using any nested loops-- potentially very efficient! We'll walk you through this:

First, assume you are given an int variable n, that contains the number of integers to read from standard input.

Also assume you are given an array, named wasReadIn, of fifty (50) bool elements and initialize all the elements to false.

Third, read in the n integers from the input, and each time you read an integer, use it as an index into the bool array, and assign that element to be true-- thus "marking" in the array which numbers have been read.

Lastly the "punchline": write a loop that traverses the bool array: every time it finds an element that is true it prints out the element's INDEX -- which was one of the integers read in. Place all the numbers on a single line, separated by a single spaces. Note: this technique is not limited to 50 elements-- it works just as well for larger values. Thus, for example you could have an array of 1,000,000 elements (that's right-- one million!) and use it to sort numbers up to 1,000,000 in value!
Answer:
int number;

for (int i=0; i<50; i++)
{
wasReadIn[i]=0;
}

for (int i=0; i<n; i++)
{
cin >> number; wasReadIn[number]++;
}

for(int i=0; i<50; i++) if(wasReadIn[i]>0) for(int j=0; j<wasReadIn[i]; j++) cout << i << " ";

62. In this exercise, you will write some code that reads n unique (no duplicates!) non-negative integers, each one less than fifty (50). Your code will print them in sorted order without using any nested loops-- potentially very efficient! We'll walk you through this:

First, assume you are given an int variable n, that contains the number of integers to read from standard input.

Also assume you are given an array, named wasReadIn, of fifty (50) bool elements and initialize all the elements to false.

Third, read in the n integers from the input, and each time you read an integer, use it as an index into the bool array, and assign that element to be true-- thus "marking" in the array which numbers have been read.

Lastly the "punchline": write a loop that traverses the bool array: every time it finds an element that is true it prints out the element's INDEX -- which was one of the integers read in. Place all the numbers on a single line, separated by a single spaces. Note: this technique is not limited to 50 elements-- it works just as well for larger values. Thus, for example you could have an array of 1,000,000 elements (that's right-- one million!) and use it to sort numbers up to 1,000,000 in value!
Answer:
int number;

for (int i=0; i<50; i++) wasReadIn[i]=0;

for (int i=0; i<n; i++)
{
cin >> number; wasReadIn[number]=1;
}

for (int i=0; i<50; i++)
{
if (wasReadIn[i]==1) cout << i << " ";
}

63. Write a statement to declare and initialize an array of int named denominations that contains exactly six elements.

Your declaration statement should initialize the elements of the array to the following values: 1, 5, 10, 25, 50, 100. (The value 1 goes into the first element; the value 100 to the last.)
Answer:
int denominations[6] = {1,5,10,25,50,100}; 64. Given an array temps of double , containing temperature data, and an int variable n that contains the number of elements in temps :

Compute the average temperature and store it in a variable called avgTemp .

Besides temps , n , and avgTemp , you may use only two other variables -- an int variable k and a double variable total , which have been declared.
Answer:
total=0; for (k=0; k<n; k++)
{
total += temps[k];
}

avgTemp =total/n; 65. We informally define the term "corresponding element" as follows: The first element in an array and the last element of the array are corresponding elements. Similarly, the second element and the element just before the last element are corresponding elements. The third element and the element just before the element just before the last element are corresponding elements -- and so on.

Given an array a and a variable n that contains the number of elements in a , write an expression for the corresponding element of a[i] .
Answer:
a[n-i-1] 66. Reversing the elements of an array involves swapping the corresponding elements of the array: the first with the last, the second with the next to the last, and so on, all the way to the middle of the array.

Given an array a , an int variable n containing the number of elements in a , and two other int variables, k and temp , write a loop that reverses the elements of the array.
Answer:
for (int k=0; k<n/2; k++)
{
temp=a[k]; a[k]=a[n-k-1]; a[n-k-1]=temp;
}
67. An array of integers named parkingTickets has been declared and initialized to the number of parking tickets given out by the city police each day since the beginning of the current year. (Thus, the first element of the array contains the number of tickets given on January 1; the last element contains the number of tickets given today.)

A variable named ndays has been declared and initialized to hold the size of the array. (Thus, if today were January 18, ndays would have the value 18; if today were February 3, ndays would have the value 34.)

In addition, a variable named mostTickets has been declared, along with a variable k .

Without using any additional variables, and without changing the values of ndays or the elements of the parkingTickets array, write some code that results in mostTickets containing the largest value found in parkingTickets .
Answer:
mostTickets=0; for (k=0; k< ndays; k++)
{
if (parkingTickets[k]>mostTickets) mostTickets=parkingTickets[k];
}

68. Assume that two parallel arrays have been declared and initialized: healthOption an array of type char that contains letter codes for different healthcare options and annualCost an array of type int. The i-th element of annualCost indicates the annual cost of the i-th element of healthOption. In addition, there is an char variable, best2.Write the code necessary to assign to best2 the health option with the lower annual cost, considering only the first two healthcare options.

Thus, if the values of healthOption are 'B', 'Q', 'W', 'Z' and the values of annualCost are 8430, 9400, 7050, 6400 your code would assign 'B' to best2 because 8430 is less than 9400 and is associated with 'B' in the parallel array. (We ignore 'W' and 'Z' because we are considering only the first two options.)
Answer:
if (annualCost[0]<annualCost[1]) best2=healthOption[0]; else best2=healthOption[1]; 69. printArray is a function that has two parameters. The first parameter is an array of element type int and the second is an int , the number of elements in the array. The function prints the contents of the array parameter; it does not return a value.

inventory is an array of int s that has been already declared and filled with values. n is an int variable that holds the number of elements in the array.

Write a statement that prints the contents of the array inventory by calling the function printArray .
Answer:
printArray(inventory,n); 70. Write a statement that declares a prototype for a function printArray , which has two parameters. The first parameter is an array of element type int and the second is an int , the number of elements in the array. The function does not return a value.
Answer:
void printArray(int [], int); 71. Write the definition of a function printArray , which has two parameters. The first parameter is an array of int s and the second is an int , the number of elements in the array. The function does not return a value. The function prints out each element of the array, on a line by itself, in the order the elements appear in the array, and does not print anything else.
Answer:
void printArray (int s[],int n)
{
for (int k=0; k<n; k++) cout << s[k] << endl;

} 72. Write the definition of a function named sumArray that receives two parameters: an array of element type int and an int that contains the number of elements of the array. The function returns the sum of the elements of the array as an int .
Answer:
int sumArray (int s[], int n)
{
int sum=0; for(int k=0; k<n; k++) sum += s[k];

return sum;
}
73. Write the definition of a function, isReverse , whose first two parameters are arrays of integers of equal size, and whose third parameter is an integer indicating the size of each array. The function returns true if and only if one array is the reverse of the other. ("Reverse" here means same elements but in reverse order.)
Answer:
bool isReverse (int one[], int two[], int size)
{
int matches=0; for (int k=0; k<size; k++) { if (one[k] == two[size-k-1]) { matches++; } } if (matches==size) return true; else return false;
}
74. Write the definition of a function reverse , whose first parameter is an array of integers and whose second parameter is the number of elements in the array. The function reverses the elements of the array. The function does not return a value.
Answer:
void reverse (int a[], int n)
{
int temp; for (int k=0; k<n/2; k++) { temp=a[k]; a[k]=a[n-k-1]; a[n-k-1]=temp; }
}
75.

Similar Documents