CS 70

Written Questions

These questions go with the earlier parts of this assignment. Answer them right here on this page—your answers are saved as you go, and you can come back and change them until the deadline.

  • LHS Cow speaking

    If you're working ahead on Homework 0 and haven't done the lessons yet, you should skip this part and come back to it after you complete the lessons.

About Your Server Account

1 point

The CS 70 server lets us give everyone the same development environment. There are files, libraries, and programs that you can access on the server that probably aren't on your own computer (and aren't on the lab computers either).

With the Homework 0 project open on the server, type cs70-message in the terminal and hit enter. What is displayed?

The Hundred Doors Example

These questions are about the Hundred Doors example from Working With C++ Code.

1 point

Which doors are open at the end of the process?

3 points

Printing in Five Languages

Find the line in doors-in-python.py that actually prints output to the screen and paste it here:

Find the line in doors-in-swift.swift that actually prints output to the screen and paste it here:

Find the line in DoorsInJava.java that actually prints output to the screen and paste it here:

Find the line in doors-in-c.c that actually prints output to the screen and paste it here:

Find the line in doors-in-c++.cpp that actually prints output to the screen and paste it here:

Hmm. One of these things is not like the others...!

Types and Representations

These questions are about the programs introduced in Exploring C++'s Numeric Types.

3 points

Output of show-rep

Using show-rep, find the bit representation of the int value 1 and paste it here:

Using show-rep, find the bit representation of the char value 1 and paste it here:

Using show-rep, find the bit representation of the float value 1.0 and paste it here:

3 points

Output of show-types

Using show-types, find the maximum value of int and paste it here:

Using show-types, find the maximum value of unsigned int and paste it here:

Using show-types, find the maximum value of float and paste it here:

Which of these takes up the most space in memory (i.e. requires the most bytes)?

Conversion and Promotion

These questions are about what happens if you assign a value of one type to a variable of another. Both Week 1 Lesson 2 and show-types might be useful in answering them.

3 points

Consider the following block of C++ code, which depends on a previously-declared int variable named x:

long int y = x;

Can we trust that the values of x and y are equal?

3 points

Consider the following block of C++ code, which depends on a previously-declared int variable named x:

short int y = x;

Can we trust that the values of x and y are equal?

3 points

Consider the following block of C++ code, which depends on a previously-declared int variable named x:

float y = x;

Can we trust that the values of x and y are equal?

The Memory Model

These questions relate to what and how information is stored in memory, and our CS 70 memory model.

3 points

Consider the following variable declaration from a C++ program:

int x = 42;

If, while our program is running, we looked in memory at the spot where x is stored, which of the following would we expect to find?

3 points

Draw a Memory Diagram

Consider the following C++ program:

int increment(int x) {
    x = x + 1;
    return x;
}

void main() {
    int numToInc = 5;
    int oldNum = numToInc;
    numToInc = increment(numToInc);
}

Draw a memory diagram of this program using the CS 70 memory model (as seen in Week 1 Lesson 2), take a picture of it, and upload it using the button below.

Make sure that your diagram is clear and legible:

  • Draw and write neatly
  • Make sure your diagram is well-lit
  • Make sure your picture is in focus

We can't grade what we can't read!

Upload your picture here:

(When logged in, completion status appears here.)