Need help with this C++ Code: #ifndef POINT3DWEIGHED_H_ #define POINT3DWEIGHED_H
ID: 3756762 • Letter: N
Question
Need help with this C++ Code:
#ifndef POINT3DWEIGHED_H_
#define POINT3DWEIGHED_H_
// TODO include iostream declarations but not definitions
#include "Point3D.h"
template<class T, class W>
class Point3DWeighed : public Point3D<T>
{
public:
// TODO Declare default constructor
// TODO Declare constructor from x, y, z, w
// TODO Declare copy constructor
// TODO Declare destructor
W getWeight() const;
void getPoint(T& x1, T& y1, T& z1, W& weight1) const;
// TODO Declare matching setWeight
// TODO Declare matching setPoint
// virtual T distanceToOrigin() const override; from Point3D
// TODO Declare friend operator+
protected:
W weight;
// TODO Declare protected functions below.
// TODO add
// TODO equals
// TODO less
// TODO print
// TODO read
// TODO Use keywords virtual, const, and override appropriately
};
#include "Point3DWeighed-impl.h"
#endif /* POINT3DWEIGHED_H_ */
#pragma once
Here's the Point3D.h which might be needed for above code.
Point 3D.h
#ifndef POINT3D_H_
#define POINT3D_H_
#include <iosfwd> // include iostream declarations but not definitions
#include "Point2D.h"
template<class T>
class Point3D : public Point2D<T>
{
public:
Point3D();
Point3D(T x, T y, T z);
Point3D(const Point3D& point);
virtual ~Point3D() override;
T getZ() const;
void getPoint(T& x1, T& y1, T& z1) const;
void setZ(const T z);
void setPoint(const T x1, const T y1, const T z1);
virtual T distanceToOrigin() const override;
template <class U>
friend Point3D<U> operator+(const Point3D<U>& p1, const Point3D<U>& p2);
protected:
T z;
virtual T multiply(const Point<T>& p1) const override;
virtual void add(const Point<T>& p1) override;
virtual bool equals(const Point<T>& p1) const override;
virtual bool less(const Point<T>& p1) const override;
virtual void print(std::ostream& os) const override;
virtual void read(std::istream& is) override;
};
#include "Point3D-impl.h"
#endif /* POINT3D_H_ */
#pragma once
Explanation / Answer
void testPoint3DWeighed()
{
cout<<" --------- testing PA3 Point3Weighed class "
<<"and abstract class Point, Point2D, Point3d, Point3DWeighed "
<<"standalone function findMinDistanceToOrigin() and create your "
<<"own standalone finction findMinDistanceBetweenTwoPoints() ";
// ifstream fin;
// ofstream fout;
// string fileNameI, fileNameO;
typedef Point3DWeighed<double,double> MyPoint;
double minDistance;
MyPoint minPoint;
vector<MyPoint*> a;
fillVector(fin, a);
findPointMinDistanceToOrigin(a,minDistance,minPoint);
const string info = "testing vector of Point3DWeighed";
printResult( fout, info, a, minDistance, minPoint );
printResult( cout, info, a, minDistance, minPoint );
}
{
std::string s;
is >> s;
if ( s != "[" ) throw std::runtime_error( "Expected [, got "+s);
a.clear();
// char c = ' ';
// while ( std::isspace(c) ) is >> c;
P *temp1 = new P;
is>>*temp1;
a.push_back(temp1);
if ( !is ) throw std::runtime_error( "Invalid P input format" );
is>>op;
P *temp2 = new P;
is>>*temp2;
if ( !is ) throw std::runtime_error( "Invalid P input format" );
a.push_back(temp2);
is >> s;
if ( s != "]" ) throw std::runtime_error( "Expected ], got "+s);
if ( !is ) throw std::runtime_error( "Invalid vector input format" );
}
p1 = closestP ? *closestP : P();
}
template<class P>
void fill2VectorsOp(
std::istream &is,
std::vector<P*> &a,
std::string &op
)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.