签到

05月11日
尚未签到

共有回帖数 0

    白衫故友

    等级:
    /*Manage.cpp
    **用这个摸版的类。。
    **需要Input() (功能为输入类的所有有需要的数据成员)
    **需要Onput() (功能为返回类的所有有需要的数据成员)
    **需要GetNumber() (功能为输返回类的比较值(大的在前面输出))
    注意:比较的值必须可用比较符号  
    **需要ALLOUTUSE() (功能为输出类的所有有需要的数据成员
    (由于全部输出所以只输出必要的))
    **需要GetName() (功能为返回标认类对象的..用来关于输入string查找
    注意:返回string  
    **最后说一下类里面的数据成员不要为*变量..否则指针指向的东西不会记录  
    *******************************************************************************/
    #ifndef MANAGE
    #define MANAGE
    #includestring
    #includeiostream
    #includefstream
    using namespace std;
    templateclass T
    class IOF{
    public:
          IOF(const char*o="ino",const char*n="ink"){
                             numberfilename=new char[strlen(n)+1];
                             objectfilename=new char[strlen(o)+1];
                             int i;
                             for(i=0;( *(objectfilename+i) = *(o+i) )!='';i++);
                             *(objectfilename+i)='';
                             for(i=0;( *(numberfilename+i) = *(n+i) )!='';i++);
                             *(numberfilename+i)='';
                             }
          ~IOF(){
                 delete[]numberfilename;
                 delete[]objectfilename;
                 }
          bool OutNumberToFile(int const&k);
          bool OutDataToFile(T const* object,int const&k);
          bool InNumberOfFile(int&k);
          bool InDataOfFile(T*object,int&k);
    protected:
             char* numberfilename;
             char* objectfilename;
    };
          templatetypename T
          bool IOFT::OutNumberToFile(int const&k){
               bool fulfill=false;
               ofstream outk(numberfilename,ios::out|ios::binary);
               if(outk){
                        outk.write((char*)&k,sizeof(k));
                        fulfill=true;
                        }
               outk.close();
               return fulfill;
               }
               
               
               
          templatetypename T
          bool IOFT::OutDataToFile(T const* object,int const&k){
               bool fulfill=false;
               ofstream outo(objectfilename,ios::out|ios::binary);  
               if(outo){
                        for(int i=0;ik;i++){
                                outo.seekp(sizeof(T)*i,ios::beg);
                                outo.write((char*)&object,sizeof(T));
                        }
                        fulfill=true;
                        }  
               outo.close();
               return fulfill;          
               }
           
           
           
           
          templatetypename T
          bool IOFT::InNumberOfFile(int&k){
               bool fulfill=false;
               ifstream ink(numberfilename,ios::in|ios::binary);
               if(ink){
                        ink.read((char*)&k,sizeof(k));
                        fulfill=true;
                        }
               ink.close();
               return fulfill;
               }
               
               
               
          templatetypename T
          bool IOFT::InDataOfFile(T*object,int&k){

          bool fulfill=false;
               ifstream ino(objectfilename,ios::in|ios::binary);  
               if(ino){
                        for(int i=0;ik;i++){
                                ino.seekg(sizeof(T)*i,ios::beg);
                                ino.read((char*)&object,sizeof(T));
                        }
                        fulfill=true;
                        }  
               ino.close();
               return fulfill;          
               }
    templateclass T
    class Manage{
         public:
                Manage(const char*objectname,const char*numbername):
                             iof(objectname,numbername){}
                bool ADD();
                bool ALL();
                bool DELETE();
                bool SEE();
                bool MAKEROVER();
         protected:
                   IOFT iof;
    };
                templatetypename T
                bool ManageT::ADD(){
                     int k=0;
                     if(( iof.InNumberOfFile(k) ));
                     T *object=new T[k];
                     if(( iof.InDataOfFile(object,k) ));
                     (object+k)-Input();
                     k++;
                     if(( iof.OutNumberToFile(k) )&&( iof.OutDataToFile(object,k) )){
                          return true;
                          }
                          else{
                          return false;
                          }
                     }
                     
                     
                templatetypename T
                bool ManageT::ALL(){
                     int k=0;
                     if(! ( iof.InNumberOfFile(k) )){
                          return false;
                          }
                     T *object=new T[k];
                     if(! ( iof.InDataOfFile(object,k) )){
                          return false;
                          }
                     for(int i=0;ik-1;i++)
                     for(int j=i+1;jk;j++)
                     {
                             T t;
                             if((object+i)-GetNumber()(object+j)-GetNumber()){
                             t=*(object+i),*(object+i)=*(object+j),*(object+j)=t;
                             }
                     }
                     for(int i=0;ik;i++){
                             cout "NO."i+1"-";
                             (object+i)-ALLOUTUSE();
                             }
                             cout "end";
                             getchar();
                             getchar();
                     return true;
                     }
                 
                 
                templatetypename T
                bool ManageT::DELETE(){
                     int k=0;
                     if(! ( iof.InNumberOfFile(k) )){
                          return false;
                          }
                     T *object=new T[k];
                     if(! ( iof.InDataOfFile(object,k) )){
                          return false;
                          }
                     cout "Input name:(if you input 0 to the end)";
                     string name;
                     int i=0;
                     cin name;
                     while(name!="0")


              {
                     while(ik){
                     if(name==(object+i)-GetName()){
                     (object+i)-Output();
                     cout "nnis it?(if true input 0)";
                     string j;
                     cin j;
                     if(j=="0"){
                              T t;
                              t=*(object+i),
                              *(object+i)=*(object+k-1),
                              *(object+k-1)=t;
                              k--;
                              if(( iof.OutNumberToFile(k) )&&( iof.OutDataToFile(object,k) )){
                                   cout "fulfill!!"endl;
                                   }
                                   else{
                                   return false;
                                   }
                              }                      
                     }
                     i++;
                     }
                     cout "Input name:(if you input 0 to the end)";
                     cin name;
                     }
                     return true;
                     }
                 
                 
                templatetypename T
                bool ManageT::SEE(){
                     int k=0;
                     if(! ( iof.InNumberOfFile(k) )){
                          return false;
                          }
                     T *object=new T[k];
                     if(! ( iof.InDataOfFile(object,k) )){
                          return false;
                          }
                     cout "Input name:(if you input 0 to the end)";
                     string name;
                     cin name;
                     while(name!="0")
                     {
                     int i=0;
                     while(ik){
                     if(name==(object+i)-GetName()){
                     (object+i)-Output();
                     cout "nnis it"endl;
                     }
                     i++;
                     }
                     cout "Input name:(if you input 0 to the end)";
                     cin name;
                     }
                     return true;
                     }
                 
                 
                templatetypename T
                bool ManageT::MAKEROVER(){
                     int k=0;
                     if(! ( iof.InNumberOfFile(k) )){
                          return false;
                          }
                     T *object=new T[k];
                     if(! ( iof.InDataOfFile(object,k) )){
                          return false;
                          }
                     cout "Input name:(if you input 0 to the end)";
                     string name;
                     int i=0;
                     cin name;
                     while(name!="0")
                     {
                     while(ik){
                     if(name==(object+i)-GetName()){
                     (object+i)-Output();
                     cout "nnis it?(if true input 0)";
                     string j;
                     cin j;
                     if(j=="0"){
                                (object+i)-Input();
                                if(( iof.OutNumberToFile(k) )&&( iof.OutDataToFile(object,k) )){
                                   cout "fulfill!!"endl;
                                   }
                                   else{
                                   return false;
                                   }
                              }                      
                     }
                     i++;
                     }
                     cout "Input name:(if you input 0 to the end)";
                     cin name;
                     }
                     return true;
                     }
    #endif

    楼主 2016-01-23 10:49 回复

共有回帖数 0
  • 回 帖
  • 表情 图片 视频
  • 发表

登录直线网账号

Copyright © 2010~2015 直线网 版权所有,All Rights Reserved.沪ICP备10039589号 意见反馈 | 关于直线 | 版权声明 | 会员须知