CS 150 Midterm 1

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

To the right are the six steps of the C++ development process as shown in your textbook. Below, match each step with the tool that accepts the shown input and produces the output as shown. Step 1 Step 2 Step 3 Step 4 Step 5 Step 6

(1) Text editor (2) Preprocessor (3) Compiler (4) Linker (5) Loader (6) CPU

In the reading you learned about five concepts related to variables. Line 4 is ______________.

In the reading you learned about five concepts related to variables. Line 4 is ______________.

Look at the following piece of code. Check the answers that match it. Address Hexdump Dissassembly-------------------------------$0600 a9 c0 LDA #$c0$0602 aa TAX$0603 e8 INX$0604 69 c4 ADC #$c4$0606 00 BRK

machine language machine dependent native code (This code is written in machine (and assembly) language for a specific processor; thus it is non-portable or machine dependent. This is the native code for the 6502 processor. Machine language is both difficult to write and to understand. (That's why Woz added all of the comments on the right).)

Provides instructions for building your program.

make

Below is the main function from the f2c program. Which line(s) contain a variable definition?

16, 18

Which line throws an exception because of range checking?

4

Which lines cause syntax errors? [1] string s{"shiver me timbers"}; [2] auto len = s.size(); [3] s.front() = 'S'; [4] s.back() = "S"; [5] s[len] = 'X'; [6] s.substr(0, 1) = "W"; [7] auto a = s.substr(0, 100); [8] auto b = s.substr(4, 3); [9] auto c = s.substr(len);

4, 6

Which line produces undefined behavior? 1. string s = "holey moley"; 2. auto len = s.size(); 3. auto a = s.front(); 4. s.at(len) = a; 5. s[len] = 'c';

5

Which of these lines are illegal? [1] int n1 = 4; [2] double n2 = 3.145; [3] unsigned char n3 = 158; [4] int n4 = n2; [5] int& r1 = n1; [6] int& r2 = n2; [7] double& r3 = n1; [8] const int& r4 = n2;

6, 7

Which lines compile and return string objects? [1] string s{"shiver me timbers"}; [2] auto len = s.size(); [3] s.front() = 'S'; [4] s.back() = "S"; [5] s[len] = 'X'; [6] s.substr(0, 1) = "W"; [7] auto a = s.substr(0, 100); [8] auto b = s.substr(4, 3); [9] auto c = s.substr(len);

7, 8, 9

This portion of code: #include <iostream> using std::cout; int main() { cout << "Hello CS 150\n"; } A. Compiles, runs, prints output without a newline. B. Compiles, runs, prints output with a newline. C. Compiles but crashes when run D. Syntax error: missing return statement E. Other syntax error.

A

Used by compiler to produce object code.

Assembler

In C++, the statement string s{3, 'X'};

Creates a string containing the ASCII(3) character followed by 'X'

Combines object modules to produce an executable.

Linker

What prints out when this code runs? extern int = y; int x = 42; y = 3.012; cout << "(" << x << "," << y << ")"

Linker error

Which of these statements apply to C++?

More efficient than Java or Python Produces native code that runs on the CPU Compiles to native code

Below is the main function from the f2c program. Which line(s) contain a function declaration?

None

If a and c are both false, which expressions must be evaluated? if (a && b || c && d || e)...

c, e, a

If a and b are true, which expressions need not be evaluated?

c, e, d

What command makes hw the current folder?

cd ~/workspace/cs150/hw

Allows you to run your program in a controlled environment.

debugger

Associates a name with a type.

declaration

In the reading you learned about five concepts related to variables. Line 3 is ______________. More than one answer may be required.

declaration, initialization, definition

Allocates memory for a new variable.

definition

Explain this output. Why is nothing printed?#include <iostream> using namespace std; int main() { cout << "Hello, World"; } make example./example

file not saved

This code illustrates the ____________ idiom. if (n % 2 == 1) cout << "Odd" << endl;

guarded action

Multiple possible outputs, testing a single condition, use:

if . . . else

What is true about string::size_type?

it is returned from the string length() member function it is the same as size_t it is returned from the string size() member function you may create variables of that type it is an unsigned integer type of some size

This code illustrates the ____________ idiom. 1 auto n = 3; 2 if (n % 2 == 1) n = -n; 3 else if (n < 0) n++; 4 else if (n % 2 = 0) n--; 5 else n = 0; guarded action alternative action multiple selection None of these are correct

multiple selection

Which line or lines are illegal? int a; int b = 3; int main() { a = 4; cout << a << ", " << b << endl; }

none

Match the letter at the right of each line in the figure with the correct statement below. string s1; // A. string s2 = "hello"; // B. string s3{"world"}; // C. string s4(20, '-'); // D. string s5(R"("bob")"); // E. #include // F. cin >> s1; // G. getline(cin, s2); // H.

reads one line of text from standard input : choice H explicitly converts a character array to a string object : choice C Reads one word or token from standard input : choice G Needed to use the C++ string type : choice F Produces a string that may contain quotes or backslashes : choice E implicitly converts a character array to a string object : choice B produces the empty string : choice A Produces a string from multiple copies of a single character : choice D

In Line 2, what is the implicit argument?

the address of s

In C++, what is true about the += operator operating on string objects

you may concatenate a string literal (character array) to a string object you may concatenate creates a string variable to a string object you may concatenate a char variable to string object you may concatenate a char literal to a string object


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

DSCI 4520.001 EXAM 1 (QUIZ 1 & 2)

View Set

Week 10: Occupational Health and Safety

View Set

The French Revolution and Napoleon

View Set

Chapter 32 NCLEX-Style Review Questions

View Set