-
-
Save anonymous/1ebcd1666fcad9bc9e3f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef _Header_Matrix_ | |
#define _Header_Matrix_ | |
#include "HeaderWektor.h" | |
using namespace std; | |
class Matrix{ | |
private: | |
Wektor **tab; | |
int hei; | |
int len; | |
public: | |
Matrix(); | |
Matrix(int heimat, int lenmat, Wektor **wlista); | |
~Matrix(); | |
Matrix(Matrix &mat); | |
int Hei() { return hei; } | |
int Len() { return len; } | |
Wektor **Tab() { return tab; } | |
Matrix &operator*(int temp); | |
Matrix operator+(Matrix &mat); | |
Matrix &Matrix::operator=(Matrix &mat); | |
friend ostream &operator<<(ostream &os, Matrix &mat); | |
friend Matrix &operator*(int temp, Matrix &mat); | |
}; | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef _Header_Wektor_ | |
#define _Header_Wektor_ | |
#include <iostream> | |
#include <cstdlib> | |
using namespace std; | |
class Wektor{ | |
private: | |
int len; | |
int *tab; | |
public: | |
Wektor(); | |
Wektor(int l, int *t); | |
~Wektor(); | |
Wektor(Wektor &wek); | |
int Len(){ return len; } | |
int *Tab(){ return tab; } | |
Wektor &operator=(Wektor &wek); | |
Wektor operator+(Wektor &wek); | |
Wektor operator-(Wektor &wek); | |
Wektor &operator*(int temp); | |
friend Wektor &operator*(int temp, Wektor &wek); | |
friend ostream &operator<<(ostream &os, Wektor &wek); | |
}; | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "HeaderMatrix.h" | |
void MultWek(Wektor **lista, int iwek); | |
void PlusWek(Wektor **lista, int iwek); | |
void MinusWek(Wektor **lista, int iwek); | |
void ShowWek(Wektor **lista, int iwek); | |
void ShowMat(Matrix **lista, int imat); | |
void MultMat(Matrix **lista, int imat); | |
void PlusMat(Matrix **lista, int imat); | |
int main(){ | |
char ch; | |
cout << "a - WEKTOR\nb - MATRIX: "; | |
cin >> ch; | |
system("cls"); | |
//-------------------------------WEKTOR----------------------------- | |
//iwek - number of vectors, lenwek - lenght of vector | |
if (ch == 'a'){ | |
int *tab; | |
int iwek = 0, lenwek = 0; | |
Wektor **lista = NULL; | |
cout << "Enter the number of vectors: "; | |
cin >> iwek; | |
cout << "Enter the number of dimensions: "; | |
cin >> lenwek; | |
lista = new Wektor*[iwek]; | |
for (int i = 0; i < iwek; i++){ | |
tab = new int[lenwek]; | |
cout << "Wektor " << i + 1 << " enter values: "; | |
for (int j = 0; j < lenwek; j++) | |
cin >> tab[j]; | |
lista[i] = new Wektor(lenwek, tab); | |
delete [] tab; | |
} | |
cout << "a - SUBTRACT\nb - MULTIPLY\nc - SHOW\nd - ADDING\nq - EXIT\n"; | |
cin >> ch; | |
while (ch != 'q'){ | |
system("cls"); | |
switch (ch){ | |
case 'a': | |
MinusWek(lista, iwek); | |
break; | |
case 'b': | |
MultWek(lista, iwek); | |
break; | |
case 'c': | |
ShowWek(lista, iwek); | |
break; | |
case 'd': | |
PlusWek(lista, iwek); | |
break; | |
default: | |
cout << "Error in switch!\n"; | |
} | |
while (cin.get() != '\n') | |
continue; | |
cout << "a - SUBTRACT\nb - MULTIPLY\nc - SHOW\nd - ADDING\nq - EXIT\n"; | |
cin >> ch; | |
} | |
}//-------------------------------MATRIX----------------------------- | |
//imat - number of matricies, heimat - height of matrix, lenmat - lenght of matrix | |
else{ | |
int imat = 0, heimat = 0, lenmat = 0, *tab = NULL; | |
Wektor **wlista; | |
cout << "Enter the number of matrices: "; | |
cin >> imat; | |
Matrix **lista = new Matrix*[imat]; | |
for (int i = 0; i < imat; i++){ | |
cout << "Enter the height of matrix: " << i + 1 << " : "; | |
cin >> heimat; | |
cout << "Enter the lenght of matrix: "; | |
cin >> lenmat; | |
wlista = new Wektor*[heimat]; | |
for (int i = 0; i < heimat; i++){ | |
tab = new int[lenmat]; | |
cout << "Wektor " << i << " enter the values:"; | |
for (int j = 0; j < lenmat; j++) | |
cin >> tab[j]; | |
wlista[i] = new Wektor(lenmat, tab); | |
delete [] tab; | |
} | |
lista[i] = new Matrix(heimat, lenmat, wlista); | |
} | |
cout << "a - SUBTRACT\nb - MULTIPLY\nc - SHOW\nd - ADDING\nq - EXIT\n"; | |
cin >> ch; | |
while (ch != 'q'){ | |
switch (ch){ | |
case 'a': | |
//MinusMat(lista, wysmat); | |
break; | |
case 'b': | |
MultMat(lista, imat); | |
break; | |
case 'c': | |
ShowMat(lista, imat); | |
break; | |
case 'd': | |
PlusMat(lista, imat); | |
break; | |
default: | |
cout << "Error in switch!\n"; | |
} | |
while (getchar() != '\n') | |
continue; | |
cout << "a - SUBTRACT\nb - MULTIPLY\nc - SHOW\nd - ADDING\nq - EXIT\n"; | |
cin >> ch; | |
} | |
system("PAUSE"); | |
} | |
return 0; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "HeaderMatrix.h" | |
//-------------------------CONSTRUCTOR--------------------------- | |
Matrix::Matrix(){ | |
tab = NULL; | |
hei = 0; | |
len = 0; | |
} | |
//------------------------------CONSTRUCTOR------------------------------- | |
Matrix::Matrix(int heimat, int lenmat, Wektor **wlista){ | |
tab = wlista; | |
hei = heimat; | |
len = lenmat; | |
} | |
//--------------------------COPYING CONSTRUCTOR------------------------- | |
Matrix::Matrix(Matrix &mat){ | |
hei = mat.hei; | |
len = mat.len; | |
tab = new Wektor*[hei]; | |
for (int i = 0; i < hei; i++){ | |
tab[i] = new Wektor[len]; | |
*tab[i] = *mat.Tab()[i]; | |
} | |
} | |
//------------------------------DESTRUCTOR------------------------------- | |
Matrix::~Matrix(){ | |
delete [] tab; | |
} | |
//------------------------------OPERATOR <<------------------------------- | |
ostream &operator<<(ostream &os, Matrix &mat){ | |
for (int i = 0; i < mat.Hei(); i++){ | |
os << *mat.Tab()[i]; | |
os <<"\n"; | |
} | |
return os; | |
} | |
//---------------------------SHOW-------------------------------- | |
void ShowMat(Matrix **lista, int imat){ | |
for (int i = 0; i < imat; i++){ | |
cout << *lista[i]; | |
cout << "\n"; | |
} | |
} | |
//------------------------MULTIPLY--------------------------- | |
void MultMat(Matrix **lista, int imat){ | |
int temp; | |
cout << "Enter the number"; | |
cin >> temp; | |
for (int i = 0; i < imat; i++) | |
(*lista[i]) * temp; | |
} | |
//--------------------------OPERATOR *------------------------------------ | |
Matrix &operator*(int temp, Matrix &mat){ | |
return mat * temp; | |
} | |
Matrix &Matrix::operator*(int temp){ | |
for (int i = 0; i < hei; i++) | |
(*tab[i]) * temp; | |
return *this; | |
} | |
//--------------------------OPERATOR +---------------------------------- | |
Matrix Matrix::operator+(Matrix &mat){ | |
Wektor **arr = new Wektor*[hei]; | |
for (int i = 0; i < hei; i++){ | |
arr[i] = new Wektor[len]; | |
*arr[i] = (*tab[i]) + (*mat.Tab()[i]); | |
} | |
Matrix temp(hei, len, arr); | |
return temp; | |
} | |
//---------------------------ADDING---------------------------------- | |
void PlusMat(Matrix **lista, int imat){ | |
Matrix add; | |
cout << *lista[0]; | |
cout << " + "; | |
cout << *lista[1]; | |
cout << " = \n"; | |
add = ((*lista[0]) + (*lista[1])); | |
cout << add; | |
} | |
//-------------------------OPERATOR =------------------------------------ | |
Matrix &Matrix::operator=(Matrix &mat){ | |
delete [] tab; | |
hei = mat.hei; | |
tab = new Wektor*[hei]; | |
for (int i = 0; i < hei; i++){ | |
tab[i] = new Wektor[len]; | |
*tab[i] = (*mat.Tab()[i]); | |
} | |
return *this; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "HeaderWektor.h" | |
//-------------------------CONSTRUCTOR--------------------------- | |
Wektor::Wektor(){ | |
len = 2; | |
tab = new int[len]; | |
tab[0] = 0; | |
tab[1] = 0; | |
} | |
//--------------------------CONSTRUCTOR----------------------------- | |
Wektor::Wektor(int l, int *t){ | |
len = l; | |
tab = new int[len]; | |
for (int i = 0; i < len; i++) | |
tab[i] = t[i]; | |
} | |
//--------------------------COPYING CONSTRUCTOR------------------------- | |
Wektor::Wektor(Wektor &wek){ | |
len = wek.len; | |
tab = new int[len]; | |
for (int i = 0; i < len; i++) | |
tab[i] = wek.Tab()[i]; | |
} | |
//-----------------------------DESTRUCTOR-------------------------------- | |
Wektor::~Wektor(){ | |
delete [] tab; | |
} | |
//-------------------------------OPERATOR =------------------------------- | |
Wektor &Wektor::operator=(Wektor &wek){ | |
delete [] tab; | |
len = wek.len; | |
tab = new int[len]; | |
for (int i = 0; i < len; i++) | |
tab[i] = wek.Tab()[i]; | |
return *this; | |
} | |
//-------------------------------OPERATOR *------------------------------- | |
Wektor &operator*(int temp, Wektor &wek){ | |
return wek * temp; | |
} | |
Wektor &Wektor::operator*(int temp){ | |
for (int i = 0; i < len; i++) | |
tab[i] *= temp; | |
return *this; | |
} | |
//------------------------------OPERATOR <<-------------------------------- | |
ostream &operator<<(ostream &os, Wektor &wek){ | |
for (int i = 0; i < wek.Len(); i++){ | |
os << wek.Tab()[i]; | |
os <<" "; | |
} | |
return os; | |
} | |
//-------------------------------OPERATOR +-------------------------------- | |
Wektor Wektor::operator+(Wektor &wek){ | |
int *arr = new int[len]; | |
for (int i = 0; i < len; i++){ | |
arr[i] = tab[i]; | |
arr[i] += wek.Tab()[i]; | |
} | |
Wektor nowy(len, arr); | |
return nowy; | |
} | |
//-------------------------------OPERATOR - -------------------------------- | |
Wektor Wektor::operator-(Wektor &wek){ | |
int *arr = new int[len]; | |
for (int i = 0; i < len; i++){ | |
arr[i] = tab[i]; | |
arr[i] -= wek.Tab()[i]; | |
} | |
Wektor nowy(len, arr); | |
return nowy; | |
} | |
//-------------------------------SHOW---------------------------- | |
void ShowWek(Wektor **lista, int iwek){ | |
for (int i = 0; i < iwek; i++){ | |
cout << *lista[i]; | |
cout << "\n"; | |
} | |
} | |
//--------------------------MULTIPLY------------------------ | |
void MultWek(Wektor **lista, int iwek){ | |
int temp; | |
cout << "Enter the number: "; | |
cin >> temp; | |
for (int i = 0; i < iwek; i++) | |
(*lista[i]) * temp; | |
} | |
//--------------------------------ADDING----------------------------- | |
void PlusWek(Wektor **lista, int iwek){ | |
Wektor add; | |
cout << *lista[0] << " + " << *lista[1] << " = "; | |
add = ((*lista[0]) + (*lista[1])); | |
cout << add; | |
} | |
//--------------------------------SUBTRACT----------------------------- | |
void MinusWek(Wektor **lista, int iwek){ | |
Wektor sub; | |
cout << *lista[0] << " - " << *lista[1] << " = "; | |
sub = ((*lista[0]) - (*lista[1])); | |
cout << sub; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment