721
edits
Line 81: | Line 81: | ||
===Programming Task=== | ===Programming Task=== | ||
Extend our Point2D class to have the following functions: | |||
<code> | |||
Point2D operator+(Point2D& p2); | |||
<code> | |||
This function should add up two points and return a new Point2D, which is the sum of the two points. | |||
If you implement this function you can then simply write: Point2D sum = p0 + p1; (where p0 and p1 are of the class Point2D) | |||
<code> | |||
Point2D operator/(float f); | |||
</code> | |||
This function should divide a point by the number f and return a new Point2D which is the divided point. | |||
If you implement this function you can then simply write: | |||
<code> | |||
Point2D div = p0 / 5; | |||
</code>(where p0 is of class Point2D) | |||
Write an algorithm that calculates the centroid of the given points | |||
use a for loop to add up any given number of points (for this, out the points into an array and the access the array in the loop!) | |||
If you are curious of the operator+ and operator/ statements, google "cpp operator overloading" ! | If you are curious of the operator+ and operator/ statements, google "cpp operator overloading" ! | ||
Line 96: | Line 102: | ||
Here are the points to calculate the centroid for: | Here are the points to calculate the centroid for: | ||
<code> | <code> | ||
Point2D p0(0,0); | |||
Point2D p1(0,1); | |||
Point2D p2(1,0); | |||
Point2D p3(1,1); | |||
</code> | </code> | ||
And here is a code template to start coding from: https://repl.it/@abnutzer/Homework-2 | And here is a code template to start coding from: https://repl.it/@abnutzer/Homework-2 | ||
Press the "fork" button to work on your own copy of the code! | Press the "fork" button to work on your own copy of the code! | ||
Later in the class, our points will not be two dimensional anymore, but contain different features of our sounds. E.g. it could be 3D: A dimension for the loudness of the bass, one for the mids and one for the treble. In general the resolution of the spectral data will be much higher and thus a point of 128 dimensions or more can be considered. | Later in the class, our points will not be two dimensional anymore, but contain different features of our sounds. E.g. it could be 3D: A dimension for the loudness of the bass, one for the mids and one for the treble. In general the resolution of the spectral data will be much higher and thus a point of 128 dimensions or more can be considered. |