November 2022 1 10 Report
#include
class Rational
{
private:
int chisl, znam;
public:
Rational() { chisl = 0; znam = 0; }
Rational(int a, int b) { chisl = a; znam = b; }
void Mult(Rational x);
Rational operator*(const Rational& x);
void Write();
};
void Rational::Mult(Rational x)
{
chisl = chisl * x.chisl;
znam = znam * x.znam;
}
Rational Rational:: operator*(const Rational& x)
{
Rational result;
result.chisl = chisl * x.chisl;
result.znam = znam * x.znam;
return result;
}
void Rational::Write()
{
std::cout << chisl << "|" << znam << std::endl;
}

int main()
{
Rational n1(2, 3), n2(3, 2);
Rational n3 = n1 * n2;
n3.Write();
return 0;
}

В этом коде нужно передать результат операции умножения по значению.
Please enter comments
Please enter your name.
Please enter the correct email address.
You must agree before submitting.

Answers & Comments


Copyright © 2024 SCHOLAR.TIPS - All rights reserved.