⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rational.cpp

📁 QT方面的开发
💻 CPP
字号:
// Filename: rational.cc// Overloading functions#include "rational.h"ostream& operator<<(ostream& out, Rational  x) {    return (out << x.m_A << " / " << x.m_Q << '\t');}istream& operator>>(istream& in, Rational& x)// Unprotected Input!!!{    return (in >> x.m_A >> x.m_Q);}void Rational::display() const {        cout << m_A << " / " << m_Q;}bool Rational::operator>(const Rational& other) const {    return ( (double)*this  >  (double) other );}Rational max(Rational r1, Rational r2) {    return (r1 > r2 ? r1: r2);   }int main() {    int     i = 10, j = 5;    float   x = 7.0;    double  y = 14.5;    Rational v(5,0), w(10), z(3.5), zmax;    cout << v << "\tzero denominator?"    << "\nmax(" << i << ", " << j << ") = "    << max(i, j)    << "\nmax(" << x << ", " << y << ") = "    << max(x, y)    << "\nmax(" << i << ", " << z << ") = "    << max(static_cast<Rational>(i), z);    zmax = max(w, z);    cout << "\ngreater(" << w << ", " << z << ") = "    <<  zmax    << "\nEnter two longs for Rational: ";    cin >> w;    cout << "Rational value: "<< w    << "   double value: "<< y    << "\nsum = " << w + y << "\tproduct = "    << w * y  << endl;}/*OOP> gpp rational.ccOOP> ./a.out5 / 1           zero denominator?greater(10, 5) = 10greater(7, 14.5) = 14.5greater(10, 3500 / 1000 ) = 10 / 1greater(10 / 1  , 3500 / 1000   ) = 10 / 1Enter two longs for Rational: 432123Rational value: 432 / 123   double value: 14.5sum = 18.0122   product = 50.9268OOP>*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -