Скажите где косяк??? в умножение перегрузил оператор, а как реализовать умножение двух двоичных чисел!!!????
Это Bin.cpp
Код:
Bin Bin:: operator*(Bin& b1){
int t=0;
int i, n1,n2,s;
char f[2];
if(b1.n.size()>n.size()){s=b1.n.size();}
else{s=n.size();}
b1.n.resize(s);
n.resize(s);
for(b1.it=b1.n.begin(), it=n.begin(), i=0; i<s; i++){
*f=*b1.it;
n1=atoi(f);
_itoa(n1, f, 10);
*f=*it;
n2=atoi(f);
_itoa(n2, f, 10);
n1=n1*n2;
t=0;
if(n1>1){
t=n1/2;
n1=n1%2;
}
_itoa(n1, f, 2);
*b1.it=*f;
if(i<b1.n.size()){b1.it++;}
else{*b1.it='0';}
if(i<n.size()){it++;}
else{*it='0';}
}
if(t>0){
_itoa(t, f, 2);
b1.n.push_back(*f);
}
return b1;
это bin.h
Код:
#ifndef BIN
#define BIN
#include <list>
#include <iostream>
using namespace std;
class Bin{
public:
friend istream& operator>>(istream&, Bin&);
friend ostream& operator<<(ostream&, const Bin&);
Bin operator+(Bin&);
Bin operator-(Bin&);
Bin operator*(Bin&);
Bin operator/(Bin&);
Bin operator%(Bin&);
int operator>(Bin);
int operator<(Bin);
int operator==(Bin);
int operator!=(Bin);
int check();
Bin sign();
private:
list <unsigned char> n;
list <unsigned char>::iterator it;
long Transfer();
friend void conclusion(Bin);
};
#endif
это main.cpp
Код:
#include <cstdlib>
#include <iostream>
#include "Bin.h"
using namespace std;
int main(int argc, char *argv[])
{
string c;
Bin b1, b2;
cout<<"Enter the first number:"<<endl;
cin>>b1;
if(b1.check()){
cout<<"Enter the command(+,-,*,/,%,>,>,!=,==)"<<endl;
cin>>c;
if(c==">" || c=="<" || c=="==" || c=="!=" || c=="+" || c=="*"|| c=="/"|| c=="-"|| c=="%"){
cout<<"Enter the second number:"<<endl;
cin>>b2;
if(b2.check()){
//Операция сложение
if(c=="+"){
b1=b1+b2;
cout<<"Result of additions:"<<endl<<b1; }
// Операция вычитание
if(c=="-"){
if(b1>b2){
b1=b1-b2;
cout<<"Result:"<<endl<<b1;}
else{cout<<"The inadmissible answer!"<<endl;}}
//Операция умножение
if(c=="*"){
b1=b1*b2;
cout<<"Result of multiple:"<<endl<<b1;}
//Операция деление
if(c=="/"){
b1=b1/b2;
cout<<"Result of division:"<<endl<<b1;}
// Операция остаток
if(c=="%"){
b1=b1%b2;
cout<<"Result:"<<endl<<b1;
}
// Операция больше
if(c==">"){
if(b1>b2){
cout<<"The first number more than the second!"<<endl;
}
else{
cout<<"The first number no more than the second!"<<endl;
if(b1==b2){cout<<"The numbers are equal!"<<endl;}
else{cout<<"The first number less than the second!"<<endl;}
}
}
//Операция меньше
if(c=="<"){
if(b1>b2){
cout<<"The first number less than the second!"<<endl;
}
else{
cout<<"The first number no less than the second!"<<endl;
if(b1==b2){cout<<"The numbers are equal!"<<endl;}
else{cout<<"The first number more than the secind!"<<endl;}
}
}
// Операция равно
if(c=="=="){
if(b1==b2){
cout<<"The Numbers are equal!"<<endl;
}
else{
cout<<"The numbers are not equal!"<<endl;
if(b1>b2) {cout<<"The first number more than the second!"<<endl;}
else{cout<<"The first number less than the second!"<<endl;}
}
}
// Операция не равно
if(c=="!="){
if(b1!=b2){
cout<<"The numbers are not equal!"<<endl;
if(b1>b2){cout<<"The first number more than the second!"<<endl;}
else{cout<<"The first number less than the second!"<<endl;}
}
else{cout<<"The numbers are equal!"<<endl;}
}
}
else {cout<<"The second number is incorrect!"<<endl;}
}
else {cout<<" The incorect operations is entered!"<<endl;}
}
else {cout<<"The first number is incorrect!"<<endl;}
system("PAUSE");
return EXIT_SUCCESS;
}