List of all available Websheets
Viewing cpp/classes/norm by daveagp@gmail.com. You have unsaved changes. Log in above to create, edit, preview and publish Websheets.
Property | Value |
---|---|
Description html markup shown to student | Define a two-dimensional <tt>Point</tt> class. <p> The method <tt>p.dot(q)</tt> should compute the dot product $p \cdot q = p_x \times q_x + p_y \times q_y$. <p> The method <tt>p.norm()</tt> should compute the norm of $p$, defined as $\sqrt{p \cdot p}$. |
Public permissions | |
Engine | |
Template / Reference solution |
using namespace std; // point.h class Point { public: Point(double x, double y); double dot(Point other); double norm(); private: double x; double y; }; // point.cpp Point::Point(double x, double y) { // parameter names same as data members :( this->x = x; // woohoo \[ this->y = y; ]\ } double Point::dot(Point other) { return x * other.x + y * other.y; } double Point::norm() { // square root of dot product with self \[ return sqrt(this->dot(*this)); ]\ } // test code int main() { Point p(3, 4); Point q(2, 0); cout << p.dot(q) << endl; cout << p.norm() << endl; cout << q.norm() << 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 default compiler flag(s) | ["-Wshadow"] |
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'.