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

List of all available Websheets


Viewing cpp/cs104/classes/ctor-default-arrays 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
 
Try to create an array of A1 objects below.  What does the <tt>A1</tt> class need to enable this ability?.
   
   
</ol>
<p><strong>Learning goal:</strong> </p>
<ul><li>When does the compiler generate a default constructor and when does it not?</li>
   <li>What does the default constructor do?</li>
</ul>
Remarks
Comments, history, license, etc.
 
Copied from problem cpp/cs104/classes/ctor-default (author: redekopp@usc.edu)
Copied from problem cpp/cs104/classes/constructor_init (author: redekopp@usc.edu)
remove
Engine
Template / Reference solution
 
#include <iostream>
#include <algorithm>
using namespace std;
struct A1 {
\[
REDACTED
\show:
   A1(double myx) { x = myx; }
   double x;
]\
};
int main()
{
\[
REDACTED
\show:
   A1 obj[5];
   for(int i=0; i < 5; i++){  
      cout << "obj[" << i << "]'s value of x: " << obj[i].x << 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'.