CPE 211 Final exam

Ace your homework & exams now with Quizwiz!

In C++ capitalization of identifiers does not matter because identifers NAME and name are considered to be the same identifier by the compiler?

false

In C++ mathematical expressions addition and subtraction are performed before multiplication and division?

false

In C++ when using the open function, the argument for the open function must be a string variable

false

In a switch statement there must be at least one case label

false

In a switch statement, a char variable can be used as a case label

false

In an assignment statement more than 1 variable can be present on the left hand side of the statement - i.e. x + y =30; is a valid assignment statement

false

The #include statements in a C++ program are interpreted by the compiler?

false

The following C++ statement is an example of type casting the integer variable num to a floating point value: int num;float var;var = (num)float;

false

The getline function reads the next character only from the input stream regardless of what it is?

false

The getline function skips all whitespace characters when reading from the input stream?

false

Value returning functions can use the statement return;

false

When an input file stream goes into the fail state, the program is terminated and an error message is written to the terminal.

false

in C++, void functions return a single function value?

false

Which of the following logical expressions evaluate as true?

false||true true||false true||true

What is the definition for a function heading?

first line of the function definition that contains the name of the function, the return type of the function and the function parameter declarations

Which of the following functions is used to associate a file on the hard drive with a declared file stream variable

open

Which of the following statements will associate the file out.txt with the output file stream variable outFile? (assume all variables and file streams have been declared correctly and that all header files are present)

outFile.open("out.txt");

In C++ the following assignment statement is valid? num1 = num2 = num3 = num4 = 0;

true

In a switch statement there can be 0 or more statements associated with a Switch Label?

true

The ignore statement cin.ignore(20); will always ignore 20 characters on the input stream cin?

true

The result of a logical expression using the OR (||) logical operator is true if at least one of the operands is a boolean true value?

true

The return value for a value returning function can be ignored by making the function call a standalone statement and not part of an expression?

true

The statement cin.get(ch); obtains the next character, regardless of what it is, from the standard input stream cin? (ch is declared as a character variable)

true

Typically, information is lost when a floating point value is coerced to an integer value.

true

Value Returning Functions are used in expressions like variables are?

true

Value parameters receive a copy of an arguments value

true

When an input file stream goes into the fail state, the program continues running, there are no warnings or errors written to the terminal and all future statements associated with that input stream are ignored?

true

When using the extraction operation to read from an input stream, the leading white space characters (tabs,spaces and newlines) will be skipped?

true

in C++ the following statement will decrement the variable num by 1? --num;

true

in C++ the following statement will increment num by 1? num++;

true

in C++ the string function find returns the value string::npos when the value it is looking for is not found?

true

Which of the following logical expressions evaluate as true?

true&&true

Which of the following are allowed aggregate operations on a structure?

used as a parameter in a function Return value of a value returning function Assignment

Which of the following are allowed aggregate operations on Arrays?

used as a parameter in a function heading

Which of the following are logical operators for C++? More than one answer can be selected

! || &&

Write a count controlled loop that will output the numbers 1, 2, 3, 4 and 5 (one per line)

#include <iostream> using namespace std; int main(){ int a = 0; while (a <= 5){ a++; cout<<a<<endl; } return 0; }

What is the output for the following code segment? a = 40;i f (a>20) cout << "20"; else if (a > 30) cout << "30"; else if (a > 40) cout << "40";

20

What is the value output for sum in the following segment of code? Note: the comment is correct int sum = 0; int j = 1; do{ if ( j%3 != 0 ) // true if j is not divisible by 3 sum = sum +j; j++;}while(j < 10); cout << sum;

27

How many times does the body of the following while loop execute? int count = 0; while (count < 12){ count = count + 4; }

3

What is the output for the following switch statement: int num = 0; while (num < 5){ switch(num) { case 1:cout << "1"; case 2:cout << "2"; break; case 3:cout << "3"; default:cout << "4"; } num++; }

4122344

When the following code is executed, how many iterations of the loop are performed? int number = 1; bool notDone = true; do{ number=number*2; notDone = (number < 32); }while (notDone);

5

Given the code segment below, string firstName = "Samuel"; cout << firstName.size(); what is the value output by the output statement?

6

Assignment statement

A statement that stores the value of an expression into a variable

Function Call

A statement that transfers control to a function

Event Counter

A variable that is incremented each time an even occurs

Write the declaration for the identifier customer to be a variable of the structure data type Address declared above

Address customer;

In C++ capitalization of identifiers does not matter because identifiers NAME and name are considered to be the same identifier by the compiler?

False

In C++ it is a syntax error if a loop is declared inside the body of another loop? - (in other words it is illegal in c++ to nest loops)

False

In C++ the compiler checks to make sure that all index values are valid (correspond to memory allocated for the array)

False

In C++ when using the open function, the argument for the open function must be a string variable

False

In a loop, event counters are incremented every time the loop body is executed.

False

In a switch statement, a variable can be used as a case label?

False

In a switch statement, if the switch expression matches a case label, control branches to the statements associated with the default label?

False

In an assignment statement more than 1 variable can be present on the left hand side of the statement - i.e. x + y =30; is a valid assignment statement

False

In an if-then-else-if logic statement, all logical expressions are always evaluated

False

Local variables declared inside a block statement can be accessed out of that block statement?

False

The Arguments corresponding to reference parameters cannot be variables

False

The body of a for loop executes one or more times.

False

The default label is required in a switch statement?

False

The following C++ statement is an example of type casting the integer variable num to a floating point value: int num; float var; var = (num)float;

False

The following function call will pass the one dimensional array value into the void function Read? Read(value[ ]);

False

The initialization of the static variable in the declaration shown below occurs every time the statement is encounterd? static int count = 0;

False

The statement getline(cin, str1); reads an entire line ending in a ? into the string variable str1?

False

When a continue statement is executed, the innermost loop in which it appears is exited.

False

When the structure declaration is encountered memory is allocated for the declaration.

False

With a specific structure, the member names do not have to be unique?

False

he following is a valid function prototype with a 2 dimensional array as a parameter? void InitArray(floatArray[ ][ ]);

False

in C++ the result of the integer division of 6/4 is 1.5?

False

in C++, void functions return a single function value?

False

in an array, the component items can be of different data types - the array is heterogeneous.

False

the function call for a void function has to be made as part of an expression?

False

void function calls must occur as part of an expression?

False

What is the definition for a function definition?

The code that extends from the function heading to the end of the block that is the body of the function

Switch Expression

The expression whose value determines which switch label is selected

Syntax

The formal rules governing how valid instructions are written in a programming language.

Lifetime

The period of time during the execution of a program that an identifier has memory allocated to it

Name Precedence

The precedence that a local identifier has over a global identifier with the same name

Semantics

The set of rules that determine the meaning of instructions written in a programming language

What is the definition for a function call?

The statement that transfers control to a function

A boolean variable can be considered to be a logical expression

True

A break statement causes the immediate exit from the loop or switch statement in which it appears?

True

A break statement is optional in a switch statement

True

A hierarchical structure is a structure in which at least one of the members of the structure is itself a structure?

True

A structure declaration must end with a semi-colon?

True

A value parameter is automatically initialized to the value of the corresponding argument.

True

By default arrays are always passed by reference into a function

True

Every C++ program must have a function named start

True

Four_4 is a valid identifer in C++ (following strict ANSII C++ standards and material presented in lecture notes)

True

In C++ any non-zero integer value is coerced to a boolean value of true

True

In C++ the following assignment statement is valid? num1 = num2 = num3 = num4 = 0;

True

In a C++ program identifiers used in the program must be unique?

True

In an array each component item of the array is accessed by its position in the array

True

In sentinel-controlled loops, the sentinel should be a value that is not expected as normal input.

True

Local variables cannot be accessed outside of the block in which they are declared?

True

Logical operators can take logical expressions as operands?

True

Reference parameters receive the memory address of the corresponding argument?

True

Static variables maintain their value from function call to function call

True

The C++ statement std::cout << "Hello\n"; shows an example of the name qualification method for accessing the standard output stream cout?

True

The base address of an array is the memory address corresponding to index value 0 for the array?

True

The body of a while loop will execute zero or more times depending on the status of the while expression that is tested?

True

The default switch label is optional in a switch statement.

True

The end of file status bit is changed from false to true when an attempt is made to read beyond the end of an input file?

True

The following is a valid array declaration in C++: float arr[][3] = { {1.0, 2.0, 3.0}, {3, 2, 1}};

True

The ignore statement cin.ignore(20); will always ignore 20 characters on the input stream cin?

True

The insertion operator << is used to insert information into the output file stream in C++?

True

The lifetime of an identifier is the time when memory has been allocated for use by that identifier?

True

The memory allocated to a static variable remains allocated for the duration of the execution of the program?

True

The statement cin.get(ch); obtains the next character, regardless of what it is, from the standard input stream cin? (ch is declared as a character variable)

True

The two character sequence \n is used to represent the new line character in C++ and it can be stroed in a character variable?

True

Typically, information is lost when a floating point value is coerced to an integer value.

True

Void functions do not need to use a return statement

True

When a break statement is executed, the loop in which it appears is exited.

True

When local variables are declared, they start with their values undefined?

True

When used with a file stream, the clear() function will reset all the status bits for the file stream so that it can be used again.

True

in C++ the following statement will increment num by 1? num++;

True

In C++ using strict ANSII standard C++ (and as mentioned for this course), identifiers can start with what character(s) (more than one answer is possible)?

Underscores Letters

Which of the following can be used as arguments in a function call when the argument is paired up with a reference parameter?

Variables

If x=10 and y=10, What is the boolean value for the relational expression: x != y

False

A global identifier takes precedence over a local identifier with the same name?

false

For sentinel controlled loops, the best sentinel is a value that IS expected as normal input for the program?

false

Data Type

A specific set of values along with a set of operations on those values

Write a sentinel controlled loop that prompts the user to enter a number, reads the number and continues to loop prompting for and reading numbers until the number entered is greater than 0. Do not forget the priming read. This loop is just prompting for and reading in a number - it is not doing any processing on that number.

#include <iostream> using namespace std; int main(){ int a; cout<<"enter a number:"; cin>>a; while (a <= 0){cout<<"enter a number:"; cin>>a; } return 0; }

In C++, which of the following operators are valid integer math operators?

% * + / -

What is the member selector operator that is used to access the members of a structure variable?

. (a period)

In C++, which of the following operators are valid integer math operators?

/ * + %

Which of the following is a way to put a comment into a C++ program?

/* comment */

Which of the following is a way to put a comment into a C++ program?

//

Given the code segment below: string plant = "Daisy"; cout << plant.find('D'); What is the value output by the output statement?

0

Given the following variable declarations and assignments, evaluate the C++ expression shown. Remember that evaluation proceeds from left to right following an order of precedence for the operations. int a = 4, b = 2, c = 6, d = 8; float x = 4.0, z = 15.0; What is the value of this expression: d - (d+1)/b*b

0

What is the output of the following loop segment? int a = 0; int sum = 0 while (a >= 5){ sum = sum + a; a++; } cout << sum << endl;

0

What is the output of the following loop? int a = 0; while (a <= 5) { cout << a;a++; } cout << endl << "done\n";

012345 done

A value returning function can return how many function values?

1

What is the output for the following do-while loop? int num = 0; do{ num++; cout << num << "-"; }while(num < 5);

1-2-3-4-5-

Declaration

A statement that associates an identifier with a data object, a function, or a data type

Given the following variable declarations and assignments, evaluate the C++ expression shown. Remember that evaluation proceeds from left to right following an order of precedence for the operations. int a = 4, b = 2, c = 6, d = 8; float x = 4.0, z = 15.0; What is the value of this expression: (4*8)%3 + d/3*b

6

What is the output for the following segment of code? (Hint: be careful on this problem- look at all parts of the for statement) int sum = 100; int j; for (j = 10; j > 5; j--) sum -= j;cout << sum;

60

Before the code shown below is executed, the input stream (cin) contains the following characters (\n represents the new line character) : 500B\nHello 66\n44\n33and the reading marker is on the 5 Using the space provided, write what is output to the terminal by the following segment of code. int m = 10; int x = 20; string text = "Null"; char ch = 'A';getline(cin,text,'\n'); cin.ignore(5,'\n'); cin >> m >> ch; cout << m << "-" << ch << "-" << x << "-" << text << endl; xt << endl;

66-4-20-500B

Which of the choices below are relational operators? More than one answer can be selected

== > = <=

Function Prototype

A function declaration without the body of a function

Named Constant

A location in memory referenced by an identifier, that contains a data value that cannot be changed

Variable

A location in memory, referenced by an identifier, that contains a data value that can be changed

Count Controlled Loop

A loop the executes a specified number of times

Value Parameter

A parameter that receives a value of the corresponding argument

Reference Parameter

A parameter that receives the memory address of the corresponding argument

Relational Expression

An expression followed by a relational operator followed by an expression that evaluates to a logical value of true or false

Logical Expression

An expression made up of logical values and operators that evaluates to a logical value of true or false

Literal value

Any constant value written directly into a program

Which of the following is a problem solving technique mentioned in the slides for chapter 1?

Divide and Conquer

Which of the following are types of Event Controlled Loops?

EndOfFile controlled Sentinel Controlled Flag Controlled

A continue statement will cause the immediate exit of the loop in which it appears?

False

A relational expression is an expression followed by a logical operator followed by another expression?

False

A simple data type is a DataType in which each value is a collection of component items.

False

Global identifiers have name precedence over local identifiers.

False

An expression is an arrangement of ____________, _________________ and ______________ that can be evaluated to compute a value of a given type.

Identifiers Literals Operators

What are the three versions of the if statement discussed in the lecture notes and example programs?

If-Then-Else If-Then If-Then-Else-If

finish the code segment below by selecting the statement that will open the input file specified (typed in) by the user: ifstream InFile; string filename; cout << "enter the name of the input file: "; cin >> filename;

InFile.open(filename.c_str());

Which of the following data types can be used as a switch expression?

Integer Character Boolean

In C++ using strict ANSII standard C++ (and as mentioned for this course), identifiers can start with what character(s) (more than one answer is possible)?

Letters Underscore

For this course and following the strict ANSI C++ standard, which of the following are allowed characters for identifiers(select all that apply)

Letters Underscore Digits(Numbers)

Value parameters (passing by value) are used if the argument-parameter data flow is

One Way into the Function

Reference Parameters (passing by reference) are used if the argument-parameter data flow is:

One-Way, out of the function Two-Way, into and out of the function

An expression is an arrangement of ____________, _________________ and ______________ that can be evaluated to compute a value of a given type.

Operations Literals Identifiers

From the notes and text, "The set of rules determining the meaning of the instructions written" is the definition for _______________________

Semantics

Which of the following are ways to structure statements in most programming languages(more than one answer is possible here. you need to select them all)

Sequentially Loop Subprogram Selection

There are three functions shown in the code segment below. Assume all variables and function prototypes have been correctly declared before this segment of code. Sum(number,sum); result = sum*Average(value); status = WriteInfo(outFile, result); Which function(s) is(are) most likely void function(s)?

Sum

There are three functions shown in the code segment below. Assume all variables and function prototypes have been correctly declared before this segment of code. Sum(number,sum); result = sum*Average(value); status = WriteInfo(outFile, result); Which function(s) is(are) most likely value-returning function(s)?

WriteInfo Average

Which of the following is a valid Named Constant Declaration in C++?

const string NAME = "Elm";

The implementation phase of computer programming involves which one of the following:

converting the algorithm steps into a programming language

What Linux command is used to copy a file?

cp

For the structure variable customer declared in question 8 above, write a statement that will assign the value of Alabama to the state member.

customer.state = "Alabama";

For the structure variable customer declared in question 8 above, write a statement that will assign the value of 12345 to the zip member.

customer.zip = 12345;

For the code segment below, what is the value output if the user types in 1 A 2 (select the best possible answer) int num1, num2, num3;] cout << "Enter in 3 integers\n"; cin >> num1 >> num2 >> num3; cout << num3;

do not know - file stream went into fail state

For the code segment below, what is the value output if the user types in 1 A 2 (select the best possible answer) int num1, num2, num3; cout << "Enter in 3 integers\n"; cin >> num1 >> num2 >> num3; cout << num3;

do not know - file stream went into fail state

What are the two main types of loops mentioned in class and in the text?

event controlled count controlled

Which of the following are functions that return the boolean status of a file stream status bit?

fail() good() eof()

Which of the following methods can be used to read/remove information from an input stream?

getline ignore get extraction

A switch expression can be which of the following (Select all correct answers):

integer bool char

What Linux command is used to view the contents of a directory?

ls

What Linux command is used to create a directory?

mkdir

What Linux command is used to obtain the current working directory path of a terminal window?(the command that shows you what directory you are in)

pwd

What Linux command is used to delete a file in a directory?

rm

What Linux command is used to delete a directory (provided that the directory is empty)?

rmdir

Which of the following are output file stream manipulators?

setprecission left showpoint

Which of the following are output file stream manipulators?

setw fixed endl

The following C++ statement can be used to do what in a program? cin.ignore(30,'?');

skip 30 characters or skip characters until a ? is encountered - whichever occurs first

Given the code segment below: string plant = "Daisy"; cout << plant.find('A'); What is the value output by the output statement?

string::npos

From the notes and text, "The formal rules for governing how valid instructions are written" is the definition for _______________________

syntax

Given the C++ code segment below, string str1, str2; str1 = "The_third_Quiz_in_CPE211"; str2 = str1.substr(4,8);cout << str2; What is the string value output by the output statement?

third_Qu

Given the C++ code segment below, string str1, str2;str1 = "The_third_Quiz_in_CPE211"; str2 = str1.substr(4,8); cout << str2; What is the string value output by the output statement?

third_Qu

The job of a compiler is to do what?

translate a high level programming language into machine language

The void function named GetNums has two parameters A pass-by-value parameter named x of type float A pass-by-reference parameter named num of type int. Given the description of the above parameters for the function GetNums, which of the following choices is a valid function heading? (possibly more than one answer)

void GetNums( float x , int& num )

The void function named GetNums has two parameters A pass-by-reference parameter named x of type float A pass-by-value parameter named num of type int. For the description of the above parameters for the function GetNums, which of the following choices are valid function prototypes? (possibly more than one answer)

void GetNums( float& , int );

Which of the following is/are a valid function heading for the void function InitArray that will initialize a one dimensional array of integers

void InitArray(int arr[ ]) void InitArray(int arr[10])

Which of the following answers are a possible function heading for a void function named Input that requires two parameters an input file stream and an integer value that has to be passed back to the caller of the function

void Input(ifstream& fileIn, int& value)

A function that does not return a function value is known as what kind of function?

void function

Static Variable

was not listed on test, may be listed here

Which of the following are Logical operators?

|| <= == != && > !(Maybe? we can't see the correct answer)


Related study sets

AP WORLD HISTORY 4.5 ECONOMIC SYSTEMS

View Set

Ch 21 Mgmt of labor and birth risks

View Set

Chapter 9: Business Cycles, Unemployment, and Inflation

View Set

M09 Chapter 6 Input Sensor AUTI 131

View Set

Ch. 19 Exam Questions (Life/Health)- Oklahoma Life and Health Insurance Laws and Rules

View Set