Написать комментарии к коду. Программирование С++ Нужно пояснение кода. Код с комментариями.
#include
#include
#include
#include
#include
#include
#include
using namespace std;
class Rational
{
public:
Rational() //конструктор по умолчанию
{
num = 0;
den = 1;
}
Rational(int numerator, int denominator)
{
if (denominator 0 && b > 0)
{
if (a > b)
{
a %= b;
}
else
{
b %= a;
}
}//while
return a + b;
}
};
bool operator == (Rational a, Rational b) /перезгузим оператор ==
{
if ((a.Numerator() == b.Numerator()) && (a.Denominator() == b.Denominator()))
{
return true;
}
else {
return false;
}
}
bool operator > (Rational a, Rational b) ) /перезгузим оператор ==
{
return (a.Numerator() / (double)a.Denominator()) > double(b.Numerator() / (double)b.Denominator()); ) /перезгузим оператор ==
}
bool operator < (Rational a, Rational b)
{
return (a.Numerator() / (double)a.Denominator()) < (b.Numerator() / (double)b.Denominator());
}
int main() {
{
const set rs = { {1, 2}, {1, 25}, {3, 4}, {3, 4}, {1, 2} };
if (rs.size() != 3) {
cout << "Wrong amount of items in the set" << endl;
return 1;
}
vector v;
for (auto x : rs) {
v.push_back(x);
}
if (v != vector{ {1, 25}, { 1, 2 }, { 3, 4 }}) {
cout << "Rationals comparison works incorrectly" << endl;
return 2;
}
}
{
map count;
++count[{1, 2}];
++count[{1, 2}];
++count[{2, 3}];
if (count.size() != 2) {
cout << "Wrong amount of items in the map" << endl;
return 3;
}
}
cout << "OK" << endl;
return 0;
}
const n=3;m=4;
var a:array [1..n,1..m] of integer; i,j,k,max:Integer; ind:array [0..1] of Integer=(1,1);
begin
Randomize;
for i:=Low(a) to High(a) do
for j:=Low(a) to High(a[1]) do
a[i,j]:=Random(100);
for i:=Low(a) to High(a) do
begin
writeln;
for j:=Low(a) to High(a[1]) do
write(a[i,j]:3);
end;
max:=a[1,1];
for i:=Low(a) to High(a) do
for j:=Low(a) to High(a[1]) do
if a[i,j]> max then
begin
max:=a[i,j];
ind[0]:=i;
ind[1]:=j;
end;
writeln;
Writeln(' Max element: ',max);
Write(' Index: ');
for i:=0 to 1 do
write(ind[i],' ');
Readln;
end.