【问题】
xxxxxxxxxx22 1/ 分类页样式 began /2.category-list-link:hover{3 transform: scale(1.1);4 box-shadow: 10px 10px 15px 2px rgba(0,0,0,.12), 0 0 6px 0 rgba(104, 104, 105, 0.1);5 border-radius: 15px;6 padding: 6px 16px;7 margin-left: 0px;8 font-size: 16px;9 transition-duration: 0.15s;10 //display:flex;11}12a.category-list-link:before{13 top: 10px;14 width: 18px;15 height: 18px;16 content: “📚”;17 margin-right: 5px;18 font: normal normal normal 14px/1 FontAwesome;19 font-size: 15px;20 line-height: 18px;21}22/ 分类页样式 end /css
(1)输出结果是最简分数(可以是带分数);
(2)分母为1,只输出分子。
【输入形式】
提示“Input x: ”,输入第一个分数。如:1/6
提示“Input y: ”,输入第二个分数。如:2/9
【输出形式】
提示并输出+、-、*、/的结果,如
x+y=7/18
x-y=-1/18
x*y=1/27
x/y=3/4
【样例输入】
Input x: 1/6
Input y: 2/9
【样例输出】
x+y=7/18
x-y=-1/18
x*y=1/27
x/y=3/4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
| #include <iostream> #include <cmath> using namespace std; class CFraction { private: int nume; int deno; public: CFraction(int nu = 0, int de = 1) :nume(nu), deno(de) {} void simplify();
friend istream &operator>>(istream &in, CFraction &x); friend ostream &operator<<(ostream &out, CFraction x);
friend CFraction operator+(const CFraction &c1, const CFraction &c2); friend CFraction operator-(const CFraction &c1, const CFraction &c2); friend CFraction operator*(const CFraction &c1, const CFraction &c2); friend CFraction operator/(const CFraction &c1, const CFraction &c2);
};
void CFraction::simplify() { int nume_ = abs(nume), deno_ = abs(deno);
if (nume < 0 && deno < 0) { nume *= -1; deno *= -1; } else if (nume > 0 && deno < 0) { nume *= -1; deno *= -1; }
while (deno_ % nume_ != 0) { int temp = deno_; deno_ = nume_; nume_ = temp % nume_; } nume /= nume_; deno /= nume_;
} istream &operator>>(istream &in, CFraction &x) { char temp; in >> x.nume >> temp >> x.deno; return in; } ostream &operator<<(ostream &out, CFraction x) { if (x.deno != 1) out << x.nume << '/' << x.deno; else out << x.nume; return out; } CFraction operator+(const CFraction &c1, const CFraction &c2) { CFraction temp(c1.nume * c2.deno + c2.nume * c1.deno, c1.deno * c2.deno); temp.simplify(); return temp; } CFraction operator-(const CFraction &c1, const CFraction &c2) { CFraction temp(c1.nume * c2.deno - c2.nume * c1.deno, c1.deno * c2.deno); temp.simplify(); return temp; } CFraction operator*(const CFraction &c1, const CFraction &c2) { CFraction temp(c1.nume * c2.nume, c1.deno * c2.deno); temp.simplify(); return temp; } CFraction operator/(const CFraction &c1, const CFraction &c2) { CFraction temp(c1.nume * c2.deno, c1.deno * c2.nume); temp.simplify(); return temp; }
int main() { CFraction x, y, s; cout << "Input x: "; cin >> x; cout << "Input y: "; cin >> y; s = x + y; cout << "x+y=" << s << endl; s = x - y; cout << "x-y=" << s << endl; s = x * y; cout << "x*y=" << s << endl; s = x / y; cout << "x/y=" << s << endl; return 0; }
|