Image

Imagelone_wolf225 wrote in Imagecpp

I've been away from coding too long it seems. Now I have a new project, and I'm getting some errors...and still don't understand what the question means.

Ok, here's the assignment of what I'm trying to do.

Just so you know, these are mathematical vectors like in Calculus, not the data structure vector.

Implement a templated C++ class Vector that manipulates a numeric vector. Your class should be templated with any numerical scalar type T, which supports the operations + (addition), - (subtraction), and * (multiplication). In addition, type T should have constructors T(0), which produces the additive identity elemetn (typically 0) and T(1), which produces the multiplicative identity (typically 1). Your class should provide a constructor, which is given the size of the vector as an argument. It should provide member functions (or operators) for vector addition, vector subtraction, multiplication of a scalar and a vector, and vector dot product. Write a class Complex that implements a complex number by overloading the operators for addition, subtraction, and multiplication. Implement three concrete instances of your class Vector with the scalar types int, double, and Complex, respectively

This part confuses me -- In addition, type T should have constructors T(0), which produces the additive identity elemetn (typically 0) and T(1), which produces the multiplicative identity (typically 1).

This I'm not sure how to construct - Write a class Complex that implements a complex number by overloading the operators for addition, subtraction, and multiplication.

My teacher responded with this about the part I can't understand. Still not sure -- Several people have asked about T(0) and T(1). This requirement essentially implies that your class Complex should have a constructor that takes an int parameter. Then you can call T(0) or T(1) from within the methods of Vector, so that these methods will work correctly even when the vector instance has size 0.

Can anyone help with some clarity on that? I need something to point me in the right direction

Also, in my code, I have the header file for my class like this:

(I have the greater than and less than signs around the template part with int size and typename T. And include iostream. It just wouldn't post correctly for some reason.)

#include <iostream>
using namespace std;

template <int size, typename T>
class Vector {
	T A[size];
	int size;
public:
	Vector( );
	Vector(int x);
    friend Vector operator +(const Vector& a, const Vector& b);
    friend Vector operator -(const Vector& c, const Vector& d);
	friend Vector operator *(const Vector& e, const Vector& f);
	friend ostream& operator<<(ostream& os, const Vector& z);
	Vector vecScalar(T scalar, Vector vec);
	T dotProduct(Vector first, Vector second);
};


It doesn't recognize my constructors when I call them in my .cpp file. I just get a lot of errors. And was that the right way to set up using a template? I'm just having major frustration because I can't see what's wrong with it. Thanks in advance