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

List of all available Websheets


Viewing cpp/cs104/classes/nodefault by redekopp@usc.edu. You have unsaved changes. Log in above to create, edit, preview and publish Websheets.
PropertyValue
Description
html markup
shown to student
 
Consider the initialization of <tt>ObjB::a</tt> (i.e. we want to initialize <tt>val</tt> that is a member of <tt>a</tt>.  Our goal is to initialize <tt>val</tt> with the value of <tt>w</tt> from 
the <tt>ObjB</tt> constructor.
<p>
   How can we do this?  <strong>Note:</strong> <tt>ObjA</tt> does not have any public <tt>set</tt>/<tt>mutator</tt> functions...only the constructor allows us to set <tt>value</tt>
Remarks
Comments, history, license, etc.
 
Copied from problem cpp/cs104/classes/constructor_init (author: redekopp@usc.edu)
remove
Engine
Template / Reference solution
 
#include <iostream>
using namespace std;
class ObjA
{
public:
   \[
REDACTED
\show:
   ObjA(int v) {
      val = v;  
   }
   ]\
   int get() const { return val; }
private:
   int val;
};
int main()
{ 
   ObjA mya1(3);
   ObjA myarray[10];
   
   for(int i=0; i < 10; i++){
      cout << myarray[i].get() << endl; 
   }
   return 0;
}
C++ test suite
json list of stdin/args tests
e.g. [{"stdin":"hi", "args":["4", "5"]},
{"stdin":"noargs"}]

to just run once with no input use [{}]
 
[{}]
Is example?
i.e., just a demo
remove


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'.