Today read Rujia's book, with the object-oriented overload with the operator to play a large number, he also played an article

Source: Internet
Author: User

#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib>using namespace std; #define MAXN 1002struct bign {int len,s[maxn];bign () {memset (s,0,sizeof (s)); len=1;} string str () const {String res = "    ";    for (int i = 0; i < len; i++) res = (char) (s[i] + ' 0 ') + res;    if (res = = "") res = "0";    cout<< "String str () const\n" <<endl;  return res; }/*bign operator + (const Bign & D) {bign C;}    */bign operator + (const bign& b) const {bign C;    C.len = 0;      for (int i = 0, g = 0; G | | i < MAX (Len, B.len); i++) {int x = g;      if (i < len) x + = S[i];      if (I < B.len) x + = B.s[i];      c.s[c.len++] = x% 10;    g = X/10;    }//cout<< "bign operator + (const bign& b) const\n" <<endl;  return C; }bign operator = (const char *num) {int i;len=strlen (num); for (i=0;i<len;i++) {s[i]=num[len-1-i]-' 0 ';} return *this;}; IStream & operator >> (IStream & in,bign & x) {String S;in>>s;x=s.c_str (); return in;}  ostream& operator << (ostream &out, const bign& x) {out << x.str ();  cout<< "ostream& operator << (ostream &out, const bign& x) \ n" <<endl; return out;} /* Run this program using the console Pauser or add your own getch, System ("pause") or input loop */int main (int argc, Cha r** argv) {int t,k=1,z;bign a,b,c;cin >>t;z=t;while (t--) {cin>>a>>b;//Simply call your own Write function c=a+b;// Addition is to pass the left object as a reference into the overloaded operator +, where = does not use overloaded operators, only requires the system enough//cout<<c;cout << "case" <<k<< ":" <<  Endl;if (k!=z) cout <<a<< "+" <<b<< "=" << C << endl<<endl;  else cout <<a<< "+" <<b<< "=" << c << Endl; The k=k+1;//output stream is also written by its own overloaded function}return 0;}

  

Today read Rujia's book, with the object-oriented overload with the operator to play a large number, he also played an article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.