Not logged in. Log in with GitHub. About Websheets.

List of all available Websheets


Viewing cpp/cs102/practice12/functionsTF by jmell@usc.edu. You have unsaved changes. Log in above to create, edit, preview and publish Websheets.
PropertyValue
Description
html markup
shown to student
 
<p>Consider the following code, and mark all the statements that are true:</p>
<pre><code>
#include <iostream>
using namespace std;
int multiplyByTen(int num);
void setToA(char c);
void printA();
void printB();
void printC();
void changeArray(char arr[]);
int main()
{
  int num = 1;
  
  // A
  for (int i = 0; i < 3; ++i) 
  {
    cout << max(1, multiplyByTen(num)) << " ";
  }
  cout << endl;
    
  // B
  char char1 = 'm';
  char char2 = 'O';
  setToA(char1);
  cout << char1 << " " << char2 << endl;
  
  // C
  printA();
  cout << endl;
  
  // D
  char char3 = 't';
  cout << char3;
  setToA(char3);
  cout << " " << char3 << endl;
  
  // E
  char myArr [3];
  myArr[0] = 'O';
  myArr[1] = 'O';
  myArr[2] = 'O';
  changeArray(myArr);
  cout << myArr[0] << " " << myArr[1] << " " << myArr[2];
  
}
int multiplyByTen(int num) 
{
    num *= 10;
    return num;   
}
void setToA(char c) 
{
    c = 'A';
}
void printA()
{
    cout << "A" << " ";
    printB();
}
void printB()
{
    printC();
    cout << "B" << " ";
}
void printC()
{
    cout << "C" << " ";
}
void changeArray(char arr[])
{
    arr[0] = 'X';
}
</code></pre>
Remarks
Comments, history, license, etc.
 
Copied from problem cpp/cs102/practice11/arraysTF (author: jmell@usc.edu)
Copied from problem cpp/cs102/practice9/compiling (author: jmell@usc.edu)
remove
Engine
Choices
json list of string, bool pairs
e.g. [["good", true],
["bad", false]]
 
[["At the end of the for loop (A), the program will have printed \"10 100 1000\".", null], ["At the end of the for loop (A), the value of the variable \"num\" in function main will be 1.", null], ["The variable \"num\" in functions main and multiplyByTen reference the same location in memory.", null], ["The following print statement is valid code: \"cout << max(1, multiplyByTen(num)) << endl;\"", null], ["The print statement after point (B) will print \"A A\"", null], ["The code below point (C) will print \"A C B\"", null], ["The code below point (D) will print \"t A\"", null], ["The code below point (E) will print \"O O O\"", null]]


Optional properties:

Note: problems are open-source by default (see 'Public permissions'). Assumed license for open problems is Creative Commons 4.0 Attribution-ShareAlike unless specified in 'Remarks'.