Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please help with all tasks of lab. Here is my header.h #ifndef PARTICLE _ H #define PARTICLE _ H #include struct Coord 3 D {
Please help with all tasks of lab.
Here is my header.h
#ifndef PARTICLEH
#define PARTICLEH
#include
struct CoordD
double x;
double y;
double z;
;
get the distance from the given coordinate to the origin
double lengthconst CoordD p;
return the coordinate that's farthest from the origin
CoordD fartherFromOriginCoordD p CoordD p;
advance the position of the coordinate traveling at a given speed for a
given time
void moveCoordDCoordD ppos, const CoordD pvel, double dt;
struct Particle
public:
double x;
double y;
double z;
double vx;
double vy;
double vz;
static sizet getNumAllocations return numallocations;
void operator newconst sizet t
voidt;
numallocations;
return ::new Particle;
void operator deletevoid const p
numallocations;
freep;
private:
static sizet numallocations;
;
dynamically allocate memory for a particle and initialize it
Particle createParticledouble x double y double z
double vx double vy double vz;
set its velocity to vx vy vz
void setVelocityParticle p double vx double vy double vz;
get its current position
CoordD getPositionconst Particle p;
update particle's position after elapsed time dt
void moveParticleParticle p double dt;
delete all memory allocated for the particle passed by pointer
void deleteParticleconst Particle p;
#endif PARTICLEH
My Current Code. I am keep running into errors and I am not sure what's wrong?
#include
#include
struct CoordD
double x;
double y;
double z;
;
double lengthconst CoordD p
double dist std::sqrtpx px py py pz pz;
return dist;
CoordD fartherFromOriginCoordD p CoordD p
double dist lengthp;
double dist lengthp;
if dist dist
return p;
else
return p;
void moveCoordDCoordD ppos, const CoordD pvel, double dt
pposx pvelx dt;
pposy pvely dt;
pposz pvelz dt;
sizet Particle::numallocations ;
Particle createParticledouble x double y double z
double vx double vy double vz
Particle particle new Particle;
particlex x;
particley y;
particlez z;
particlevx vx;
particlevy vy;
particlevz vz;
return particle;
void setVelocityParticle p double vx double vy double vz
pvx vx;
pvy vy;
pvz vz;
CoordD getPositionconst Particle p
CoordD pos px py pz ;
return pos;
void moveParticleParticle p double dt
moveCoordD&getPositionp &CoordD pvx pvy pvz dt;
void deleteParticleconst Particle p
delete p;
int main
CoordD pointP ;
std::cout "Length of pointP: length&pointP std::endl;
CoordD pointQ ;
CoordD farthest fartherFromOrigin&pointP, &pointQ;
std::cout "Farthest from origin: farthestx farthesty farthestz std::endl;
CoordD pos ;
CoordD vel ;
moveCoordD&pos, &vel, ;
std::cout "New position: pos.x pos.y pos.z std::endl;
Particle particle createParticle;
std::cout "Current position: getPositionparticlex getPositionparticley getPositionparticlez std::endl;
moveParticleparticle;
std::cout "New position: getPositionparticlex getPositionparticley getPositionparticlez std::endl;
deleteParticleparticle;
return ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started