Cop 3014 Exam 3

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

Complete the code to print all items for the given array, using the above common loop structure. int daysList[365]; ... for (i = 0;_________ ; ++i) { cout << daysList[i] << endl;

I<365

Given integers i, j , k, which XXX correctly passes three integer arguments for the following function call?addInts XXX; (j, 6 + 7) (i + j + k) (10, j, k +5) (10 15 20)

(10, j, k +5)

Mustang is an object of type Car. Which statement invokes drive()? (A). mustang.drive(145); (B). drive(135); (C). Car.drive(150); (D). mustang->drive(115);

(A). mustang.drive(145);

Which expression evaluates to false if x is 0 and y is 10?

(x == 0) && (y == 20)

Which input value causes "Goodbye" to be output next? int x;cin >> x; while (x >= 0) { // Do something cin >> x;} cout << "Goodbye";

-1

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

userNum.at(N_SIZE - 1) = 20;

Declaring Vectors

vector <int> myvector

what is the output? int Calc(int num1, int num2) { ... cout << Calc(x,5): return 0; }

16

Which is not a valid identifier?

1stName

Which is true regarding how functions work?

If a function returns a variable, the function stores the variable value until the function is called again.

What are the ending contents of the vector? Vector <int>years(3) yearsList.at(0)= 5; yearsList.at(1) = yearsList.at(0); yearsList.at(0)=10; yearsList.at(2) = yearsList.at(1)

10, 5, 5

How many total elements are stored within the two arrays int familyAges[50] and double familyHeights[50]?

100

What is the output? int num = 10 ... cout << "Done";

10 11 12 Done

Given: int maxScores[4] = {20, 20, 100, 50};. What is maxScores[3]?

50

what is the output, if the input is 3 2 1 0?

6 6 6 6 6 ... (infinite loop)

A _________ is a computer component that stores files and other data

disk

Given the following function to change to return the product instead of the sum, how many times must the code be changed? int main() { cout<< Calculate(3, 4) cout<< Calculate(5, 2) cout<< Calculate(6, 7) return 0; }

1

A restaurant gives a discount for children under 10. They also give the discount for adults over 55. Which expression evaluates to true if a discount should be given?

(age < 10) || (age > 55)

Which expression evaluates to 3.5? int x= 7; int y = 1;

(x/2.0)

which input value causes "Goodbye" to be output next?

-1

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

0

What is the ending value of y? int x; int y; x= 6; y= (1/2)*(x+5);

0

the numNegatives variable counts the number of negative values in the array userVals. What should numNegatives be initialized to? int userVals[20]; ... numNegatives = numNegatives + 1; } }

0

What is the output int n; for (n=0; n< 10; n=n+3) { cout << n << " "; }

0 3 6 9

what is true for comments?

The compiler does not generate machine code for comments.

Given a list of syntax errors from a compiler, a programmer should focus attention on which error(s), before recompiling?

The first error only

Choose the statement(s) that generate(s) this output: I wish you were here.

cout << "I wish" << endl; cout << "you were here.";

Given two integer vectors origList = {2, 3, 4, 5} and offsetList = {6, 7, 8, 9}, which statement prints out the sum of the second element in the origList with the corresponding element in the offsetList? cout << origList + offsetList << endl; cout << origList.at(2) + offsetList.at(2) << endl; cout << origList.at(1) + offsetList.at(1) << endl; cout << origList.at(2) + offsetList.at(2) << endl;

cout << origList.at(1) + offsetList.at(1) << endl;

string str = "Amy"; Which statement prints "...Amy"?

cout << setw(6)<< setfill('.') << str;

Which for loop will iterate 100 times?

for (i = 0; i < 100; i++)

Which is a valid definition for a function that passes two integers (a,b) as arguments, and returns an integer?

int myFunction(int a, int b) ^^memorize exact <--- emailed him about needs two ints one outside and in parentheses

Declare an array named myVals that stores 10 items of type int

int myVals[10];

Which XXX and YYY correctly complete the code to find the maximum score? Choices are in the form XXX / YYY. int[] scores = {43, 24, 58, 92, 60, 72}; int maxScore;maxScore = scores[0]; for (XXX) { if (num > maxScore) { YYY;} }Question options: 1)int scores: num / maxScore = num 2)scores != 0 / num = maxScore 3)int num: scores / maxScore = num 4)num < scores / num = maxScore

int num: scores / maxScore = num

Which declares two related integer ARRAYS named personName and personAge each with 50 elements?

int personName[50]; int personAge[50];

Using two separate statements, declare two related integer ARRAYS named seatPosition and testScore each with 130 elements.

int seatPosition[130]; int testScore[130];

[Q1] Which function converts a string to an integer? 1)convert(string, int) 2)int() 3)string_to_int() 4) integer()

int()

which best describes the meaning of a 1 (true) being output? Assume v is a large vector of ints. int i; bool s; ... cout << s;

last value is negative

Which is an invalid access for the vector? vector<int>numsList(5); int x=3;

numsList.at(x+2)

what line of code assigns a clear variable outputGenres with the value the gamePointer points to? char userGames = '8'; user* gamesPointer;

outputGames = *gamesPointer;

What is the output? void Swap(int& x, int y) { int tmp;tmp = x;x = y; y = tmp; } int main() {int p = 4, q = 3;Swap(p, q); cout << "p = " << p << ", q = " << q << endl; } p = 3, q = 3 p = 4, q = 3 p = 3, q = 4 Error: Argument names must match parameter names

p = 3, q = 3

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);

Given x=4 and y=8, what are the ending values of x and y? x=y; y=x; x=y;

x=8, y=8

What is the output? int columns; int rows; ... cout << endl; }

xxx xxx

given the list {3 9 7 18 1}, what is the second outer loop iteration?

{1 3 7 18 9}

C++ is _____

derived from C

What is output? #include <iostream> #include<ios> ... cout << setfill('-') <<setw(7) << "Tim" << endl; return 0; }

----Tim

Which expression doubles x? x += 2; x *= 2; x *= x ;x = x 2;

x *= 2;

RAM is an abbreviation that stands for:

Random Access Memory

What is the index of the last element? int numList[50];

49

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

5

What code for XXX, YYY correctly swaps a and b? Choices are written as XXX / YYY.XXX;a = b;YYY;b = tmp; Question options: tmp = a / (nothing) tmp = a / tmp = b tmp = b / (nothing) (nothing) / tmp = a

tmp = a / (nothing)

An array is automatically passed by pointer. true or false?

true

How to write a constructor

class Restaurant Restaurant::Restaurant()

Identify the correct declaration of an array of strings? a)Char[50] StringArr[10]; b)Char StringArr[10]; c)Char StringArr[10][50] d) StringArr[10];;

Char StringArr[10];

what does the code output? cout << "I "; cout << "want pie." << endl;

I want pie.

Which statement prints" Amy"? (3 spaces)

cout << right << setw(6) << str;

An identifier can ______

start with an underscore

Given: int yearsArr[4]; yearsArr[0] = 1999; yearsArr[1] = 2012; yearsArr[2] = 2025; 1)How many elements in memory does the array declaration create? 2)What value is stored in yearsArr[1]? 3)With what value does currYear = yearsArr[2] assign currYear? 4)With what value does currYear = yearsArr[3] assign currYear? 6)What is the proper way to access the first element in array yearsArr?

1)4 2)2012 3)2025 4)unknown 6)yearsArr[0]

How many elements does the vector declaration create? vector <int> score (10) // vector declaration ... scores.at(3) = 28;

10

What are the ending values in vector origValues? Note the question ASKS FOR origValue, not newValues.const int NUM_ELEMENTS = 4; vector<int> origValues(NUM_ELEMENTS); vector<int> newValues(NUM_ELEMENTS) ;origValues.at(0) = 10; origValues.at(1) = 20; origValues.at(2) = 30; origValues.at(3) = 40; newValues = origValues; newValues.at(2) = 21; newValues.at(3) = 22;

10, 20, 30, 40

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

What is y after executing the statements? x = 5; y = x + 1; y = y* 2;

12

What is the output? int x = 18; while (x > 0) { cout << x << " "; x = x / 3; }

18 6 2

For the given program, how many cout statements will execute? void PrintShippingCharge(double itemWeight) {if ((itemWeight > 0.0) && (itemWeight <= 10.0)) { cout << (itemWeight 0.75) << endl;}else if ((itemWeight > 10.0) && (itemWeight <= 15.0)) {cout << (itemWeight 0.85) << endl;}else if ((itemWeight > 15.0) && (itemWeight <= 20.0)) {cout << (itemWeight * 0.95)<< endl;}}int main() {PrintShippingCharge(18);PrintShippingCharge(6);PrintShippingCharge(25);return 0; } 1 2 3 9

2

How many times will the loop iterate, if the input is 105 107 99 103? cin >> x; while (x > 100) { // Do something cin >> x; }

2

Given array scorePerQuiz has 10 elements. Which assigns element 7 with the value 8? 1) scorePerQuiz= [8]; 2) scorePerQuiz[7]= [8]; 3) scorePerQuiz [8]= [8]; 4) scorePerQuiz[0]= [8];

2) scorePerQuiz[7]=[8];

Which XXX causes the program to output the message "Hello!"?void PrintMessage() {cout << "Hello!";}int main() {XXX;return 0;} 1)cout << PrintMessage() 2)PrintMessage() 3)void PrintMessage() 4)PrintMessage("Hello!")

2)PrintMessage()

what are the ending values in countVal? vector<int> countVal; ... countVal.at(2) = 44;

22, 33, 44

What is the output, if the input is 3 2 4 5? All variables are integers.

245

How many function calls exist in the following code?int Calc1 (int a, int b) {return a + b / 2;} int Calc2 (int a, int b) {return a * b / 100; }int main () {int x;int y; x = Calc1 (5,3);cout << x; y = Calc2 (5,3);cout << y; cout <<Calc2 (5,3); } a)2 b)3 c)4 d)5

3

How many references are declared? Dog labrador = new Dog(); Dog poodle; Dog beagle = new Dog(); poodle = beagle; poodle = labrador;

3

what is the final value of y? int x = 6; int y = 2; if (x < 10) { if (y < 5) { y = y + 1; } else { y = 7; } } else { y = y + 10; }

3

Which statement has a syntax error? Assume variables x, y, z and age have already been defined. 1) print('Name, age') 2) age = '32' 3) x + y = z 4) y = y

3) x+ y = z

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

given integer vector itemNumbers has three elements with values 33, 34, 35. What are the values in itemNumbers after the following? itemNumbers.push_back(32);

33, 34, 35, 32

What is the ending value of w? int w; int y; y = 34; w = y % 5;

4 (30/5 =6, remainder of 4)

The following program generates an error. Why? void PrintSum(int num1, int num2) {cout << num1 + num2;} int main() {int y;y = PrintSum(4, 5); return 0;} 1)The void function is missing a "return;" statement. 2)The values 4 and 5 cannot be passed directly to PrintSum() 3)main() has a return statement that returns the value 0 4)PrintSum() has void return type, so cannot be assigned to a variable

4) PrintSum() has void return type, so cannot be assigned to a variable

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

4321

If the list {29 18 45 7 16} is sorted in ascending order using selection sort, what will be the value of the 0th element after the first pass over the outer loop (i = 0)?

7

Given that integer array x has elements 4, 7, 3, 0, 8, what are the elements after the loop? int i;for (i = 0; i < 4; ++i) {x[i] = x[i + 1];} a)4, 4, 7, 3, 0 b)7, 3, 0, 8, 8 c)7, 3, 0, 8, 4 d)Error: Invalid access

7, 3, 0, 8, 8

How many elements are in the array? int userVals[2][4];

8

What is the ending value of x? int y = 6; x = (1 / 2) * y + 8;

8

Given that this loop iterates over all items of the array, how many items are in the array? for (i = 0; i < 99; ++i) { cout << someArray[i] << endl; }

99

What is the index of the last element for the following array: int pricesArr[100];?

99

which operator is the insertion operator?

<<

What is the ending value of the element at index 0? index 1? intNumbers[10]; numbers[0]= 35; numbers[1]= 37; numbers[1] = numbers[0] + 4;

@0 =35 @1 = 39

Which of the following statements is true about private data members of a class?

A member function can access the private data members, but class users cannot.

What is myChar assigned with? char myChar; myChar = '\'';

A single quote: '

Which is true regarding accessing elements of arrays and vectors?

An access to an out-of-range index will generate an error for vectors but not nessecarily arrrays

Which is true about accessors?

An accessor reads a class' data members

Which outputs "Negative" for values less than 0, otherwise outputs "Non-negative"? a. if (val > 0) { cout << "Non-negative"; } else { cout << "Negative"; } b. if (val >= 0) { cout << "Non-negative"; } else { cout << "Negative"; } c. if (val < 0) { cout << "Non-negative"; } else { cout << "Negative"; } d. if (val <= 0) { cout << "Negative"; } else { cout << "Non-negative"; }

B

Two vectors, itemsNames and itemsPrices, are used to store a list of item names and their corresponding prices. Which is true?

Both vectors should be declared to have the same number of elements

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

Compiler

What does a clock do?

Determines the rate of execution for a processor's instructions

Given that integer array x has elements 5, 10, 15, 20, what is the output? int i;for (i = 0; i < 4; ++i) { System.out.print(x[i] + x[i + 1]); 10, 15, 20, 5 15, 25, 35, 25 15, 25, 35, 20 Error: Invalid access

Error: Invalid access

Given two integer arrays, largerArray with 4 elements, and smallerArray with 3 elements. What is the result after this code executes?for (i = 0; i < 4; ++i) {largerArray[i] = smallerArray[i];} 1)All the elements of largerArray will get copied to smallerArray. 2)Some of the elements of largerArray will get copied to smallerArray 3)All of the elements of smallerArray will get copied to largerArray. 4)Error: The two arrays are not the same size.

Error: The two arrays are not the same size.

What is output? #include <iostream> using namespace std; ... int main() { Greet t1; return 0; }

Hello

What is output? #include <iostream>using namespace std; class Greet {public:Greet(); };Greet::Greet() { cout << "Hello"; }int main() {Greet t1; return 0;}

Hello

Given strings strg1= Hello and strg2= goodbye, what is final value? Str3 = Str1 +Str2; 1)Hello Goodbye 2)HelloGoodbye 3)GoodbyeHello 4)Error

HelloGoodBye

What declares a two-dimensinal integer array called myArray with 3 rows and 4 columns?

Int myArray[3][4]

In what component does a processor store the processor's required instructions and data?

Memory

Having a loop within a loop is known as: a) Nesting. b) Doubling up. c) Recursion. d) Stacking.

Nesting

Which input for char c causes "Done" to be output next? c = 'y'; while (c = 'y') { // Do something cout << "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

The ______ is a process that manages programs and interferes with peripherals

Operating system

What is the. purpose of the & symbol in the following code? int *myVar int distance =132 myVar = &distance

Refers to the memory address of distance

What type of value will myFunc() return for the given program? #include <iostream> using namespace std; ... sam = myFunc(); }

Sample

_____ sort is a sorting algorithm that treats the input as two parts, a sorted part and an unsorted part, and repeatedly picks the proper value to move from the unsorted part to the end of the sorted part

Selection

An identifier can _____ .

Start with an underscore

Given two arrays, studentNames that maintains a list of student names, and studentScores that has a list of the scores for each student, which XXX and YYY prints out only the student names whose score is above 80? Choices are in the form XXX / YYY.String[] studentNames = new String[NUM_STUDENTS];int[] studentScores = new int[NUM_STUDENTS]; int i; for (i = 0; i < NUM_STUDENTS; ++i) {if (XXX > 80) {System.out.print(YYY + " a)studentNames[i] / studentNames[i] b)studentNames[i] / studentScores[i] c)studentScores[i] / studentNames[i] d)studentScores[i] / studentScores[i]

StudentScores[i] / studentNames[i] (SCORES THEN NAMES)

What value of x outputs "Junior"? if (x < 56) { // Output "Sophomore" } else if (x > 56) { // Output "Senior" } else { // Output "Junior" }

Value 56

Which declaration assigns a variable with 5 such that the value cannot be later changed?

const int Num_ITEMS=5;

Which statement reads and stores data into integer variable inputNum from the FILE opened by the stream inFS? a) inFS >> inputNum; b) cin >> inputNum; c)inFS.open(inputNum);

a inFS >> inputNum;

Given only int variables a and b, which is a valid expression? 1)4a + 3 2)a + ab 3)a + -2 4)2 x 3

a + -2

Which shows valid accesses for an array a and vector v, each with 10 elements?

a[5]v.at(5)

Which XXX is valid for the following code? int CalcSum(int a, int b) {return a + b;} int main() {int y;XXXreturn 0; } a.y = CalcSum(); b.y = CalcSum(4, 5); c.y = CalcSum(4 + 5); d.CalcSum(y, 4, 5);

b) y = CalcSum(4, 5);

If the input is 5, what is the output? int x; int z=0; cin>> x if(x > 9) { z = 3; } z = z + 1; cout << z; a. 0 b. 1 c. 3 d. 4

b. 1

Which is true regarding sizing of arrays and vectors? a.Appending an element to an array automatically resizes the array if necessary b.Appending an element to a vector automatically resizes the vector if necessary c.An array's size can be specified during declaration, but a vector's size cannot d.An vector's size can be specified during declaration, but an array's size cannot

b.Appending an element to a vector automatically resizes the vector if necessary (APPENDING VECTOR)

What is the output? void WaterTemperatureForCoffee(int temp) {if (temp < 195) {cout << "Too cold."; }else if ((temp >= 195) && (temp <= 205)) {cout << "Perfect temperature."; }else if (temp > 205) {cout << "Too hot."; }}int main() {WaterTemperatureForCoffee(205); WaterTemperatureForCoffee(190); return 0; } a)Too cold. b)Perfect temperature. c)Perfect temperature. Too cold. c.perfect temperature.Too cold.

c) Perfect temperature.Too Cold

Which statement correctly declares a char array named myText initialized to Hello? a.char myText = {"Hello"}; b.char[10] myText= "Hello" c.char myText[10] = "Hello"; d.myText[] = {"Hello"};

c.char myText[10] = "Hello";

For which quantity is a double the best type? a.People in a household b.Boxes on a conveyor belt c.Planes above a city d.Height of a building

d. height of a building

Which XXX is most appropriate for printing out the char array userText?userText[10] = "zyBook"; for (i = 0; XXX; ++i) { // Print userText[i]} a.i < 6 b.i <= 6 c.userText != '\0' d.userText[i] != '\0'

d.userText[i] != '\0' (HAS i IN[])

Given the two vectors, which code will output all the vectors' elements, in the order key, item followed by a newline? vector<int> keysList(SIZE_LIST); vector<int> itemsList(SIZE_LIST);

for (i = 0; i < keysList.size(); ++i) { cout << keyList.at(i) << ", " << itemsList.at(i) << endl; } (There is a for expression and keysListSize is NOT subtracted by 1)

Which XXX causes every character in string inputWord to be output?for (XXX) {cout << inputWord.at(i) << endl; } i = 0; i < (inputWord.size() - 1); ++i i = 0; i < inputWord.size();++i i = 0; i < (inputWord.size() + 1);++i i = 0; i <= inputWord.size(); ++i

i = 0; i < inputWord.size(); ++i

Which outputs "Negative" for values less than 0, otherwise outputs "Non-negative"?

if (val >= 0) { cout << "Non-negative";} else { cout << "Negative"; } (GREATER THAN OR EQUAL TO)

If the input is 5, what is the output? int x ;cin >> x; if (x < 10) { cout << "Live "; }else if (x < 20) { cout << "long ";} else if (x < 30) {cout << "and ";} cout << "prosper!";

live prosper!

Which best describes what is output? Assume v is a large vector of ints. int i; int s; s = v.at(0); for (i = 0; i < v.size(); ++i) { if (s > v.at(i)) { s = v.at(i);}} cout << s;

min value in v

which best describes what is output? Assume v is a large vector of ints. int i; int s; ... cout << s;

min value in v

myChar is a character variable, which assignment is valid?

myChar = 't'

Assign the second element of array myVals with the value 555.

myVals[1]=555;

Which assigns the vector's FIRST element with 99? vector<int> myVector(4); myVector.at() = 99; myVector.at(-1) = 99; myVector.at(0) = 99; myVector.at(1) = 99;

myVector.at(0) = 99;

which assigns the vectors last element with 99? vector <int> myVector(15);

myVector.at(14) = 99;

The inFS.open(str) function has a string parameter str that specifies the ____ of the file to open

name

which is the output for x = 15?

no match

what line of code makes the character pointer studentPointer point to the character variable userStudent? char userStudent = 'S'; char* studentPointer;

studentPointer = &userStudent

If a program compiles without errors, the program is free from _____

syntax errors

What is an essential feature? while(loopExpression){ loopBody }

the loop expression should be effected by the loop body

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

userNum.at(N_SIZE, -1) = 20;

A pointer is a(n) _____ that contains a ____

variable, memory address


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

2021 Private Pilot Test Prep (Ch 4 & 5, ALL & AIR ONLY)

View Set

Info Sec & Network Quiz Chapter 8

View Set

Nclex review: Pneumonia and Respiratory Meds

View Set

Unit 9 Life insurance underwriting and policy issue

View Set

6.15 Software-Defined Network (SDN)

View Set

Chapter 5 - Antepartal Period: Psycho-Social Cultural Aspects

View Set

Macroeconomics test 2: chapters 8, 9, 10, 11, 12, 18

View Set

AP Micro: Chapter 4 Self-Assessment

View Set