vec_t
object
tar.gz
archive of your lab9/ directory, including:
README
file containing
Makefile
.h
headers and .cpp
source)
make clean
before tar
)
sendlab
notes
vec_t
class in the vector.h
interface, providing
the following class member functions:
// constructors (overloaded)
vec_t(double ix=0.0, double iy=0.0, double iz=0.0);
// copy constructor
vec_t(const vec_t& rhs);
// destructor (default ok)
~vec_t();
// assignment operator
vec_t& operator=(const vec_t& rhs);
// accessor/mutator
const double& operator[](int i) const;
double& operator[](int i);
// unary operators
vec_t operator-();
// binary operators
vec_t operator-(const vec_t& rhs);
// friend operators
friend vec_t operator*(const vec_t& lhs, const double& s);
friend vec_t operator*(const double& s, const vec_t& rhs);
// friend i/o functions
friend std::ostream& operator<<(std::ostream& s, const vec_t& rhs);
friend std::ostream& operator<<(std::ostream& s, vec_t *rhs);
friend std::istream& operator>>(std::istream& s, vec_t& rhs);
friend std::istream& operator>>(std::istream& s, vec_t *rhs);
// public member functions
double dot(const vec_t&);
double len();
dot()
and len()
must be implemented in the vec_t
implementation vector.cpp
main()
routine works unaltered:
int main()
{
vec_t v1(1.0, 2.0, 3.0);
vec_t v2(4.0, 5.0, 6.0);
vec_t v3, v4, v5(v2);
// use operator>> intead of fscanf
std::cout << "Enter 3 values for v3" << std::endl;
std::cin >> v3;
// use ostream instead of 'prn' function
std::cout << "v1 = " << v1 << std::endl;
// test operator[]
std::cout << "v2 = " << v2 << std::endl;
v2[1] = 3.0;
v2[0] = v2[2];
std::cout << "v2 = " << v2 << std::endl;
// use ostream instead of 'prn' function
std::cout << "v3 = " << v3 << std::endl;
// test binary operator-
v4 = v1 - v3;
std::cout << "v4 = v1 - v3 = " << v4 << std::endl;
// test operator*
std::cout << "v4 * 5 = " << v4 * 5 << std::endl;
// test global binary operator*
std::cout << "3 * v4 = " << 3 * v4 << std::endl;
// test unary operator-
std::cout << "-v5 = " << -v5 << std::endl;
// test dot product member function
std::cout << "v3 . v4 = " << v3.dot(v4) << std::endl;
// test len product member function
std::cout << "||v4|| = " << v4.len() << std::endl;
}
7 8 9
Enter 3 values for v3
7 8 9
v1 = 1 2 3
v2 = 4 5 6
v2 = 6 3 6
v3 = 7 8 9
v4 = v1 - v3 = -6 -6 -6
v4 * 5 = -30 -30 -30
3 * v4 = -18 -18 -18
-v5 = -4 -5 -6
v3 . v4 = -144
||v4|| = 10.3923