Отчёт (1079127), страница 2
Текст из файла (страница 2)
fraction fraction::operator += (int op2){ //fraction+= int
chisl+= op2*znam;
sokrashenie(chisl, znam);
return *this;
}
fraction fraction::operator += (fraction &op2){ //fraction+= fraction
chisl= chisl*op2.znam+znam*op2.chisl;
znam*= op2.znam;
sokrashenie(chisl, znam);
return *this;
}
fraction fraction::operator += (double op2){ //fraction+= double
fraction temp;
temp= preobraz(op2);
chisl= chisl*temp.znam+znam*temp.chisl;
znam*= temp.znam;
sokrashenie(chisl, znam);
return *this;
}
Файл “Дроби.cpp”.
#include "Class_Drobi.h"
using namespace std;
void main(){
setlocale(0,"russian");
cout<<"Введите дробь: \n";
fraction z;
cin >>z; //-5/3
cout<<"z="<<z<<endl; // z=-1 2/3
cout<<"Проверка конструкторов"<<endl;
fraction fr1(10,14),fr2;
cout<<"fr2="<<fr2<<endl; //fr2=0
cout<<"fr1="<<fr1<<endl; //fr1=5/7
fraction fr("-1 4/8");
cout<<"fr="<<fr<<endl; //fr=-1 1/2
fraction x=z ,y;
cout<<"x="<<x<<endl; //x=-1 2/3
double dbl=-1.25;
fraction f= dbl;
cout<<"f="<<f<<endl; //f=-1 1/4
cout<<"Проверка перегруженной операции '+'"<<endl;
f+= dbl/2;
cout<<"f="<<f<<endl; //f=-1 7/8
y=x+dbl;
cout<<"y="<<y<<endl; //y=-2 11/12
y=dbl+y;
cout<<"y="<<y<<endl; //y=-4 1/6
y+=dbl;
cout<<"y="<<y<<endl; //y=-5 5/12
int i=5;
y+=i;
cout<<"y="<<y<<endl; //y=-5/12
y=x+y;
cout<<"y="<<y<<endl; //y=-2 1/12
y+=x;
cout<<"y="<<y<<endl; //y=-3 3/4
y=i+x;
cout<<"y="<<y<<endl; //y=3 1/3
y=x+i;
cout<<"y="<<y<<endl; //y=3 1/3
y+= dbl+i+x;
cout<<"y="<<y<<endl; //y=5 5/12
system("Pause");
}
Анализ результата.