Question: c++ /** file: ball.cpp ** brief: Ball class - implementation ** author: Andrea Vedaldi **/ #include ball.h #include Ball::Ball() : r(0.1), x(0), y(0), vx(0.3), vy(-0.1),

c++
c++ /** file: ball.cpp ** brief: Ball class - implementation ** author:
/** file: ball.cpp
** brief: Ball class - implementation
** author: Andrea Vedaldi
**/
#include "ball.h"
#include
Ball::Ball()
: r(0.1), x(0), y(0), vx(0.3), vy(-0.1), g(9.8), m(1),
xmin(-1), xmax(1), ymin(-1), ymax(1)
{ }
void Ball::step(double dt)
{
double xp = x + vx * dt ;
double yp = y + vy * dt - 0.5 * g * dt * dt ;
if (xmin + r
x = xp ;
} else {
vx = -vx ;
}
if (ymin + r
y = yp ;
vy = vy - g * dt ;
} else {
vy = -vy ;
}
}
void Ball::display()
{
std::cout
}
/** file: ball.cpp
** brief: Ball class - implementation
** author: Andrea Vedaldi
**/
#include "ball.h"
#include
Ball::Ball()
: r(0.1), x(0), y(0), vx(0.3), vy(-0.1), g(9.8), m(1),
xmin(-1), xmax(1), ymin(-1), ymax(1)
{ }
void Ball::step(double dt)
{
double xp = x + vx * dt ;
double yp = y + vy * dt - 0.5 * g * dt * dt ;
if (xmin + r
x = xp ;
} else {
vx = -vx ;
}
if (ymin + r
y = yp ;
vy = vy - g * dt ;
} else {
vy = -vy ;
}
}
void Ball::display()
{
std::cout
}
Task 5: Member functions and separation of concerns. By isolating data members in the protected part of the class definition, the representation of the data (protected data members) can be separated from the operations that apply to it (public member functions). Answer the following questions: How should the class be changed so that a user could be able to get and set the position of the ball? The member functions of a class are often said to encode its "behaviour". Can you find a practical example demonstrating why separating the data representation from its behaviour is useful

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!