Отчет 2 (1079245), страница 2
Текст из файла (страница 2)
return a <= b;
}
friend ostream& operator << (ostream& out, frac a) // Вывод
{
if (a.n == 0)
out << 0;
else
{
if (a.s == -1)
out << '-';
a.canc ();
if (a.d == 1)
out << a.n;
else
{
int w = a.n / a.d;
if (w != 0)
out << w << ' ';
out << a.n - w * a.d << '/' << a.d;
}
}
return out;
}
private:
void dize () // Реакция на деление на ноль
{
if (d == 0)
{
cout << "Division by zero" << endl;
system ("pause");
exit (1);
}
}
void canc () // Сокращение дроби
{
int i = gdc(n, d);
n /= i;
d /= i;
}
int n; // Числитель
int d; // Знаменатель
int s; // Знак
};
Frac.cpp
#include "stdafx.h"
#include "frac.h"
#include <iostream>
using namespace std;
void main()
{
locale::global (locale ("rus") );
frac a = 7;
frac b = 0.5;
frac c (3, 2);
frac d (5, 1, 4);
frac e = "6 1/2";
a += -0.5;
b *= e;
c -= c;
d /= b;
cout << a << ", " << b << ", " << c << ", " << d << ", " << e << endl;
cout << boolalpha << (a == 6.5) << endl;
cout << boolalpha << (b < 3.75001) << endl;
cout << boolalpha << (c != 0) << endl;
cout << boolalpha << (d >= 10 + b) << endl;
cout << boolalpha << (e <= b + 6)<< endl;
system("pause");
}
Проверка и вывод результата:
11















