Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

just answer to do parts , / / = = = = = = = = = = = = = = = = =

just answer to do parts ,//============================================================
// FILE: vector3dT.h
//============================================================
#define __vector3dT_H__
#include
#include
#include
#include
#include
#include
template class vector3d;
typedef vector3d vector3D;
typedef vector3d vector3F;
typedef vector3d vector3I;
typedef vector3d vector3L;
typedef vector3D vec3;
template
class vector3d {// class that serves as both vectors and points
public:
vector3d();
vector3d(const std::string& name, int dims);
vector3d(const std::string& name, int dims, const std::initializer_list& li);
//---------------------------------------------------------------------
T operator[](int i) const;
T& operator[](int i);
//---------------------------------------------------------------------
std::string name() const;
void name(const std::string& name);
T x() const { return data_[0]; }// read-only value of x
T y() const { return data_[1]; }
T z() const { return data_[2]; }
T& x(){ return data_[0]; }// read-write value of x
T& y(){ return data_[1]; }
T& z(){ return data_[2]; }
//---------------------------------------
vector3d& operator+=(const vector3d& v);
vector3d& operator-=(const vector3d& v);
//---------------------------------------------------------------------
vector3d& operator+=(T k);
vector3d& operator-=(T k);
vector3d& operator*=(T k);
vector3d& operator/=(T k);
//---------------------------------------------------------------------
vector3d operator-();
//---------------------------------------------------------------------
friend vector3d operator+(const vector3d& u, const vector3d& v){
check_equal_dims(u, v);
return vector3d(u.name_+"+"+ v.name_, u.dims_,
{ u[0]+ v[0], u[1]+ v[1], u[2]+ v[2],0});
}
friend vector3d operator-(const vector3d& u, const vector3d& v){
check_equal_dims(u, v);
return vector3d(u.name_+"-"+ v.name_, u.dims_,
{ u[0]- v[0], u[1]- v[1], u[2]- v[2],0});
}
//---------------------------------------------------------------------
friend vector3d operator+(const vector3d& v, T k){
return vector3d(v.name_+"+"+ std::to_string(k), v.dims_,{ v[0]+ k, v[1]
+ k, v[2]+ k,0});
}
friend vector3d operator+(T k, const vector3d& v){ return v + k; }
//---------------------------------------------------------------------
friend vector3d operator-(const vector3d& v, T k){
return vector3d(v.name_+"-"+ std::to_string(k), v.dims_,{ v[0]- k, v[1]
- k, v[2]- k,0});
}
friend vector3d operator-(T k, const vector3d& v){ return v *-1+ k; }
//---------------------------------------------------------------------
friend vector3d operator*(const vector3d& v, T k){
return vector3d(v.name_+"*"+ std::to_string(k), v.dims_,{ v[0]* k, v[1]
* k, v[2]* k,0});
};
friend vector3d operator*(T k, const vector3d& v){ return v * k; }
//---------------------------------------------------------------------
friend vector3d operator/(const vector3d& v, T k){
if (k ==0){ throw new std::invalid_argument("divide by zero"); }
double kinv =1.0/ k;
return v * kinv;
}
//-------------------------------------------------

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced Database Systems

Authors: Carlo Zaniolo, Stefano Ceri, Christos Faloutsos, Richard T. Snodgrass, V.S. Subrahmanian, Roberto Zicari

1st Edition

155860443X, 978-1558604438

More Books

Students also viewed these Databases questions