= 0, int a = 0, int b = 1) {
int gcd = GCD(a, b);
int aa = c * b + a;
if (aa > 0 && b > 0 || aa < 0 && b < 0) {
this->a = abs(a) % abs(b) / gcd;
this->b = abs(b) / gcd;
this->c = c + abs(a) / abs(b);
}
else
if (aa > 0 && b < 0 || aa < 0 && b > 0) {
this->a = abs(aa) % abs(b) / gcd;
this->b = abs(b) / gcd;
this->c = (-1) * abs(aa) / abs(b);
}
}
fraction Add(int c, int a, int b) {
return fraction(c, a, b);
}
fraction operator +(fraction& x) {
int gcd = GCD((c * b + a) * x.b + (x.c * x.b + x.a) * b, b * x.b);
return fraction(0, ((c * b + a) * x.b + (x.c * x.b + x.a) * b) / gcd, (b * x.b) / gcd);
}
fraction operator -(fraction& x) {
int gcd = GCD((c * b + a) * x.b - (x.c * x.b + x.a) * b, b * x.b);
return fraction(0, ((c * b + a) * x.b - (x.c * x.b + x.a) * b) / gcd, (b * x.b) / gcd);
}
fraction operator *(fraction& x) {
int gcd = GCD((c * b + a)*(x.c * x.b + x.a), b * x.b);
return fraction(0, ((c * b + a)*(x.c * x.b + x.a)) / gcd, (b * x.b) / gcd);
}
fraction operator /(fraction& x) {
int gcd = GCD((c * b + a)* x.b, b * (x.c * x.b + x.a));
return fraction(0, ((c * b + a)* x.b) / gcd, (b * (x.c * x.b + x.a)) / gcd);
}
int A() {
return a;
};
int B() {
return b;
};
int C() {
return c;
};
private:
int GCD(int a, int b) {
a = abs(a);
b = abs(b);
return b ? GCD(b, a % b) : a;
}
int a;
int b;
int c;
};
template <typename T>
class Matrix
{
public:
class wrong_size {};
class wrong_mult {};
void get_size(int h, int w)//размер массива
{
height = h;
width = w;
}
int give_h()//высот массива
{
return height;
}
int give_w()//выдать массив
{
return width;
}
void creation()//создать массив
{
a = new T*[height];
for (int i = 0; i < height; i++)
a[i] = new T[width];
}
void get_val(int i, int j, T val)//присвоение эл-ту массива значениe
{
a[i][j] = val;
}
friend istream& operator»(istream& os, Matrix& z)
{
for (int i = 0; i < z.height; i++)
for (int j = 0; j < z.width; j++)
os » z.a[i][j];
return os;
}
friend ostream& operator«(ostream& os, Matrix& z)
{
for (int i = 0; i < z.height; i++)
{
for (int j = 0; j < z.width; j++)
os « z[i][j] « " ";
os « endl;
}
return os;
}
double* operator[](int i)
{
return a[i];
}
Matrix operator+(Matrix sl)
{
if (height == sl.height && width == sl.width)
{
Matrix i;
i.get_size(height, width);
i.creation();
for (int k = 0; k < height; k++)
for (int j = 0; j < width; j++)
i.get_val(k, j, (a[k][j] + sl[k][j]));
return i;
}
else throw wrong_size();
}
Matrix operator-(Matrix sl)
{
Matrix i;
if (height == sl.height && width == sl.width)
{
i.get_size(height, width);
i.creation();
for (int k = 0; k < height; k++)
for (int j = 0; j < width; j++)
i.get_val(k, j, (a[k][j] - sl[k][j]));
return i;
}
else throw wrong_size();
}
/*
Matrix operator*(Matrix sl)
{
Matrix i;
T sum = 0;
if (sl.height == width)
{
i.get_size(height, sl.width);
i.creation();
for (int k = 0; k < height; k++)
for (int j = 0; j < sl.width; j++)
{
for (int z = 0; z < height; z++)
sum += a[k][z] * sl[j][z];
i.get_val(k, j, sum);
sum = 0;
}
return i;
}
else throw wrong_mult();
}*/
private:
T * *a;
int width, height;
};
template <typename T>
void LOG(Matrix<T> &c)//функция заменяющая все эл-ты массива на их абсолютные величины
{
for (int i = 0; i < c.give_h(); i++)
for (int j = 0; j < c.give_w(); j++)
if (c[i][j] > 0)
{
c.get_val(i, j, log(c[i][j]));
cout « c[i][j];
cout « endl;
};
}
template<typename T>
Славтехоспади не 75 тыс строк
Обсуждают сегодня