SA C++ Quizlet

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

What is the value of x after the following statements? double x; x = 0; x += 3.0 * 4.0; x -= 2.0; A 10.0 B 12.0 C 22.0 D 14.0

A 10.0

What is the value of x after the following code executes? int x=10; if(x++ >10) { x =13; } A 11 B 9 C 13 D 10

A 11

What is the output of the following code fragment? int x=0; { int x=13; cout << x <<","; } cout << x << endl; A 13,0 B 13,13 C Nothing, there is a syntax error. D 0,13

A 13,0

What is the value returned by the following function? int function() { int value = 35; return value + 5; value += 10; } A 40 B 35 C 50 D 10

A 40

Which of the following statements is NOT legal? A char ch="cc"; B char ch=65; C char ch='0'; D char ch='b';

A char ch="cc";

Which of the following is NOT considered a phase of the program-design process? A marketing the program B implementation C problem-solving

A marketing the program

What is wrong with the following statement?cout << "Hello to everyone\n" A missing a semicolon B cout should be count. C missing a ( D missing a "

A missing a semicolon

What is the advantage of the C++11 integer data types over the old data types? A specifies exact size in bits B no advantage, just new names C Number of bits allocated changes dynamically as needed. D higher precision

A specifies exact size in bits

A common characteristic of Machine Learning includes A the use of massive amounts of data. B a working theory of explaining possible outcomes C always getting the same results independent of the source database. D predetermined outcomes based on expert knowledge E None of these possible answers.

A the use of massive amounts of data.

Given the function definition void something ( int a, int& b ) { int c; c = a + 2; a = a * 3; b = c + a; } and variable declarations in the main program int r=1, s=2, t=3; what is the output of the following code fragment? something(t, s); cout << r << ' ' << s << ' ' << t << endl; A) 1 14 3 B) 5 14 3 C) 1 10 3 D) 1 14 9 E) none of the above

A) 1 14 3

What is wrong with the following switch statement? int ans; cout <<"Type y for yes on n for no\n"; cin >> ans; switch (ans) { case 'y': case 'Y': cout << "You said yes\n"; break; case 'n': case 'N': cout << "You said no\n"; break;default: cout <<"invalid answer\n"; } A) ans is a int B) There are no break statements on 2 cases. C) break; is illegal syntax D) nothing

A) ans is a int

To open a file with a user supplied name, you need a variable to store the name. If the file name has no more than 20 characters, which would be the most appropriate variable declaration? A) char filename[21]; B) char filename(19); C) char filename[100]; D) char filename;

A) char filename[21];

If a file did not open correctly, you should A) display an error message and suitable action such as exit or obtain corrected file. B) exit the program immediately. C) continue with program processing. D) display an error message and continue with program processing.

A) display an error message and suitable action such as exit or obtain corrected file.

Which statement correctly opens an input stream named in_file and attaches it to a file named project.txt? A) in_file.open("project.txt"); B) in_file=project.txt C) in_file="project.txt" D) in_file.open(project.txt);

A) in_file.open("project.txt");

The put function outputs A) one character value. B) one integer value. C) one float value. D) one double value.

A) one character value.

The member function setf stands for A) set the associated flags. B) set the format. C) set the file name. D) nothing.

A) set the associated flags.

The predefined function tolower() returns a number. What is the output of the following code? char ch='G'; cout << tolower(ch) << endl; A) the integer value of 'g' B) G C) the double value of 'g' D) the integer value of 'G' E) the char 'G'

A) the integer value of 'g'

What is the output of the following program fragment? cout << static_cast<double>(3)/4 << endl; A 3 B 0.75 C 0.5 D 0

B 0.75

What is the output of the following code fragment? cout << pow(4,2) << endl; A 2 B 16 C 4 D 8

B 16

Given the following code fragment and the input value of 2.0, what output is generated? float tax, total; cout << "enter the cost of the item\n"; cin >> total; if ( total >= 3.0) { tax = 0.10; cout << total + (total * tax) << endl; } else { cout << total << endl; } A 4.4 B 2.0 C 2.2 D 3.1

B 2.0

Given the following enumerated data type definition, what is the value of SAT?enum myType{SUN=3, MON=1, TUE=3, WED, THUR, FRI, SAT, NumDays}; A 5 B 7 C 8 D unknown E 6

B 7

The output from Basic Computation can best be described as ________? A None of the possible answers. B Deterministic C Stocastic D Irrelevant E Unpredictable

B Deterministic

The term OS stands for A Operating Services. B Operating System. C Oscillating System. D No meaning in computer science. E Operations Services.

B Operating System.

When looking at the machine level, a computer's central processing unit can best be described as having A a Faustian instruction set. B a very simple instruction set. C an unknowable instruction set. D a very complex instruction set. E a probabilistic instruction set.

B a very simple instruction set.

When a void function is called, it is considered A a returned value. B an executable statement. C a comment. D an output function.

B an executable statement.

If x has the value of 3, y has the value of -2, and w is 10, is the following condition true or false? if( x < 2 && w < y) A true B false

B false

What is the output of the following code fragment if x is 15? if(x < 20) if(x <10) cout << "less than 10 "; else cout << "large\n"; A no output, syntax error B large C nothing D less than 10

B large

Call-by-reference parameters pass A nothing. B memory location of the actual argument. C the numeric value of the memory address of the argument. D the value of the actual argument.

B memory location of the actual argument.

Using function calls in a program is consider an aspect of: A data abstraction. B procedural abstraction. C calculus. D poor programming style.

B procedural abstraction.

When a variable is local to a function, we say that it has the ________ of the function A value B scope C constant D locality

B scope

A memory address is A where the CPU is stored. B where the value of a variable is stored. C a step in the program. D where the computer is located.

B where the value of a variable is stored.

How is Information related to Data? A) They are the same. B) One has context based on the other. C) None of the possible answers. D) They are the opposites. E) One is unused in C++.

B) One has context based on the other.

What is wrong with the following code? while( ! fileIn.eof() ) { fileIn >> value; fileOut << value; } A) We will write past the end of the output file. B) We will read past the end of the input file and attempt to output a garbage value. C) Nothing D) Two of the answers are true.

B) We will read past the end of the input file and attempt to output a garbage value.

ios::showpos is a flag that A) can be used to find the absolute value of an integer. B) always displays a + in front of positive integers. C) always displays a + in front of all integers. D) all of the above.

B) always displays a + in front of positive integers.

using namespace std; tells the compiler A) what language to use for input and output. B) where to get the definitions of certain objects (variables). C) where your program is located. D) nothing.

B) where to get the definitions of certain objects (variables).

What is the correct Boolean test if you want a loop to quit iterating if x < 10 and y > 3? A (x >=10 && y <=3) B (x >10 || y < 3) C (x >=10 || y <=3) D (x < 10 && y > 3)

C (x >=10 || y <=3)

Which of the following Boolean expressions tests to see if x is between 2 and 15 (inclusive of 2 and 15)? A (x<=15 || x>=2) B (2 <=x || x <=15) C (x >=2 && x <=15) D (2 <= x <= 15)

C (x >=2 && x <=15)

What is the value of x after the following statements? int x, y, z; y = 10; z = 3; x = y * z + 3; A garbage B 30 C 33 D 60

C 33

A finite sequence of precise instructions that leads to a problem solution is A a program. B a list of inputs and outputs. C an algorithm. D the CPU.

C an algorithm.

The functions pow(), sqrt(), and fabs() are found in which include file? A cstdlib B regular C cmath D iostream

C cmath

cout << "How many items would you want?\n"; A is a program. B is a variable declaration. C is an output statement. D is an input statement.

C is an output statement.

The get function reads A one integer value. B one float value. C one character value. D one double value.

C one character value.

Given the following code fragment, and an input value of 3, what is the output that is generated? int x; cout <<"Enter a value\n"; cin >> x; if(x=0) { cout << "x is zero\n"; } else { cout << "x is not zero\n"; } A x is zero B unable to determine C x is not zero D x is 1

C x is not zero

The phase which best describes the type of computational problem where you know in advance the question to be answered, the equations to be used, the range of results and the type of data to be analyzed is A) None of the possible answers. B) Machine Intuition C) Data Analysis D) Computational Formatting E) Simplistic Programming

C) Data Analysis

What is wrong with the following for loop? for(int i=0; i<10; i--) { cout << "Hello\n"; } A) improper use of a for-loop B) missing a semicolon ";" C) infinite loop D) off-by-one error E) i is not initialized.

C) infinite loop

Given the following code fragment, what is the final value of y? int x, y; x = -1; y = 0; while(x <= 3) { y += 2; x += 1; } A 8 B 2 C 6 D 10

D 10

What is the value of x after the following statements? int x;x = 0; x = x + 30; A 33 B garbage C 0 D 30

D 30

Given the following code fragment and the input value of 4.0, what output is generated? float tax; float total; cout << "enter the cost of the item\n"; cin >> total; if ( total >= 3.0) { tax = 0.10; cout << total + (total * tax) << endl; } else { cout << total << endl; } A 4.0 B 3 C 3.3 D 4.4

D 4.4

What is the result of the following code fragment: 4 + ceil(2.0); A 7.0 B 8.0 C 6.999 D 6.0

D 6.0

Which of the following is TRUE for a void function? A The value of 0 should be returned. B There cannot be a return statement. C The value of void should be returned. D Nothing is returned.

D Nothing is returned.

Which of the following lines correctly reads a value from the keyboard and stores it in the variable named myFloat? A cin << myFloat; B cin >> myFloat >> endl; C cin >> "myFloat"; D cin >> myFloat;

D cin >> myFloat;

If you have the following declaration in your program, const int SIZE=34; then which of the following statements are legal? A x = SIZE--; B cin >> SIZE; C SIZE ++; D cout << SIZE;

D cout << SIZE;

Which function returns TRUE if the character argument is a letter? A isdigit B islower C isspace D isalpha

D isalpha

Given the following code fragment, and an input value of 5, what is the output? int x; if( x< 3) { cout << "small\n"; } else { if( x < 4) { cout << "medium\n"; } else { if( x < 6) { cout << "large\n"; } else { cout << "giant\n"; } } } A small B giant C medium D large

D large

What is wrong with the following statement? cout << "Hello to everyone\n; A) cout should be count. B) missing a semicolon C) missing a ( D) missing a "

D missing a "

The postcondition of a function A tells what must be true before the function executes. B determines how the function will complete its job. C declares the function for the compiler. D tells what will be true or returned after the function executes.

D tells what will be true or returned after the function executes.

The expression static_cast<double>(3) is called a A multiplier. B doubler. C polymorphism. D type cast.

D type cast.

When calling the following function, the ________ of the actual arguments is passed to the function definition. double sqrt(double value); A address B scope C name D value

D value

Which of the following expressions are equivalent to (!(x<15 && y>=3))? A) (x>15 && y<=3) B) (x>15 || y < 3) C) (x>=15 && y < 3) D) (x>=15 || y < 3) E) C and D

D) (x>=15 || y < 3)

When testing a program with a loop, which of the following tests should be performed? A) one less than the maximum number of iterations B) maximum number of iterations C) one more than the maximum number of iterations D) A, B, and C E) A and B F) loop never iterates

D) A, B, and C

From which language did C++ directly evolve? A) Ada B) C- C) C+ D) C E) A

D) C

The command outFile.precision(2); A) displays integers as floating point numbers. B) truncates all floating point variables to 2 decimal places. C) sets all output streams in your program to display 2 decimal places. D) displays all floating point values sent to outFile with 2 decimal places.

D) displays all floating point values sent to outFile with 2 decimal places.

A do-while loop that will ask the user to enter a number between 2 and 5 inclusive, and will keep asking until the user enters a correct number, will use which of the following Boolean tests? A) (2 > number && number > 5) B) (2<5<number) C) (2 <= number && number <= 5) D) (2<=num<=5) E) (2 > number || number > 5)

E) (2 > number || number > 5)

Which of the following data types may be used in a switch statement? A) char B) A and D C) int D) enum E) bool F) all of the above

F) all of the above

A boolean expression may evaluate to more than 2 values. (T/F)

False

A void function can return any value. (T/F)

False

C++ is a low-level language. (T/F)

False

Every include directive must be followed by using namespace std; (T/F)

False

Every line in a program should have a comment. (T/F)

False

Including argument names are mandatory in the function call. (T/F)

False

It is illegal to call other functions from inside a function definition. (T/F)

False

It is illegal to make function calls inside a switch statement. (T/F)

False

Loops are used when we need our program to make a choice between two or more things. (T/F)

False

Main memory is volatile and holds its data when the computer is turned off. (T/F)

False

Once used, the width command stays in effect for all variables are send to the stream. (T/F)

False

The break statement causes all loops to exit. (T/F)

False

The function call pow(2,3) is the same as pow(3,2). (T/F)

False

The opposite of less than is greater than. (T/F)

False

The parameters listed in the function declaration are considered global variables. (T/F)

False

The printer is an example of an input device. (T/F)

False

The following statement is legal: (T/F) cout >> "Hello, my name is Bill\n";

False (cout<< ... is correct)

A function may return a boolean value. (T/F)

True

A semicolon by itself is a valid C++ statement. (T/F)

True

A void function may not be used in an output statement. (T/F)

True

It is acceptable to have both call-by-value and call-by-reference parameters in the same function declaration. (T/F)

True

It is legal to declare more than one variable in a single statement. (T/F)

True

Streams may be passed to a function. (T/F)

True

The body of a do-while loop always executes at least once. (T/F)

True

The member function eof() evaluates to when the program reads the end of file character. //single word answer, true or false

True

Using directives can be placed either directly after include directives or at the beginning of each function definition. (T/F)

True

Variables that are declared outside of any function body or parameter list are considered global. (T/F)

True

You may use a read (extraction) as a Boolean expression within an if or while statement. (T/F)

True

You must use a width statement before each variable that you want outputted in a certain width. (T/F)

True

Using functions in a program is called procedural ________.// single word answer

abstraction

Constant variables that you plan to used in different functions, as well as main(), should be ________ in scope.// Single word answer

global

A loop that iterates one too many or one too few times is said to be ________-by-one. // single word answer

off

In the function declaration, "int myFunction (int size);" the variable size is known as a ________.// Single word answer

parameter

The variables passed to a function in the call statement are known as ________.// single word answer

parameters

The ________ function puts one character back into the input stream.

putback

Braces are used to define the body of a conditional expression when there is/are ______ line(s) of code? // single word answer.

two


Kaugnay na mga set ng pag-aaral

Chapter 1: Intro to Employee Training and Development

View Set

Psych. Exam 2 (Section: Thinking and Intelligence)

View Set

Sociology Chapter 14 Capitalism And The Economy

View Set

Næringsstoffer kap 4 + litt av kap 5

View Set