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

List of all available Websheets


Viewing cpp/classes/ruleof3 by daveagp@gmail.com. You have unsaved changes. Log in above to create, edit, preview and publish Websheets.
PropertyValue
Description
html markup
shown to student
 
A memory bug.
Public permissions remove
Engine
Template / Reference solution
 
#include <iostream>
#include <string>
using namespace std;
class TwoInts {
private:
   int* data;
public:
   TwoInts(int first, int second) {
      data = new int[2];
      data[0] = first;
      data[1] = second;
   }
   ~TwoInts() {
      delete[] data;
   }
\[
   TwoInts(const TwoInts& c) {
      data = new int[2];
      data[0] = c.data[0]; data[1] = c.data[1];
   } 
\show:
   ;// todo?
]\
   int get_first() { return data[0]; }
   int get_second() { return data[1]; }
};
int biggest_of(TwoInts pair) {
   return max(pair.get_first(), pair.get_second());
}
int main() {
   TwoInts nums(10, 33);
   cout << nums.get_first() << " " << nums.get_second() << endl;
   cout << biggest_of(nums) << endl;
   cout << nums.get_first() << " " << nums.get_second() << endl;
}
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 [{}]
 
[
   {}
]
Solution visibility 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'.