Professional Documents
Culture Documents
―
―
Psychologist No Fault
Injury
Behavioral Medicine Assoc
OPEN
Details
Title
Quizzes
Description
In class quizzes
Total Cards
75
Subject
Chemical Engineering
Level
Undergraduate 2
Created
03/18/2012
Cards
Term
Definition
By using arguments
Term
Definition
Term
What is the output of the following code snippet? #include using namespace std; int pow(int base, int
power) { int result = 1; for (int i = 0; i < power; i++) { result = result * base; } return result; } int main() { cout
<< pow(pow(2, 2), 2) << endl; return 0; }
Definition
16
Term
Definition
To package a repeated task as a function even though the task does not yield a value
Term
The ceil function in the C++ standard library takes a single value x and returns the smallest integer that is
greater than or equal to x. Which of the following is true about ceil(12.6)?
Definition
What is the output of the following code snippet? #include using namespace std; void prevnext(int a, int&
prv, int nxt) { prv = a - 1; nxt = a + 1; } int main() { int a = 100; int b = 0; int c = 0; prevnext(a, b, c); cout <<
"Previous = " << b << ", Next = " << c; return 0; }
Definition
Term
What is the output of the following code snippet? #include using namespace std; void double_amount(int
in_value) { in_value = 2 * in_value; } int main() { int principal_amt = 2000; double_amount(principal_amt);
cout << principal_amt << endl; return 0; }
Definition
2000
Term
Term
#include using namespace std; void func1() { int i = 0; double b = 0; } void func2() { // empty } int main() {
func1(); func2(); return 0; }
Definition
Term
Definition
The function does not specify a type for the second parameter variable.
Term
What are the values of x and y after executing the given code snippet? #include using namespace std;
void mystery(int& a, int& b) { a = b; b = a; } int main() { int x = 10; int y = 11; mystery(x, y); return 0; }
Definition
x = 11 and y = 11
Term
Definition
A return statement.
Term
Suppose you need to write a function that calculates the volume of rectangular boxes. Which of the
following is the best choice for the declaration of this function?
Definition
Term
#include using namespace std; int my_fun(int perfect) { { int perfect = 0; return ((perfect – 1) * (perfect –
1)); } return perfect; } int main() { for (int i = 0; i < 4; i++) { cout << my_fun(i) << " "; } return 0; }
Definition
1111
Term
The statements that are executed when a function is called are known as:
Definition
Term
What is incorrect in the following code snippet? #include using namespace std; void display_box(string
str) { cout << "--------" << endl; cout << str << endl; cout << "--------" << endl; } int main() { cout <<
display_box("Hello World"); return 0; }
Definition
display_box does not return a value; therefore, it cannot be used with cout <<.
Term
How many times will the cout statement execute in the following code snippet?
Definition
9 times
Term
Definition
An inverted right triangle with six rows and seven columns of the plus sign. The number of columns
decrements by one on completion of one iteration of the inner loop.
Term
Which common error is present in the code below, which is intended to calculate the average value from a
sum of numbers?
double total = 0.0;
int n = 0;
double input;
while (cin >> input)
{
total = total + input;
n++;
}
double average = total / n;
Definition
Division by zero
Term
The code snippet below checks whether a given number is a prime number.
int j = 2;
int result = 0;
int number = 0;
cout << "Please enter a number: ";
cin >> number;
while (j <= number / 2)
{
if (number % j == 0)
{
result = 1;
}
j++;
}
if (result == 1)
{
cout << "Number: " << number << " is Not Prime! ";
}
else
{
cout << "Number: " << number << " is Prime! ";
}
The code snippet will display the desired result without errors
Term
What will be the final output of the following code snippet when a user enters input values in the order 10,
20, 30, 40, 50, and -1?
double sum = 0;
int count = 0;
double salary = 0;
double average = 0;
cout << "Enter salaries (-1 to stop): " << endl;
while (salary != -1)
{
cin >> salary;
if (salary != -1)
{
sum = sum + salary;
count++;
}
}
if (count > 0)
{
average = sum / count;
cout << "The Average Salary: " << average << endl;
}
else
{
cout << "No data!" << endl;
}
Definition
Term
string s = "12345";
int i = 1;
do
{
if (i > 1)
{
cout << s.substr (i, 1);
}
}
while (i < 5);
Definition
Term
int i = 0, j = 0;
while (i < 125)
{
i = i + 2;
j++;
}
cout << j << endl;
Definition
63
Term
bool i = false;
do
{
cout << "What do you C?" << endl;
}
while (i != i);
Definition
string s = "abcde";
int i = 1;
while (i < 5)
{
cout << s.substr (i, 1);
i++;
}
Definition
bcde
Term
int i;
int j;
for (i = 0; i < 7; i++)
{
for (j = 7; j > i; j--)
{
cout << "+";
}
cout << endl;
}
Definition
An inverted right triangle with seven rows and seven columns of the plus sign. The number of columns
decrements by one on completion of one iteration of the inner loop.
Term
Definition
2345
Term
The Monte Carlo method can find solutions to problems that are difficult to solve precisely. A typical
example of such a problem is
Definition
Term
int time = 0;
int year = 0;
int rate = 0;
int principal = 1000;
int interest = 0;
while (year < 10)
{
interest = (principal * time * rate) / 100;
cout << interest << endl;
}
Definition
The code fragment will continue to display the calculated interest because the loop will never end.
Term
int i = 1;
while (i < 10)
{
cout << i << " ";
i = i + 2;
if (i == 5)
{
i = 9;
}
}
Definition
139
Term
How many times does the loop run in the following code fragment?
Definition
15
Term
Assuming that a user enters 64 as his score, what is the output of the following code snippet?
Definition
Term
Assuming that a user enters 68 as his score, what is the output of the following code snippet?
int score = 0;
cout << "Enter your score: ";
cin >> score;
if (score < 50)
{
cout << "F" << endl;
}
else if (score >= 50 || score < 55)
{
cout << "D" << endl;
}
else if (score >= 55 || score < 65)
{
cout << "C" << endl;
}
else if (score >= 65 || score < 75)
{
cout << "B" << endl;
}
else if (score >= 75 || score < 80)
{
cout << "B+" << endl;
}
else
{
cout << "A" << endl;
}
Definition
Term
What is the output of the following code snippet if the input is 25?
if (i > 25)
{
i++;
}
else
{
i--;
}
cout << i << endl;
Definition
24
Term
Definition
110
Term
Assuming that the user inputs "twenty" as the input, what is the output of the following code snippet?
Definition
Invalid Data!
Term
Consider the following code snippet. Assuming that the user inputs 75 as the age, what is the output?
Definition
Impressively old
Term
Assuming that the user input is 40, which of the following block of statements is executed?
Definition
Term
Consider the following code snippet. Assuming that the user enters 20 and 12 as the two input values,
what is the output of the code snippet?
int num1, num2, num3 = 0, num4 = 0, num5 = 0;
cout << "num1 = " << num1 << " num2 = " << num2
<< " num3 = " << num3 << " num4 = " << num4
<< " num5 = " << num5 << endl;
Definition
Term
Definition
Execution falls through the next branch until a break statement is reached
Term
Assuming that a user enters 25 as input, what is the output of the following code snippet?
Definition
Term
What is the conditional required to check to see if the length of a string s1 is odd?
Definition
if ((s1.length() % 2) != 0)
Term
Assuming that a user enters 25 as the value for x, what is the output of the following code snippet?
if (x < 100)
{
x = x + 5;
}
if (x < 500)
{
x = x - 2;
}
if (x > 10)
{
x++;
}
else
{
x--;
}
cout << x << endl;
Definition
29
Term
Term
Assuming that the user provides 303 as input, what is the output of the following code snippet?
int x = 0;
cout << "Please enter y: ";
int y;
cin >> y;
if (y > 300)
{
x = y;
}
else
{
x = 0;
}
cout << "x: " << x << endl;
Definition
x: 303
Term
Assuming that a user enters 50, 70, and 60 as input values one after another, separated by spaces, what is
the output of the following code snippet?
int number1;
int number2;
int number3 = 0;
70
Term
Assuming that the user provides 101 as input, what is the output of the following code snippet?
if (b > 100)
{
a = b;
}
else
{
a = 0;
}
cout << "a: " << a << endl;
Definition
a: 101
Term
Assuming that a user enters 56 as his age, what is the output of the following code snippet?
Term
Assuming that a user enters 64 as his golf score, what is the output of the following code snippet?
int golf_score = 0;
cout << "Enter your golf score: ";
cin >> golf_score;
Professional!
Term
What are the values of num1 and num2 after this snippet executes?
Term
In an airline reservation system, the number of available seats in an airplane is required. Which data type
should be used to store this value?
Definition
int
Term
What is the value inside the var variable at the end of the given code snippet? #include using namespace
std; int main() { int var = 30; var = var + 2 / var; var++; return 0; }
Definition
31
Term
What is the output of the following code snippet if the user provides NEW YORK as the input? #include
#include using namespace std; int main() { string name; cout << "ENTER THE STRING: "; cin >> name; int
s1 = name.length(); cout << s1 << endl; return 0; }
Definition
3
Term
What is the output of the following code snippet? #include #include using namespace std; int main() { int
var1 = 10; int var2 = 2; int var3 = 20; var3 = var3 / (var1 % var2); cout << var3 << endl; return 0; }
Definition
Term
Assuming that the user enters 45 and 62 as inputs for n1 and n2, respectively, what is the output of the
following code snippet? #include #include using namespace std; int main() { cout << "Enter a number: ";
string n1; cin >> n1; cout << "Enter another number: "; string n2; cin >> n2; string result = n1 + n2; cout <<
result << endl; return 0; }
Definition
4562
Term
What is the correct way to invoke functions on variables in C++ that are strings?
Definition
Invoke them using the variable name and the dot (.) notation
Term
Which of the following choices is a valid statement about this code snippet? #include using namespace
std; int main() { double d = 45.326; double r = d % 9.0; cout << r; return 0; }
Definition
The assignment statement for variable r is wrong, because the % operator expects integer values as
operands
Term
Assuming that the user inputs a value of 25 for the price and 10 for the discount rate in the following code
snippet, what is the output? #include using namespace std; int main() { cout << "Enter the price: "; double
price; cin >> price; cout << "Enter the discount rate: "; double discount; cin >> discount; cout << "The new
price is " << price - price * (discount / 100.0) << endl; return 0; }
Definition
Term
Which one of the following operators computes the remainder of an integer division?
Definition
%
Term
Suppose the student provides the answer 2 5 [Enter] as input to the first prompt. What will the program
do?
Definition
Term
Definition
Term
What is the result of the following snippet?
int son_age = 5;
int father_age = son_age * 3 + 5;
Definition
Term
What is the output of the following code snippet? #include using namespace std; int main() { double a; a =
sqrt(9.0) + sqrt(16.0); cout << a << endl; return 0; }
Definition
7.0
Term
What is wrong with the following code snippet? #include using namespace std; int main() { int width = 10;
height = 20.00; cout << "width = " << width << " height = " << height << endl; return 0; }
Definition
The code snippet uses an undefined variable.
Term
How many integer elements can be stored in the array myarr declared below?
--
int myarr[10][8];
Definition
80
Term
Term
Consider the following code snippet:
--
int myarray[] = { 10, 20, 30, 40, 50 };
cout << myarray[2];
cout << myarray[3];
--
What is the output of the code snippet?
Definition
3040
Term
Term
30
Term
Definition
23
Term
Definition
25
Term
What is the valid range of index values for an array of size 10?
Definition
0 to 9
Term
Definition
80
Term
Definition
Definition
MY FLASHCARDS
FLASHCARD LIBRARY
BROWSE
ABOUT
HELP
MOBILE
Create Account