Калькулятор для дробей с использованием структур.:)

//------------------------------------------------------------------------------------------------
#include <iostream>
using namespace std;
//-------------------------------------------------
struct drob
{
int chisl;
int znam;
};
drob summa (drob, drob);
drob raznost (drob, drob);
drob proizved (drob, drob);
drob delenie (drob, drob);
//--------------------------------------------------
int main()
{
drob drob1, drob2, drob3;
char chp='/', cha='a', oper='z';
while(cha!='n')
{
cout<<"Enter 1st drob in format [3/4]: ";
cin>>drob1.chisl>>chp>>drob1.znam;
cout<<"Enter 2nd drob in format [5/6]: ";
cin>>drob2.chisl>>chp>>drob2.znam;
BIN: cout<<"Enter znak operation (+,-,*,/): ";
cin>>oper;
switch(oper)
{
case '+': drob3=summa(drob1, drob2); break;
case '-': drob3=raznost(drob1, drob2); break;
case '*': drob3=proizved(drob1, drob2); break;
case '/': drob3=delenie(drob1, drob2); break;
default: cout<<" I D I O T ! ! !\n";
goto BIN;
}
if(drob3.chisl==0)
cout<<"Resault: " <<'0'<<endl<<endl;
else
cout<<"Resault: "<<drob3.chisl<<chp<<drob3.znam<<endl<<endl;
cout<<"Continue? (y/n): "; cin>>cha;
cout<<endl;
}
return 0;
}
//-------------------------------------------------------------------
drob summa(drob dr1, drob dr2)
{
drob temp;
temp.chisl = dr1.chisl*dr2.znam+dr1.znam*dr2.chisl;
temp.znam = dr1.znam*dr2.znam;
return temp;
}
//-------------------------------------------------------------------
drob raznost(drob dr1, drob dr2)
{
drob temp;
temp.chisl = (dr1.chisl*dr2.znam)-(dr1.znam*dr2.chisl);
temp.znam = dr1.znam*dr2.znam;
return temp;
}
//-------------------------------------------------------------------
drob proizved (drob dr1, drob dr2)
{
drob temp;
temp.chisl = dr1.chisl*dr2.chisl;
temp.znam = dr1.znam*dr2.znam;
return temp;
}
//-------------------------------------------------------------------
drob delenie(drob dr1, drob dr2)
{
drob temp;
temp.chisl = dr1.chisl*dr2.znam;
temp.znam = dr1.znam*dr2.chisl;
return temp;
}

//------------------------------------------------------------------------------------------------

Хакинг | Главная | Программирование

Hosted by uCoz