getinfo();
完成接收数据。
add_digits();
完成对数据的处理。
display();
完成显示数据。因为我在学类、所以没办法!不过就算不构造类我也是不会呀!

解决方案 »

  1.   

    不是任何程序都应该强套OO的思路的,这个程序就完全没有必要。这个题目考的是算法,下面是答案~~#include <stdio.h>void GetDigitsSum( int num )
    {
           int nTest ;
           int nTestResult ;
           int nResult ;       for(;;)
           {
                  nResult = 0 ;
                  for ( nTest=10;nTest<num*10;nTest*=10 )
                  {
                         nTestResult = (num%nTest)/(nTest/10) ;
                         nResult += nTestResult ;
                  }
                  if ( nResult<10 ) break ;
                  printf("%d -> %d\n",num,nResult) ;
                  num /= 10 ;
           }
    }void main()
    {
           GetDigitsSum(9142345) ;
    }
      

  2.   

    #include <stdio.h>void GetDigitsSum( int num )
    {
          int nTest ;
          int nResult ;      for(;;)
          {
                  nResult = 0 ;
                  for ( nTest=10;nTest<num;nTest*=10 )
                        nResult += num%nTest ;              nResult += num/nTest;              printf("%d -> %d\n",num,nResult) ;              if ( nResult<10 )
     break ;              num  = nResult ;
          }
    }void main()
    {
          GetDigitsSum(9142345) ;
      

  3.   

    其实也很简单,只要做点技巧,得到num的位数就一切都好说!下面给出:
    void add()
    {
         int num;
         cin>>num;
         cout<<"\n";
         int r,result=10;
         for( ;result>9;num=result)
         {
             r=1;                    //初始化num的位数为1
    result=0;
    for(int i=10;num>i;i*=10)
    r+=1;
    cout<<r<<"\n";         //num的位数    
    for(int j=0;j<r;j++)
    {
    result+=num/(int)(pow(10,r-j-1));
    num=num%(int)(pow(10,r-j-1));
    }
    cout<<result<<"\n";    //输出过程中间的result
             cout<<"\n";    
         }
    cout<<"最后答案是:"<<result;      //输出最后结果
        cout<<endl;
    return;}
    我已经编译过,程序通过了,没有错误!给分啊!!!
      

  4.   

    不可能,我在vc6.0中通过了!
    注意,一开始result必须初始化大于9!!
    这样才能通过下面的for语句!
    然后再让result=0,r=1
      

  5.   

    哦,还要
    #include<iostream.h>
    #include<math.h>
      

  6.   

    这个是提议要求的,只要把上面的程序改动一点就可以。#include <stdio.h>int GetDigitsSum( int num )
    {
          int nTest ;
          int nTestResult ;
          int nResult ;      for(;;)
          {
                  nResult = 0 ;
                  for ( nTest=10;nTest<num*10;nTest*=10 )
                  {
                        nTestResult = (num%nTest)/(nTest/10) ;
                        nResult += nTestResult ;
                  }
                  if ( nResult<10 ) break ;
                  num /= 10 ;
          }      return nResult ;
    }void main()
    {
          printf("%d",GetDigitsSum(9142345)) ;
      

  7.   

    int DoWork(int num)
    {
          int NextNum;
          int Result;      NextNum = num/10;
          Result = num - NextNum*10;      if(NextNum>0){
              Result += DoWork(NextNum);
          }
          return Result;
    }这样不也可以吗?
      

  8.   

    To: River_H(小河)你的方法使用了递规,在流程上是正确的(但不是题意的要求~~),不过效率会低一些。
      

  9.   

    再加一个函数不就可以了吗。呵呵int ThisRight(int num)
    {
         int  nRes;
         
         while(nRes=DoWork(num), nRes) >= 10){}     return nRes;
    }
      

  10.   

    再加一个函数不就可以了吗。呵呵应该是这样的
    int ThisRight(int num)
    {
        int  nRes;
        
        while( (nRes=DoWork(num), nRes) >= 10){}    return nRes;
      

  11.   

    多谢大家:
        特别是,jwd_1_cool(三疯) 你的程序我以编译了!谢谢你!
    其他的程序我也会学习的!非常感谢大家!
      

  12.   

    ··································
    ··································
    ··································
    吵吵闹闹有何意?看看最简单的代码:
    int GetSum(int sum)
    {
        while( sum>10 )
        { 
            sum = sum%10 + sum/10;
        }
        return sum;
    }·············· 满意了吧?······························································
    不相信?自己验证去···································
      

  13.   

    借用eion的GetSum,谢谢!
    int add_digits()
    {
      int nResult=m_nNum;
      VERIFY(nResult>=0);
      while(nResult>10)
         nResult=GetSum(nResult);
    return nResult;
    }
      

  14.   

    对了,电离子的程序应该改一下
    int GetSum(int sum)
    {
        while( sum>=10 )
        { 
            sum = sum%10 + sum/10;
        }
        return sum;
    }如果不是sum>=10,使用sum>0,如果数为586时,返回值为10,结果不对