主题:问下下面的程序哪里错了?想写的是大整数类
//HugeInteger.h
#ifndef HUGEINTEGER_H
#define HUGEINTEGER_H
class HugeInteger
{
public:
HugeInteger(int);
void input(int);
void output();
void add(HugeInteger);
void multiply(HugeInteger);
bool isEqualTo(HugeInteger);
private:
int array[40];
};
#endif
//HugeInteger.cpp
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
#include <cmath>
#include "HugeInteger.h"
HugeInteger::HugeInteger(int numb)
{
input(numb);
}
HugeInteger::input(int number)
{
for (int t=0;number/(pow(10,t))!=0;t++)
array[39-t]=number/(pow(10,t));
}
HugeInteger::output()
{
for (int k=0;k!=40;t++)
if (array[k]!=0)
cout<<array[k];
}
HugeInteger::add(HugeInteger biginteger)
{
for (int j=39;j!=-1;j--)
{
array[j]=array[j]+biginteger.array[j];
if (array[j] > 10)
{
array[j-1]++;
array[j]=array[j]-10;
}
}
}
HugeInteger::multiply(HugeInteger bignum)
{
int hold[40]={0};
for (int p=39;p!=-1;p--)
{ for (int r=39;r!=-1;r--)
{
hold[r-(39-p)]=hold[r-(39-p)]+array[p]*bignum.array[r];
if (hold[r]>10)
{
hold[r-1]=hold[r-1]+hold[r]/10;
hold[r]=hold[r]%10;
}
}
}
for (int q=0;q!=40;q++)
array[q]=hold[q];
}
HugeInteger::isEqualTo(HugeInteger b)
{
for (int w=0;w!=40;w++)
{
if (array[w]!=b.array[w])
return 0;
}
return true;
}
//fig_findthenumber.cpp
#include "HugeInteger.h"
int main()
{
HugeInteger one(1);
HugeInteger d(1000);
for(HugeInteger c(-1000);c.isEqualTo (d);c.add(one))
{
for (HugeInteger b(-1000);b.isEqualTo (d);b.add(one))
{
for (HugeInteger a(-1000);a.isEqualTo (d);a.add(one))
{
static HugeInteger a2=a;
static HugeInteger b2=b;
static HugeInteger c2=c;
a2.multiply(a);
a2.multiply(a);
b2.multiply(b);
b2.multiply(b);
c2.multiply(c);
c2.multiply(c);
a2.add (b2);
if (a.isEqualTo (c2))
{
a.output ();
b.output ();
c.output ();
}
a2=a;
b2=b;
c2=c;
}
}
}
return 0;
}
--------------------Configuration: 有理数 - Win32 Debug--------------------
Compiling...
HugeInteger.cpp
d:\cpp\有理数\hugeinteger.cpp(16) : error C2556: 'int __thiscall HugeInteger::input(int)' : overloaded function differs only by return type from 'void __thiscall HugeInteger::input(int)'
d:\cpp\有理数\hugeinteger.h(10) : see declaration of 'input'
d:\cpp\有理数\hugeinteger.cpp(16) : error C2371: 'input' : redefinition; different basic types
d:\cpp\有理数\hugeinteger.h(10) : see declaration of 'input'
d:\cpp\有理数\hugeinteger.cpp(21) : error C2556: 'int __thiscall HugeInteger::output(void)' : overloaded function differs only by return type from 'void __thiscall HugeInteger::output(void)'
d:\cpp\有理数\hugeinteger.h(11) : see declaration of 'output'
d:\cpp\有理数\hugeinteger.cpp(21) : error C2371: 'output' : redefinition; different basic types
d:\cpp\有理数\hugeinteger.h(11) : see declaration of 'output'
d:\cpp\有理数\hugeinteger.cpp(22) : error C2065: 't' : undeclared identifier
d:\cpp\有理数\hugeinteger.cpp(27) : error C2556: 'int __thiscall HugeInteger::add(class HugeInteger)' : overloaded function differs only by return type from 'void __thiscall HugeInteger::add(class HugeInteger)'
d:\cpp\有理数\hugeinteger.h(12) : see declaration of 'add'
d:\cpp\有理数\hugeinteger.cpp(27) : error C2371: 'add' : redefinition; different basic types
d:\cpp\有理数\hugeinteger.h(12) : see declaration of 'add'
d:\cpp\有理数\hugeinteger.cpp(39) : error C2556: 'int __thiscall HugeInteger::multiply(class HugeInteger)' : overloaded function differs only by return type from 'void __thiscall HugeInteger::multiply(class HugeInteger)'
d:\cpp\有理数\hugeinteger.h(13) : see declaration of 'multiply'
d:\cpp\有理数\hugeinteger.cpp(39) : error C2371: 'multiply' : redefinition; different basic types
d:\cpp\有理数\hugeinteger.h(13) : see declaration of 'multiply'
d:\cpp\有理数\hugeinteger.cpp(56) : error C2556: 'int __thiscall HugeInteger::isEqualTo(class HugeInteger)' : overloaded function differs only by return type from 'bool __thiscall HugeInteger::isEqualTo(class HugeInteger)'
d:\cpp\有理数\hugeinteger.h(15) : see declaration of 'isEqualTo'
d:\cpp\有理数\hugeinteger.cpp(56) : error C2371: 'isEqualTo' : redefinition; different basic types
d:\cpp\有理数\hugeinteger.h(15) : see declaration of 'isEqualTo'
fig_findthenumber.cpp
Error executing cl.exe.
有理数.exe - 11 error(s), 0 warning(s)
#ifndef HUGEINTEGER_H
#define HUGEINTEGER_H
class HugeInteger
{
public:
HugeInteger(int);
void input(int);
void output();
void add(HugeInteger);
void multiply(HugeInteger);
bool isEqualTo(HugeInteger);
private:
int array[40];
};
#endif
//HugeInteger.cpp
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
#include <cmath>
#include "HugeInteger.h"
HugeInteger::HugeInteger(int numb)
{
input(numb);
}
HugeInteger::input(int number)
{
for (int t=0;number/(pow(10,t))!=0;t++)
array[39-t]=number/(pow(10,t));
}
HugeInteger::output()
{
for (int k=0;k!=40;t++)
if (array[k]!=0)
cout<<array[k];
}
HugeInteger::add(HugeInteger biginteger)
{
for (int j=39;j!=-1;j--)
{
array[j]=array[j]+biginteger.array[j];
if (array[j] > 10)
{
array[j-1]++;
array[j]=array[j]-10;
}
}
}
HugeInteger::multiply(HugeInteger bignum)
{
int hold[40]={0};
for (int p=39;p!=-1;p--)
{ for (int r=39;r!=-1;r--)
{
hold[r-(39-p)]=hold[r-(39-p)]+array[p]*bignum.array[r];
if (hold[r]>10)
{
hold[r-1]=hold[r-1]+hold[r]/10;
hold[r]=hold[r]%10;
}
}
}
for (int q=0;q!=40;q++)
array[q]=hold[q];
}
HugeInteger::isEqualTo(HugeInteger b)
{
for (int w=0;w!=40;w++)
{
if (array[w]!=b.array[w])
return 0;
}
return true;
}
//fig_findthenumber.cpp
#include "HugeInteger.h"
int main()
{
HugeInteger one(1);
HugeInteger d(1000);
for(HugeInteger c(-1000);c.isEqualTo (d);c.add(one))
{
for (HugeInteger b(-1000);b.isEqualTo (d);b.add(one))
{
for (HugeInteger a(-1000);a.isEqualTo (d);a.add(one))
{
static HugeInteger a2=a;
static HugeInteger b2=b;
static HugeInteger c2=c;
a2.multiply(a);
a2.multiply(a);
b2.multiply(b);
b2.multiply(b);
c2.multiply(c);
c2.multiply(c);
a2.add (b2);
if (a.isEqualTo (c2))
{
a.output ();
b.output ();
c.output ();
}
a2=a;
b2=b;
c2=c;
}
}
}
return 0;
}
--------------------Configuration: 有理数 - Win32 Debug--------------------
Compiling...
HugeInteger.cpp
d:\cpp\有理数\hugeinteger.cpp(16) : error C2556: 'int __thiscall HugeInteger::input(int)' : overloaded function differs only by return type from 'void __thiscall HugeInteger::input(int)'
d:\cpp\有理数\hugeinteger.h(10) : see declaration of 'input'
d:\cpp\有理数\hugeinteger.cpp(16) : error C2371: 'input' : redefinition; different basic types
d:\cpp\有理数\hugeinteger.h(10) : see declaration of 'input'
d:\cpp\有理数\hugeinteger.cpp(21) : error C2556: 'int __thiscall HugeInteger::output(void)' : overloaded function differs only by return type from 'void __thiscall HugeInteger::output(void)'
d:\cpp\有理数\hugeinteger.h(11) : see declaration of 'output'
d:\cpp\有理数\hugeinteger.cpp(21) : error C2371: 'output' : redefinition; different basic types
d:\cpp\有理数\hugeinteger.h(11) : see declaration of 'output'
d:\cpp\有理数\hugeinteger.cpp(22) : error C2065: 't' : undeclared identifier
d:\cpp\有理数\hugeinteger.cpp(27) : error C2556: 'int __thiscall HugeInteger::add(class HugeInteger)' : overloaded function differs only by return type from 'void __thiscall HugeInteger::add(class HugeInteger)'
d:\cpp\有理数\hugeinteger.h(12) : see declaration of 'add'
d:\cpp\有理数\hugeinteger.cpp(27) : error C2371: 'add' : redefinition; different basic types
d:\cpp\有理数\hugeinteger.h(12) : see declaration of 'add'
d:\cpp\有理数\hugeinteger.cpp(39) : error C2556: 'int __thiscall HugeInteger::multiply(class HugeInteger)' : overloaded function differs only by return type from 'void __thiscall HugeInteger::multiply(class HugeInteger)'
d:\cpp\有理数\hugeinteger.h(13) : see declaration of 'multiply'
d:\cpp\有理数\hugeinteger.cpp(39) : error C2371: 'multiply' : redefinition; different basic types
d:\cpp\有理数\hugeinteger.h(13) : see declaration of 'multiply'
d:\cpp\有理数\hugeinteger.cpp(56) : error C2556: 'int __thiscall HugeInteger::isEqualTo(class HugeInteger)' : overloaded function differs only by return type from 'bool __thiscall HugeInteger::isEqualTo(class HugeInteger)'
d:\cpp\有理数\hugeinteger.h(15) : see declaration of 'isEqualTo'
d:\cpp\有理数\hugeinteger.cpp(56) : error C2371: 'isEqualTo' : redefinition; different basic types
d:\cpp\有理数\hugeinteger.h(15) : see declaration of 'isEqualTo'
fig_findthenumber.cpp
Error executing cl.exe.
有理数.exe - 11 error(s), 0 warning(s)