Midterm Intro C++

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

Given function Multiply(u, v) that returns u * v, and Add(u, v) that returns u + v, which expression corresponds to: Add(Multiply(x, Add(y, z)), w)

(x * (y + z)) + w

What is the output, if the input is 3 2 4 5? All variables are ints. cin >> num; for (i = 0; i < num; ++i) { cin >> curr; cout << curr; }

245

Which assigns the last vector element with 20? vector<int> userNum(N_SIZE);

userNum.at(N_SIZE - 1) = 20;

In an instruction like: z = x + y, the symbols x, y, and z are examples of _____.

variables

Which declares two related integer vectors named personName and personAge each with 50 elements? vector<int> personName(50); vector<int> personAge(50); vector<int> personName, personAge = 50; vector<int> personName = 50; vector<int> personAge = 50;

vector<int> personName(50);vector<int> personAge(50);

The numNegatives variable counts the number of negative values in the vector userVals. What should numNegatives be initialized to? vector<int> userVals(20); unsigned int i; numNegatives = XXX; for (i = 0; i < userValues.size(); ++i) { if (userValues.at(i) < 0) { numNegatives = numNegatives + 1;} }

0

Which is the correct representation of 3.9e-5?

0.000039

The binary equivalent of the decimal number 15 is _____ .

00001111

What is the output, if n is 3? for (int i = 1; i <= n; ++i) { int factorial = 1; factorial = factorial * i; cout << factorial << " "; }

1 2 3

How many elements does the vector declaration create? vector<int> scores(10); // Vector declaration scores.at(0) = 25; scores.at(1) = 22; scores.at(2) = 18; scores.at(3) = 28;

10

What is the output? int num = 10; while (num <= 15) { cout << num << " "; if (num == 12) { break; } ++num; } cout << "Done";

10 11 12 Done

What are the ending contents of the vector? Choices show elements in index order 0, 1, 2. vector<int> yearsList(3); yearsList.at(0) = 5; yearsList.at(1) = yearsList.at(0); yearsList.at(0) = 10; yearsList.at(2) = yearsList.at(1);

10, 5, 5

If the input is 12, what is the final value for numItems? int x; int numItems = 0; cin >> x; if (x <= 12) {numItems = 100; }else {numItems = 200; } numItems = numItems + 1;

101

Which is not a valid identifier? name1 first_name 1stName firstName

1stName

Given a vector/array with values 5, 10, 15, 20, 25, what are the fewest number of swaps needed to reverse the list?

2

Given myVector initially has 5 elements with values 3, 4, 6, 8, and 9. What are the values in myVector after the following? myVector.resize(2);

3,4

What is the output if count is 4? for (i = count; i > 0; --i) { // Output count }

4321

Given vector userVal has 4 elements. What is the size of userVal after the following? userVal.resize(5);

5

What is the ending value of y if x is 50? y and x are ints. y = (x < 21) ? 100 : x;

50

How many x's will be output? i = 1; while (i <= 3) { j = 1; while (j <= i) { cout << "x";++j; } cout << endl; ++i; }

6

What is the output, if the input is 3 2 1 0? cin >> x; while (x > 0) { cout << 2 * x << " "; }

666666666...infinte

What is the ending value of z? x = 0; y = 3; z = pow(x + 2, y);

8

For what values of x will "Medium" be output? If x > 40: Output "Large"Else If x > 20: Output "Medium"Else If x > 10: Output "Small"

Any x from 21 to 40

Which item converts a high-level language program to low-level machine instructions?

Compiler

For which quantity is a double the best type?

Height of a building

For an enumerated type like below, the compiler assigns what kind of value to RED, GREEN, and BLACK. enum CarColor {RED, GREEN, BLACK};

Integer

Which input for char c causes "Done" to be output next? c = 'y'; while (c = 'y') { // Do somethingcout << "Enter y to continue, n to quit: "; cin >> c; } cout << "Done";

No such value (infinite loop)

For what values of x does the default case execute in the code below? x is declared as an integer. switch (x) { case 2:...break; case 3:...break; case 4:...break; default:... // When does this execute? }

Only for values that are not 2, 3, or 4

Which is true for the following code? char userText[10]; userText[0] = 'B'; userText[1] = 'o'; userText[2] = 'o'; userText[3] = 'k'; userText[4] = '\0'; ...userText[3] = 't';

Printing the array userText will work fine because the new string is 4 characters and the array size is 10.

RAM is an abbreviation that stands for:

Random Access Memory

Which expressions for YYY and ZZZ will output "Young" for ages less than 20 and "Young Adolescent" for ages between 10 and 20? int u; cin >> u; if (YYY) { cout << "Young"; if (ZZZ) { cout << " Adolescent"; } }

YYY: u < 20 ZZZ: u > 10

A sequence of instructions that solves a problem is called a(n) _____ .

algorithm

The _____ is a process that manages programs and interfaces with peripherals.

operating system

Which character array declaration is appropriate? char name[5] = "Alexandria"; char name[5] = "Alexa"; char name[5] = "Alexander"; char name[5] = "Alex";

char name[5] = "Alex";

Which declaration assigns a variable with 5 such that the value can not be later changed? const int = 5; int NUM_ITEMS = 5; int numItems = 5; const int NUM_ITEMS = 5;

const int NUM_ITEMS = 5;

Which YYY outputs the string in reverse?Ex: If the input is "Oh my", the output is "ym hO". int i; string str; getline(cin, str); for (YYY){ cout << str.at(i); }

i = str.length() - 1; i >= 0; --i)

Which if branch executes when an account lacks funds and has not been used recently? hasFunds and recentlyUsed are booleans and have their intuitive meanings.

if (!hasFunds && !recentlyUsed)

Which XXX will output only values up to 3? i is an int. for (i = 1; i < 10; i++) { cout << i << " "; XXX { break; } }

if (i == 3)

Which is the simplest expression that is true only when myChar is among a-z or A-Z? isalpha(myChar) isalpha(tolower(myChar)) isalpha(tolower(myChar)) || isalpha(toupper(myChar)) isalpha(myChar) && !isspace(myChar)

isalpha(myChar)

Which assigns the vector's first element with 99? vector<int> myVector(4);

myVector.at(0) = 99;

For the string "Orange", what character is at index 3?

n

Which expression is most appropriate for randomly choosing a day of the week?

rand() % 7;

An identifier can _____ . contain a period contain spaces start with an underscore be a reserved word

start with an underscore

Which statement appends an exclamation point at the end of myStr? char myStr[10] = "Yay";

strcat(myStr, "!");

Which XXX and YYY will loop as long as the input is an integer less than 100? Choices are in the form XXX / YYY. cin >> w; while (XXX) { // Do something YYY; } w < 100 / (nothing) w >= 100 / (nothing) w < 100 / cin >> w w >= 100 / cin >> w

w < 100 / cin >> w

For an integer constant x, which statement will yield a compiler error? y = x; w = x + 1; z = x + x; x = y + 1;

x = y + 1;

What is the output? int columns; int rows; for (rows = 0; rows < 2; ++rows) { for (columns = 0; columns < 3; ++columns) { cout << "x";} cout << endl;}

xxx xxx


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

PHYSIO: chapter 1 practice questions

View Set

Clinical Practice Fundamentals Mastery Level 2 Basics of Nursing Practice

View Set

Life Policy Provisions, Riders and Options

View Set

Insulin, Glucagon and Diabetes melitus

View Set

Common nasal and sinus problems topics

View Set

Intro to Business Chapter 1 Quiz

View Set

Ch. 7 - Financing and Accounting

View Set