Programming Test I Review (Practices 2-6)

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

reference

When used as parameters, these types of variables allow a function to access the parameter's original argument: reference floating-point counter undeclared None of these

bool salesQuotaMet = false;

Which declaration statement will declare a boolean variable saleQuotaMet and will assign the value false. boolean salesQuotaMet = false; bool salesQuotaMet = false; BOOLEAN salesQuotaMet = false; bool salesQuotaMet false;

continue

A statement that may be used to stop a loop's current iteration and begin the next one is break terminate re-iterate continue None of these

argument, parameter

A(n) ________ is information that is passed to a function, and a(n) ________ is information that is received by a function. function call, function header parameter, argument argument, parameter prototype, header None of these

computeValue(10);

Given the following header for a function named computeValue, which of the following is a valid call to the function? void computeValue(int value) void computeValue(int x); computeValue(10) computeValue(10); void computeValue(10);

TRUE

TRUE or FALSE When C++ is working with an operator, it strives to convert the operands to the same type.

TRUE

TRUE or FALSE myVar_1 is a legal variable name

cin object

The ________ causes a program to wait until information is typed at the keyboard and the [Enter] key is pressed. -output stream -cin object -cout object -preprocessor -None of these

for

The ________ loop is a good choice when you know how many times you want the loop to iterate in advance of entering the loop. while for switch do-while pre-test

do-while

The ________ loop is ideal in situations where you want the loop to iterate at least once. while for switch do-while pre-test

a post-test loop

The do-while loop is considered a pre-test loop a post-test loop an infinite loop a counter-controlled loop None of these

x = pow ( (a+b), .5);

The expression below, will be written in Visual C++ as ___________________________. x = radical a+b

cmath

The function pow(x, y), requires which header file? -iomanip iostream cmath cstring cstdlib

&&

This operator represents the logical AND: ++ || && @ None of these

!

This operator takes an operand and reverses its truth or falsehood: !& || =! ! None of these

return

This statement causes a function to end.\ end terminate return release None of these

local

This type of variable is defined inside a function and is NOT accessible outside the function. global reference local counter None of these

#include fstream

To allow file access in a program, you must use ________ in the header file. #include fstream #include file #include cfile #include fileaccess

ofstream

To write data to a file, you define an object of the ________ data type. ifstream outputFile ofstream fstream

It allows four spaces for the value in num4.

What is TRUE about the following statement? cout << setw(4) << num4 << " "; -It is incorrect because it should use setw(num4). It allows four spaces for the value in num4. It outputs "setw(4)" before the value in num4. It is incorrect because it should use setw(10).

char

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

int

What is the data type of the following function prototype's return value? int myFunction(double); int double void cannot tell from the prototype

This is true! That's all folks

What is the output of the following code segment? int x=5; if (x = 2); cout << "this is true!" << endl; else cout << "This is false!" << endl; cout << "That's all folks" << endl; This is true! This is true!This is false!That's all, folks! This is false! This is true!That's all folks This is false!That's all, folks

1 1 ... and on forever

What is the output of the following code segment? n = 1; while (n <= 5) cout << n << ' ' ; n++ ANSWERS: 1 2 3 4 5 6 2 3 4 5 1 2 3 4 1 1 ... and on forever 1 2 3 4 5

9

What is the output of the following segment of code? int value = 2; switch (value) { case 1: value += 1 case 2: case 3: value +=3; case 4: value +=4; } count << value << endl; 0 2 3 9 None of these

15

What is the value of Y (Y is defined as type double)? Y = 9 % 6 + (3 + 6) / 2 + pow (2, 3); 16 15.5 15 13.5

5

What is the value of result after the following statement executes? result = (3 * 5) % 4 + 24 / (15 - (7 - 4)); 6.4 5 1.6 2.25 None of these

true

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

4.5

What is the value of x (x is defined as type double)? x = = (3 + 6) / 2.0; -4 -4.5 -5 -6

7

What is value of x? x = 6 + 15 / 4 % 2; -1 -7.5 -0 -7

15.457

What will be the output of the following cout statement? double ratio = 15.45678; cout << setprecision (3) << fixed << ratio; 15.456 15.5 15.45 15.457

1234567 A

What will be the output of this cout statement? (1,2,3,4,5,6, and7 indicates column numbers) cout << setw (7) << 'A'; - 1234567 A -1234567 A -1234567 AAAAAAA -1234567 A

7

What will the following code display? #include <iostream> using namespace std; int getValue (int); int main () { int x = 2; cout << getValue (x) << endl; return 0; } int getValue (int num) { return num + 5; } 5 2 7 getValue(x)

202

What will the following code display? #include <iostream> using namespacestd; void doSomething (int); int main () { int x = 2; cout << x << endl; return 0; } void doSomething(int num) { num = 0 cout << num << endl; } -202 -222 -200 -000

200

What will the following code display? #include <iostream> void doSomething (int&); int main () { int x = 2; cout << x << endl; doSomething(x); cout << x << endl; return 0; } void doSomething (int& num) { num = 0; cout << num << endl; } 000 202 200 222

MonTueWed

What will the following code display? cout << "Mon"; cout << "Tue"; cout << "Wed"; -Mon Tue Wed -MonTueWed -Mon Tue Wed -"Mon""Tue""Wed"

6

What will the following code display? int number = 6; cout << number++ << endl; 6 5 7 0

3

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

in the keyboard buffer

When a user types values at the keyboard, those values are first stored as ASCII characters in the header file iostream in the keyboard buffer as integers None of these

global

A ________ variable is declared outside all functions. local global floating-point counter None of these

update

A for statement contains three expressions: initialization, test, and update reversal null validation None of these

prototype

A function ________ eliminates the need to place a function definition before all calls to the function. . header prototype argument parameter None of these

only one

A function can have no parameters, one parameter, or many parameters and can return ________ value(s). zero to many no only one a maximum of ten None of these

sentinel

A special value that marks the end of a list of values is a constant counter variable sentinel None of these

15

After the following code executes, what is the value of my_value if the user enters 0? cin >> my_value; if (my_value > 5) my_value = my_value + 5; else is (my_value > 2) my_value = my_value + 10; else my_value = my_value + 15; -15 -0 25 -10 -5

outFile << number;

Assuming outFile is a file stream object and number is a variable, which statement writes the contents of number to the file associated with outFile? write(outFile, number); outFile << number; number >> outFile; outFile >> number;

TRUE

TRUE or FALSE The value printed in a field are right-justified by default. cout << setw(8) << "ABC";

void getData (int &num)

Codes below are written to enter a data inside the function - getdata and the function getData will transfer the value so that myValue will have that data. There is an error in the following code and what will fix that? void getData (int &); int myValue; getData (myValue); <------ function call //Function void getData (int num) { cout << "Enter a value: "; cin >> num; } getData (num); getData (myValue&); void getData (int &num) void getData (int myValue) int getData (int num)

x > 7 ? cout <<"x is greater than 7" : cout << "x is less than or equal to 7";

Given the if/else statement: if (x > 7) cout <<"x is greater than 7"; else cout <<"x is less than or equal to 7"; Which of the following performs the same operation? -x > 7 ? cout <<"x is greater than 7" : cout << "x is less than or equal to 7"; -x > 7 ? cout <<"x is less than or equal to 7" : cout << "x is greater than 7"; -x > 7 ? "x is less than or equal to 7" ; "x is greater than 7"; -x > 7 : "x is less than or equal to 7" ? "x is greater than 7"; -x > 7 , "x is less than or equal to 7" , "x is greater than 7";

21

How many times will the following loop display " Looping again!"? for (int i = 0; i <= 20; i++) cout << "Looping again!" << endl; 20 19 21 an infinite number of times

5

How many times will the following loop display "RCSJ"? for (int i = 7; i < 12; i++) cout << "RCSJ" << endl; 6 5 19 4

6

How much memory space (in bytes) is required to store the word "HELLO"? -4 -5 -6 -10

<

In the following statement, which operator is used first? while (x++ < 10) ++ < neither; the expression is invalid cannot tell without the rest of the code

FALSE

TRUE or FALSE The variable name team.2020 is a valid variable name in Visual C++?

False

T OR F A function's return data type must be the same as the function's parameters.

False

T OR F A local variable and a global variable may not have the same name within a program.

True

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

False

T OR F All static variables are initialized to -1 by default.

False

T OR F Function headers are terminated with a semicolon.

True

T OR F Function prototypes are terminated with a semicolon.

False

T OR F Global variables are initialized to zero by default.

TRUE

T OR F If you want to stop a loop before it goes through all of its iterations, the break statement may be used.

True

T OR F In a function prototype, the names of the parameter variables may be left out.

FALSE

T OR F Indicate True or False for the following string comparison: "Jane" < "Jack"

False

T OR F Local variables are initialized to zero by default.

True

T OR F Many functions may have local variables with the same name.

True

T OR F Static local variables are not destroyed when function a function returns.

FALSE

T OR F The increment and decrement operators can be used in mathematical expressions; however, they cannot be used in relational expressions.

TRUE

T OR F The update expression of a for loop can contain more than one statement, for example: for(i = 5; i <= 10; i++, total+= sales)

False

T OR F You must always furnish an argument with a function call.

False

T OR F int value; value = 7.95; //floating point value is assigned to integer variable After execution of the above statement, 8 will be stored in the variable value after the value get rounded.

TRUE

T OR F or (index = 20; index <= 10; index --) count << "NJ" << endl; The above loop will terminate as soon as it begins and "NJ" will not be displayed even once.

True

T OR F x = y = z = 7; The value 7 will be assigned to each of the variable listed in the above statement.

FALSE

TRUE OR FALSE The default section is required in a switch statement.

FALSE

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

FALSE

TRUE OR FALSE The value of result in the following expression will be 0 if x has the value of 12. result = x > 100 ? 0 : 1;

TRUE

TRUE or FALSE " %" operator is used a modulus operator.

TRUE

TRUE or FALSE # include<string> preprocessor directive allows string data type to be used in a program.

TRUE

TRUE or FALSE //Program - Practice.cpp //Name - John Doe The above comments can be replaced with the comments given bellow: /* Program - Practice.cpp Name - John Doe */

FALSE

TRUE or FALSE A preprocessor directives starts with '//' character.

TRUE

TRUE or FALSE Character constants are enclosed inside single quotes.

FALSE

TRUE or FALSE Define preprocessor directive ends with semicolon (;).

TRUE

TRUE or FALSE If the expression on the left side of the following is false, the expression on the right side will not be checked. (num1 > num2) && (num1 == 5)

TRUE

TRUE or FALSE If the expression on the left side of the following is true, the expression on the right side will not be checked. (a>=b) || (c=d)

FALSE

TRUE or FALSE If you want to know the length of the string that is stored in a string object, you can call the object's size member function.

TRUE

TRUE or FALSE The cin << statement will stop reading input when it encounters a newline character.

TRUE

TRUE or FALSE The string data are stored in the memory ending with '\0' character.

for (int count = 3; count <17; count +=3) cout << count << endl;

Which for loop will display exactly the same output as the following do..while loop. int count = 3; do { cout << count << endl; count +=3; } while (count < 17); - for (int count = 3; count +=3; count <17) cout << count << endl; -for (int count = 3, count <17, count +=3) cout << count << endl; - for (int count = 3; count <17; count +=3) cout << count << endl; -int count = 3; for (count +=3; count < 17) cout << count << endl;

if (y == 5) x = 100; else x = 200;

Which if/else statement will assign 100 to x if y is equal to 5. Otherwise, it will assign 200 to x.

line 3

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

cin.ignore

Which of the following functions tells the cin object to skip one or more characters in the keyboard buffer? cin.ignore cin.jump cin.hop cin.skip None of these

string empName = 'John Doe';

Which of the following is not valid assignment statement? double sum = 12.5; string empName = 'John Doe'; char myGrade = 'A'; bool boolStat = true;

cin.get();

Which of the following statements will pause the screen until the [Enter] key is pressed? cin; cin.input(); cin.ignore(); cin.getline(); cin.get();

cin >> base >> height;

Which of the following will allow the user to input the values 15 and 20 and have them stored in variables named base and height, respectively? cin << base << height; cin base, height; cin >> base >> height; cin base >> cin height; None of these

2dArray

Which one of the following would be an illegal variable name? -2dArray -TwoDArray -Two_D_Array -_TwoD_Array_

if (code = 'C') cout << "This is a Check\n"; (NOTICE THE ' INSTEAD OF ")

Which statement allows you to properly check the char variable code to determine whether it is equal to a C and then output This is a check? -if code is equal to C cout << "This is a Check\n"; -if (code = C) cout << "This is a Check" << endl; -if (code = 'C') cout << "This is a Check\n"; -if (code = "C") cout << "This is a Check\n";

const int DAYS_IN_WEEK = 7;

Which statement below will declare DAYS_IN_WEEK as a constant with an integer value 7. -Const int DAYS_IN_WEEK = 7; -const int DAYS_IN_WEEK 7; -const int DAYS_IN_WEEK = 7; -Const integer DAYS_IN_WEEK = 7; -None of these

99

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

break

Without this statement appearing in a switch construct, the program "falls through" all of the statements below the one with the matching case expression. break exit switch scope None of these

setprecision

You can control the number of significant digits in your output with the ________ manipulator. setprecision set_precision to_fixed setfixed() None of these

getline

________ reads a line of input, including leading and embedded spaces, and stores it in a string object. cin.get getline cin.getline get None of these

sizeof()

______function returns the size (in bytes) of a variable. -sizeof() -HowMany() -size() -length()


संबंधित स्टडी सेट्स

Chapter 11: The Healthcare Delivery System

View Set

LabCE Course - Red Cell Disorders: Peripheral Blood Clues to Nonneoplastic Conditions

View Set

International Business: The International Business Environment

View Set

Peristiwa-peristiwa sekitar proklamasi dan proses terbentuknya Negara Kesatuan Republik Indonesia

View Set

duolingo 11 (Paris, At home 4, shopping 3)

View Set

Networking Devices and Initial Configuration Module 7 - 9 Checkpoint Exam

View Set