Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/129.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 这是C++;程序,关于添加两个数字_C++ - Fatal编程技术网

C++ 这是C++;程序,关于添加两个数字

C++ 这是C++;程序,关于添加两个数字,c++,C++,这是太平洋问题。类LargeInt的实现将使用动态物理结构来存储整数的各个数字,并将提供一些可以对整数执行的基本I/O和算术运算 特别是,课程应包括: 默认构造函数 一个运算符函数,用于重载运算符+ 用于重载运算符== 一个操作员函数,用于重载操作员 注1:由于LargeInt类不包含指针,因此不需要复制构造函数或析构函数 #include "targetver.h" using namespace std; class LargeInt { private: char datain[20

这是太平洋问题。类
LargeInt
的实现将使用动态物理结构来存储整数的各个数字,并将提供一些可以对整数执行的基本I/O和算术运算

特别是,课程应包括:

  • 默认构造函数
  • 一个运算符函数,用于重载
    运算符+
  • 用于重载
    运算符==
  • 一个操作员函数,用于重载
    操作员
  • 注1:由于
    LargeInt
    类不包含指针,因此不需要复制构造函数或析构函数

    #include "targetver.h"
    using namespace std;
    
    class LargeInt
    {
    private:
      char datain[200];
      int databit[200];
      int len;
      int overflow;
      LargeInt(char *x, int inlen)
      {
        int i = 0;
        int j = inlen - 1;
        len = inlen;
        overflow = 0;
        for (i = 0; i < 200; i++)
        {
          databit[i] = 0;
          datain[i] = '\0';
        }
        for (i = 0; i < len; i++)
        {
          datain[i] = x[j];
          j--;
        }
      }
      ~LargeInt();
      void GetDataBit()
      {
        int i = 0;
        for (i; i < len; i++)
          databit[i] = datain[i] - 48;
      }
    public:
      LargeInt& operator+(LargeInt& data);
      bool operator==(LargeInt& data);
      LargeInt& operator>>(int x);
      LargeInt& operator<<(int x);
    };
    
    bool LargeInt::operator==(LargeInt& data)
    {
      if (this->len != data.len)
        return false;
      else
      {
        for (int i = 0; i < 200; i++)
        {
          if (this->databit[i] == data.databit[i])
            continue;
          else
            return false;
        }
        return true;
      }
    }
    
    LargeInt& LargeInt::operator+(LargeInt& data)
    {
      LargeInt t("0", 0);
      int addlen;
      if (this->len > data.len)
        addlen = this->len;
      else
        addlen = data.len;
      for (int i = 0; i < addlen; i--)
      {
        t.databit[i] = (data.databit[i] + this->databit[i] + t.overflow) % 10;
        if ((data.databit[i] + this->databit[i] + t.overflow) >= 10)
          t.overflow = 1;
      }
      t.len = addlen;
      for (int i = 0; i < addlen; i++)
      {
        t.datain[i] = t.databit[i] + 48;
      }
    
      return t;
    }
    
    #包括“targetver.h”
    使用名称空间std;
    大类
    {
    私人:
    char-datain[200];
    int-databit[200];
    内伦;
    int溢出;
    大容量(字符*x,内部整数)
    {
    int i=0;
    int j=inlen-1;
    len=inlen;
    溢出=0;
    对于(i=0;i<200;i++)
    {
    数据比特[i]=0;
    数据输入[i]='\0';
    }
    对于(i=0;i>(int x);
    大数据和运算符数据位[i]==data.databit[i])
    持续
    其他的
    返回false;
    }
    返回true;
    }
    }
    大和大::运算符+(大和数据)
    {
    大幅度t(0,0);
    int addlen;
    如果(此->len>data.len)
    addlen=此->len;
    其他的
    addlen=data.len;
    对于(int i=0;idatabit[i]+t.overflow)%10;
    如果((data.databit[i]+this->databit[i]+t.overflow)>=10)
    t、 溢出=1;
    }
    t、 len=addlen;
    for(int i=0;i
    当我构建它时,它有一个类似这样的错误

    警告1警告C4172:返回局部变量或临时变量的地址


    移除&并且您的警告应该消失。现在,返回引用了一个变量t,它是调用函数捕获返回时已超出范围的函数的局部变量

    请阅读/尝试设置问题的格式。顺便说一句,什么是太平洋问题?它可能是具体的:-P@Sathish“特定太平洋”?:-P.@teivaz的可能重复,这与这个问题有什么关系?
    LargeInt& LargeInt::operator+(LargeInt& data)