AleksejMoiseev / project

0 stars 1 forks source link

Задание 3: Создайте структуру, описывающую простую дробь. Реализуйте арифметические операции с дробями: сумму, разность, умножение, деление. Учесть возможность сокращения дробей и перевод из неправильной дроби в простую. #132

Open AleksejMoiseev opened 5 years ago

AleksejMoiseev commented 5 years ago

include

include

include

include

using namespace std;

struct frac_t { int a; int b;

};

frac_t add(const frac_t& r1, const frac_t& r2) { int c1, c2; c1 = r1.ar2.b + r2.ar1.b; c2 = r1.b*r2.b;

frac_t res = { c1, c2 };

return res;

}

frac_t minus(const frac_t& r1, const frac_t& r2) { int c1, c2; c1 = r1.ar2.b - r2.ar1.b; c2 = r1.b*r2.b;

frac_t res = { c1, c2 };

return res;

} frac_t multi(const frac_t& r1, const frac_t& r2) { int c1, c2; c1 = r1.a r2.a; c2 = r1.br2.b;

frac_t res = { c1, c2 };

return res;

} frac_t del(const frac_t& r1, const frac_t& r2) { int c1, c2,c; c1 = r1.a / r2.a; c2 = r1.b/r2.b;

frac_t res = { c1, c2 };
c1 > c2 ? c = c1 : c = c2;
for(int i=0;i<c;i++)

return res;

}

int main() { frac_t r1 = { }; frac_t r2 = { }; cout << "vvedite "; cin >> r1.a; cout << "vvedite "; cin >> r1.b; cout << "vvedite "; cin >> r2.a; cout << "vvedite "; cin >> r2.b;

frac_t c= std::move(add(r1, r2));

cout << c.a;
cout << " / ";
cout << c.b;
cout << endl;

//cout << "\n" << r1.a;
//cout << "\n" << r1.b;
//cout << "\n" << r2.a;
//cout << "\n" << r2.b;
/*print_rect(r);
move_rect(r, 1, 2);
print_rect(r);
resize_rect(r, 1, 2);
print_rect(r);*/
return 0;

}

AleksejMoiseev commented 5 years ago

include

include "iostream"

include

include

using namespace std;

struct frac_t { int a; int b;

};

frac_t add(const frac_t& r1, const frac_t& r2) { int c1, c2; c1 = r1.ar2.b + r2.ar1.b; c2 = r1.b*r2.b;

frac_t res = { c1, c2 };

return res;

}

frac_t minus(const frac_t& r1, const frac_t& r2) { int c1, c2; c1 = r1.ar2.b - r2.ar1.b; c2 = r1.b*r2.b;

frac_t res = { c1, c2 };

return res;

} frac_t multi(const frac_t& r1, const frac_t& r2) { int c1, c2; c1 = r1.a r2.a; c2 = r1.br2.b;

frac_t res = { c1, c2 };

return res;

} frac_t del(const frac_t& r1, const frac_t& r2) { int c1, c2, c; c1 = r1.a / r2.a; c2 = r1.b / r2.b;

frac_t res = { c1, c2 };
c1 > c2 ? c = c1 : c = c2;
for (int i = 0; i < c; i++)

    return res;

}

int main() { frac_t r1 = { }; frac_t r2 = { }; cout << "vvedite "; cin >> r1.a; cout << "vvedite "; cin >> r1.b; cout << "vvedite "; cin >> r2.a; cout << "vvedite "; cin >> r2.b;

frac_t c = std::move(add(r1, r2));

cout << c.a;
cout << " / ";
cout << c.b;
cout << endl;

//cout << "\n" << r1.a;
//cout << "\n" << r1.b;
//cout << "\n" << r2.a;
//cout << "\n" << r2.b;
/*print_rect(r);
move_rect(r, 1, 2);
print_rect(r);
resize_rect(r, 1, 2);
print_rect(r);*/
return 0;

}

AleksejMoiseev commented 5 years ago

include

include "iostream"

include

include

using namespace std;

struct frac_t { int a; int b;

};

frac_t add(const frac_t& r1, const frac_t& r2) { int c1, c2; c1 = r1.ar2.b + r2.ar1.b; c2 = r1.b*r2.b;

frac_t res = { c1, c2 };

return res;

}

frac_t minus(const frac_t& r1, const frac_t& r2) { int c1, c2; c1 = r1.ar2.b - r2.ar1.b; c2 = r1.b*r2.b;

frac_t res = { c1, c2 };

return res;

} frac_t multi(const frac_t& r1, const frac_t& r2) { int c1, c2; c1 = r1.a r2.a; c2 = r1.br2.b;

frac_t res = { c1, c2 };

return res;

} frac_t del(const frac_t& r1, const frac_t& r2) { int c1, c2, c; c1 = r1.a / r2.a; c2 = r1.b / r2.b;

frac_t res = { c1, c2 };
c1 > c2 ? c = c1 : c = c2;
for (int i = 0; i < c; i++)

    return res;

}

int main() { frac_t r1 = { }; frac_t r2 = { }; cout << "vvedite "; cin >> r1.a; cout << "vvedite "; cin >> r1.b; cout << "vvedite "; cin >> r2.a; cout << "vvedite "; cin >> r2.b;

frac_t c = std::move(add(r1, r2));

cout << c.a;
cout << " / ";
cout << c.b;
cout << endl;

//cout << "\n" << r1.a;
//cout << "\n" << r1.b;
//cout << "\n" << r2.a;
//cout << "\n" << r2.b;
/*print_rect(r);
move_rect(r, 1, 2);
print_rect(r);
resize_rect(r, 1, 2);
print_rect(r);*/
return 0;

}