List of all available Websheets
Viewing cpp/var-expr/interp1d by redekopp@usc.edu. You have unsaved changes. Log in above to create, edit, preview and publish Websheets.
Property | Value |
---|---|
Description html markup shown to student | <p>Suppose you are given two (x,y) coordinates [(x1,y1) and (x2,y2)] in the Cartesian plane which are used to define a line, y = f(x).</p> <p>If you are provided a value, x0, find the value of y0 such that y0 = f(x0).</p> |
Public permissions | |
Remarks Comments, history, license, etc. | Copied from problem cpp/var-expr/gpa (author: redekopp@usc.edu) Copied from problem cpp/var-expr/in_n_days (author: redekopp@usc.edu) Copied from problem cpp/var-expr/char_arith (author: redekopp@usc.edu) Copied from problem cpp/var-expr/hello (author: daveagp@gmail.com) |
Engine | |
Template / Reference solution |
using namespace std; int main() { // declare variables here \[ double x1, y1, x2, y2, x0, y0; ]\ cout << "Enter the x1 y1 x2 and y2: " << endl; \[ cin >> x1 >> y1 >> x2 >> y2; ]\ cout << "Now enter a value for x0: " << endl; \[ cin >> x0; ]\ // Compute y0 \[ double m = (y2 - y1) / (x2 - x1); y0 = y1 - m*(x1 - x0); ]\ cout << "The point on the line should be (x0,y0) = (" << x0 << "," << y0 << ")" << 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 [{}] | [ {"stdin":"1.0 5.0 2.0 7.0 0.0", "args":[]}, {"stdin":"0.0 5.5 5.5 0.0 6.0", "args":[]} ] |
Solution visibility |
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'.