Difference between revisions of "Scratch"

From WhyAskWhy.org Wiki
Jump to: navigation, search
m (More content to test styles against)
m (Testing highlighting for SQL)
Line 1: Line 1:
<syntaxhighlight lang="cpp">
+
<syntaxhighlight lang="sql">
class point2d {
+
# use the "my_database" database
public:
+
USE my_database;
// constructor:
 
    explicit point2d(double xval=0, double yval=0);
 
// read access functions
 
    double x()const;
 
    double y()const;
 
    double modulus()const;
 
    double argument()const;
 
// write access functions
 
    point2d & x(double xval);
 
    point2d & y(double yval);
 
    point2d & modulus(double mod);
 
    point2d & argument(double degrees);
 
private:
 
    double x_;
 
    double y_;
 
  
};
+
# show all "bath_towels" data
 +
SELECT * FROM bath_towels;
  
point2d::point2d(double xval, double yval): x_(xval), y_(yval) {}
+
# update specific fields in the "color" column
double point2d::x()const { return x_;}
+
UPDATE bath_towels SET color = "Beige"
double point2d::y()const { return y_;}
+
WHERE name = "Harvest";
point2d & point2d::x(double xval){
 
    x_ = xval;
 
    return *this;
 
}
 
point2d & point2d::y(double yval){
 
    y_ = yval;
 
    return *this;
 
}
 
double point2d::modulus() const { return std::sqrt(x_*x_ + y_*y_); }
 
  
point2d & point2d::modulus(double newmod) {
+
UPDATE bath_towels SET color = "Blue"
    double const oldmod(modulus());
+
WHERE name = "Dolphin";
    double const scale(newmod/oldmod);
 
    x_ *= scale;
 
    y_ *= scale;
 
    return *this;
 
}
 
  
double point2d::argument() const {
+
UPDATE bath_towels SET color = "Lilac"
    return degrees(atan2(y_, x_));  
+
WHERE name = "Daisy";
}
+
 
 +
UPDATE bath_towels SET name = "Tempest", color = "Maroon"
 +
WHERE code = "821/9628";
 +
 
 +
# show all "bath_towels" data
 +
SELECT * FROM bath_towels;
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 06:27, 3 August 2012

# use the "my_database" database
USE my_database;

# show all "bath_towels" data
SELECT * FROM bath_towels;

# update specific fields in the "color" column
UPDATE bath_towels SET color = "Beige"
WHERE name = "Harvest";

UPDATE bath_towels SET color = "Blue"
WHERE name = "Dolphin";

UPDATE bath_towels SET color = "Lilac"
WHERE name = "Daisy";

UPDATE bath_towels SET name = "Tempest", color = "Maroon"
WHERE code = "821/9628";

# show all "bath_towels" data
SELECT * FROM bath_towels;