Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

need help with c++ program areas marked TODO #include <cmath> #include <iostream

ID: 3755260 • Letter: N

Question

need help with c++ program areas marked TODO

#include <cmath>

#include <iostream>

#include "Point3DWeighed.h"

// TODO Define Point3DWeighed default constructor

template <class T, class W>

Point3DWeighed<T,W>::Point3DWeighed(const T x1, const T y1, const T z1, const W weight1) :

Point3D<T>(x1, y1, z1), weight(weight1)

{}

// TODO Define Point3DWeighed copy constructor

template <class T, class W>

Point3DWeighed<T,W>::~Point3DWeighed()

{}

template <class T,class W>

W Point3DWeighed<T,W>::getWeight() const

{

return weight;

}

template <class T, class W>

void Point3DWeighed<T,W>::getPoint(T& x1, T& y1, T& z1, W& weight1) const

{

Point3D<T>::getPoint(x1,y1,z1);

weight1=weight;

}

// TODO Define Point3DWeighed setWeight method

// TODO Define Point3DWeighed setPoint method

template<class T, class W>

void Point3DWeighed<T,W>::add(const Point<T>& p1)

{

const Point3DWeighed<T,W> &pp1 = dynamic_cast<const Point3DWeighed<T,W>&>(p1);

Point3D<T>::add(p1);

weight += pp1.weight;

}

template <class T, class W>

bool Point3DWeighed<T,W>::equals (const Point<T>& p1) const

{

// TODO Write equals method body

}

template <class T, class W>

bool Point3DWeighed<T,W>::less (const Point<T>& p1) const

{

const Point3DWeighed<T,W> &pp1 = dynamic_cast<const Point3DWeighed<T,W>&>(p1);

return Point3D<T>::distanceToOrigin()*weight < pp1.distanceToOrigin()*(pp1.weight);

}

template<class T, class W>

void Point3DWeighed<T,W>::print(std::ostream& os) const

{

// TODO Write print method body that

// prints base Point3D object, then ", ", and weight

}

template<class T, class W>

void Point3DWeighed<T,W>::read (std::istream& is)

{

// TODO Write read method body that

// reads base Point3D object, then ",", and weight

// throw exception if there is no ","

if ( s != "," ) throw std::runtime_error( "Expected comma between z and w, got "+s);

}

template <class T, class W>

Point3DWeighed<T,W> operator+(const Point3DWeighed<T,W>& p1, const Point3DWeighed<T,W>& p2)

{

// TODO Write operator+ body

}

Explanation / Answer

#include <cmath>
#include <iostream>
#include "Point3DWeighed.h"

// TODO Define Point3DWeighed default constructor
Point3DWeighed::Point3DWeighed()
{}

template <class T, class W>

Point3DWeighed<T,W>::Point3DWeighed(const T x1, const T y1, const T z1, const W weight1) :

Point3D<T>(x1, y1, z1), weight(weight1)
{}

// TODO Define Point3DWeighed copy constructor
Point3DWeighed::Point3DWeighed(const Point3DWeighed &obj)
{
this->T = *obj.T;
this->W = *obj.W;
  
}

template <class T, class W>

Point3DWeighed<T,W>::~Point3DWeighed()

{}

template <class T,class W>

W Point3DWeighed<T,W>::getWeight() const
{

return weight;

}

template <class T, class W>

void Point3DWeighed<T,W>::getPoint(T& x1, T& y1, T& z1, W& weight1) const
{

Point3D<T>::getPoint(x1,y1,z1);
weight1=weight;

}

// TODO Define Point3DWeighed setWeight method
Point3DWeighed::setWeighed(const W &wgt)
{
this->W = *wgt;
}

// TODO Define Point3DWeighed setPoint method
Point3DWeighed::setPoints(const T &x, const T &y, const T &z )
{
this->T.x1 = *x;
this->T.y1 = *y;
this->T.z1 = *z;
}

template<class T, class W>

void Point3DWeighed<T,W>::add(const Point<T>& p1)
{

const Point3DWeighed<T,W> &pp1 = dynamic_cast<const Point3DWeighed<T,W>&>(p1);
Point3D<T>::add(p1);
weight += pp1.weight;

}

template <class T, class W>

bool Point3DWeighed<T,W>::equals (const Point<T>& p1) const

{

// TODO Write equals method body
this->T = *p1;


}

template <class T, class W>

bool Point3DWeighed<T,W>::less (const Point<T>& p1) const

{

const Point3DWeighed<T,W> &pp1 = dynamic_cast<const Point3DWeighed<T,W>&>(p1);
return Point3D<T>::distanceToOrigin()*weight < pp1.distanceToOrigin()*(pp1.weight);

}

template<class T, class W>

void Point3DWeighed<T,W>::print(std::ostream& os) const

{

// TODO Write print method body that
// prints base Point3D object, then ", ", and weight
cout<<this->T<<","<<this->W;


}

template<class T, class W>

void Point3DWeighed<T,W>::read (std::istream& is)

{

// TODO Write read method body that

// reads base Point3D object, then ",", and weight

// throw exception if there is no ","
cin>>this->T.x1>>this->T.y1>>this->T.z1>>s>>this->W.weight1

if ( s != "," ) throw std::runtime_error( "Expected comma between z and w, got "+s);

}

template <class T, class W>

Point3DWeighed<T,W> operator+(const Point3DWeighed<T,W>& p1, const Point3DWeighed<T,W>& p2)

{

// TODO Write operator+ body

}
int main()
{
std::string name;
std::cout << "What is your name? ";
getline (std::cin, name);
std::cout << "Hello, " << name << "! ";
}