Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstring>
- using namespace std;
- class MyVector{
- private:
- int niza[15];
- int broj;
- public:
- MyVector(){
- this->broj=0;
- }
- MyVector(int *niza,int broj){
- this->broj=broj;
- for(int i=0;i<broj;i++)
- this->niza[i]=niza[i];
- }
- friend istream& operator>>(istream &i,MyVector &v){
- i>>v.broj;
- for(int k=0;k<v.broj;k++)
- i>>v.niza[k];
- return i;
- }
- friend ostream& operator<<(ostream &o,MyVector &v){
- o<<"<";int i;
- for(i=0;i<v.broj-1;i++)
- o<<v.niza[i]<<",";
- o<<v.niza[i]<<">"<<endl;
- return o;
- }
- MyVector& operator-=(MyVector &v){
- for(int i=0;i<broj;i++)
- niza[i]-=v.niza[i];
- return *this;
- }
- friend int operator*(MyVector &v1,MyVector &v2){
- int suma=0;
- MyVector rez;
- rez.broj=v1.broj;
- for(int i=0;i<v1.broj;i++)
- suma+=v1.niza[i]*v2.niza[i];
- return suma;
- }
- bool operator<=(MyVector &v){
- int suma1=0,suma2=0;
- for(int i=0;i<broj;i++)
- suma1+=niza[i];
- for(int i=0;i<v.broj;i++)
- suma2+=v.niza[i];
- if(suma1<=suma2)
- return true;
- else return false;
- }
- int& operator[](int index) {
- int pom = -1;
- if (index>=0&&index<broj)
- return niza [index];
- else {
- cout << "Index out of bounds" << endl ;
- return pom;
- }
- }
- MyVector& operator--(){
- for(int i=0;i<broj;i++)
- if(niza[i]>0)
- niza[i]--;
- return *this;
- }
- MyVector operator++(int){
- MyVector tmp(*this);
- for(int i=0;i<broj;i++)
- if(niza[i]<0)
- niza[i]++;
- return tmp;
- }
- };
- int main() {
- int n;
- cin >> n;
- if (n == 1) {
- cout << "Testiranje na operatorite >> i <<" << endl;
- cout << "==============================\n";
- MyVector a;
- MyVector b;
- cin >> a;
- cin >> b;
- cout << a;
- cout << b;
- }
- else if (n == 2) {
- cout << "Testiranje na operatorot -="<< endl;
- cout << "==============================\n";
- int m;
- int niza[15];
- cin >> m;
- for (int i=0; i < m; ++i){
- cin >> niza[i];
- }
- MyVector a(niza,m);
- for (int i=0; i < m; ++i) {
- cin >> niza[i];
- }
- MyVector b(niza,m);
- a -= b;
- cout << a;
- }
- else if (n == 3) {
- cout << "Testiranje na operatorot *"<< endl;
- cout << "==============================\n";
- int m;
- int niza[15];
- cin >> m;
- for (int i=0; i < m; ++i){
- cin >> niza[i];
- }
- MyVector a(niza,m);
- for (int i=0; i < m; ++i) {
- cin >> niza[i];
- }
- MyVector b(niza,m);
- cout << a * b;
- }
- else if (n == 4){
- cout << "Testiranje na operatorot <="<< endl;
- cout << "==============================\n";
- int m;
- int l;
- int niza[15];
- cin >> m;
- for (int i=0; i < m; ++i){
- cin >> niza[i];
- }
- MyVector a(niza,m);
- cin >> l;
- for (int i=0; i < l; ++i) {
- cin >> niza[i];
- }
- MyVector b(niza,l);
- cout << (a <= b);
- }
- else if (n == 5){
- cout << "Testiranje na operatorot []"<< endl;
- cout << "==============================\n";
- int m;
- int niza[15];
- cin >> m;
- for (int i=0; i < m; ++i){
- cin >> niza[i];
- }
- MyVector a(niza,m);
- for (int i=0; i < m; ++i) {
- cin >> niza[i];
- }
- MyVector b(niza,m);
- cout << a[2];
- cout << endl;
- cout << b[3];
- }
- else if (n == 6) {
- cout << "Testiranje na operatorot --"<< endl;
- cout << "==============================\n";
- int m;
- int niza[15];
- cin >> m;
- for (int i=0; i < m; ++i){
- cin >> niza[i];
- }
- MyVector a(niza,m);
- --a;
- cout << a;
- }
- else if (n == 7) {
- cout << "Testiranje na operatorot ++"<< endl;
- cout << "==============================\n";
- int m;
- int niza[15];
- cin >> m;
- for (int i=0; i < m; ++i){
- cin >> niza[i];
- }
- MyVector a(niza,m);
- MyVector b = a++;
- cout << a;
- cout << b;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment