I am trying to make this 'homework' :
/*Define class vector with components :
private pointer to integer vector and lenght of vector,
constructor with int parameter which creates zeroth vector with requested lenght,
second constructor int* type which creates vector on example of given array,
operators '>','<','==' which compare two vectors.
Write for class 'vector' operators that'll show '<<' vector on a screen in a shape of [v1,v2,...,vn]
and operator '>>' that will write vector v1,v2,...,vn from keyboard.
Define class NewVector that will inherit from class vector and also have :
variable for saving name of a vector, operator[] which writes el. of vector by requested index - if vector doesn't exist once shall
extend so the operation is correct.
add operator
extra :
function - write vector to a file with name that is also parameter of a class NewVector.
*/
I think I have correct greater, equal... operators from another program but now Im stuck with writing << and >> operators. I could really use some advice and probbably will need more ;p
Here is what I have done so far :
#include <cstdlib>
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
class wektor {
private :
vector <int> number;
int length;
public :
wektor (int len) : length(len)
{
for (int i=0;i<length;i++)
number[i]=0;
}
//wektor(int*);
friend ostream& operator <<(ostream& out_str, wektor v);
friend istream& operator >>(istream in_str, wektor &v);
};
ostream& operator <<(ostream& out_str, wektor v)
{
cout <<" [";
for (int i=0;i<v.length;i++)
{
out_str<<v.number[i]<<",";
//return out_str;
}
return out_str;
cout << "] ";
}
int main(int argc, char *argv[])
{
wektor a(4);
cout <<a;
system("PAUSE");
return EXIT_SUCCESS;
}
The program compiles(Dev C++ - I now its old but im used to it ;/) but It crashes just after start. "The program vector.exe has stopped working bla bla.."
Any ideas ? As you can see I tried to put return out_str; in the 'for' loop - it crashes the same.
Also I have a question, is it possible to write program like that in 1h30min ? Im asking cause this was one of my exam - which I failed.
Thanks in advance,
Notes.


Sign In
Create Account


Back to top









