| ²é¿´: 3308 | »Ø¸´: 1 | ||
zhangguoli13Òø³æ (СÓÐÃûÆø)
|
[ÇóÖú]
c++Í·ÎļþÖÐÒѾ¶¨ÒåµÄº¯Êý,ʵÏÖʱÌáʾ²»ÊÇÀàµÄ³ÉÔ±º¯Êý ÒÑÓÐ1È˲ÎÓë
|
|
ÕâÊÇÍ·Îļþ # include <Grids.hpp>//StringGrid # include <Sysdefs.h>//AnsiString # include <fstream>//ifstream ofstream /*µØÖÊ¿â*/ #ifndef GEOLOGY #define GEOLOGY struct geoldata; class geology; /*µØÖÊ¿âÊý¾Ý*/ struct geoldata { AnsiString name;//µØÖ·ÀàÐÍÃû³Æ float E;//ÍÁÌ嵯ÐÔÄ£Á¿ float mu;//ÍÁÌå²´ËÉ±È float gamma;//ÍÁÌåÈÝÖØ float c;//ÍÁÌåÕ³¾ÛÁ¦ float K0;//ÍÁÌå¾²ÍÁѹÁ¦ÏµÊý float phi;//ÍÁÌåĦ²Á½Ç float f[5];//ÍÁÌåĦ²ÁϵÊý }; /*µØÖÊ¿âÀà*/ class geology { protected: int count;//µØÖÊ¿âµØÖ·ÀàÐ͸öÊý£¬0Ϊ¿Õ״̬ bool ischeck;//Êý¾ÝÊÇ·ñ±»¼ì²é¹ý geoldata *data;//µØÖ·ÀàÐ͹¹¼ÜÖ¸Õ룬¶¯Ì¬ÄÚ´æ·ÖÅ䣬˳ÐòÏßÐÔ±í£¬¼òµ¥Êý×é public: geology();//Î޲ι¹Ôì geology(geology const &geol);//¿½±´¹¹Ô죬Ö÷Òª´¦ÀíÖ¸Õë³ÉÔ± ~geology();//Îö¹¹£¬×¢ÒâÊͷſռä geology operator=(const geology &geol);//ÖØÔØ=£¬×÷ÓÃÀàËÆ¿½±´¹¹Ô캯Êý bool add(AnsiString iname,float iE,float imu,float igamma,float ic,float iK_0,float iphi,float if1,float if2,float if3,float if4,float if5);//Ìí¼Ó bool set(AnsiString iname,float iE,float imu,float igamma,float ic,float iK_0,float iphi,float if1,float if2,float if3,float if4,float if5,bool change);//¸ü¸Ä bool dele(int num);//ɾ³ýÖ¸¶¨±êºÅ£¬Èç¹ûÒѾΪ¿Õ£¬×¢ÒâÊͷſռä bool empty();//Çå¿Õ£¬×¢ÒâÊͷſռä bool iswrong(int *num,int *var,AnsiString *reason);//¼ì²é´íÎó£¬ÓÐ´í·µ»Øtrue£¬²¢½«±êºÅ¡¢±äÁ¿¡¢ÔÒòдÈëÏàÓ¦Ö¸ÕëÖ¸¶¨Êý×é int getcount();//·µ»Øcount int getnum(AnsiString findname);//²éÕÒµØÖÊ¿âÃû³Æ·µ»Ø±êºÅ geoldata get(int num);//·µ»ØÏàÓ¦µØÖÊ¿âÊý¾Ý bool gridout(TStringGrid *StringGrid);//½«Êý¾Ý´òÓ¡ÔÚStringGridÉÏ bool gridout(TStringGrid *StringGrid,AnsiString findname,int row);//½«ÏàÓ¦Êý¾Ý´òÓ¡StringGridÔÚÖ¸¶¨ÐÐÉÏ bool excelread(Variant Sheet);//´Óexcelµ¼È룬empty¾ö¶¨ÊÇ·ñ×·¼Ó bool excelwrite(Variant Sheet);//µ¼³öµ½excel bool binread(std::ifstream &infile);//´Ó¶þ½øÖÆÎļþµ¼È룬empty¾ö¶¨ÊÇ·ñ×·¼Ó bool binwrite(std::ofstream &outfile);//±£´æÎª¶þ½øÖÆÎļþ }; #endif ÏÂÃæÊÇÀàµÄʵÏÖ # include <Grids.hpp>//StringGrid # include <Sysdefs.h>//AnsiString # include <fstream>//ifstream ofstream # include "Comobj.hpp" # include "geology.h" /************************************************************************/ geology::geology():count(0),ischeck(false),data(NULL){} /************************************************************************/ geology::geology(geology const &geol) { if(geol.count==0) data=NULL; else { data=new geoldata[geol.count]; for(int i=0;i<geol.count;i++) { data.name=geol.data.name; data.E=geol.data.E; data.mu=geol.data.mu; data.gamma=geol.data.gamma; data.c=geol.data.c; data.K0=geol.data.K0; data.phi=geol.data.phi; data.f[0]=geol.data.f[0]; data.f[1]=geol.data.f[1]; data.f[2]=geol.data.f[2]; data.f[3]=geol.data.f[3]; data.f[4]=geol.data.f[4]; } } count=geol.count; ischeck=geol.ischeck; } /************************************************************************/ geology::~geology() { if(data!=NULL) delete []data; } /************************************************************************/ geology geology::operator=(const geology &geol) { if(this==&geol) return *this; if(count!=0) delete []data; count=geol.count; ischeck=geol.ischeck; if(count==0) return *this; data=new geoldata[geol.count]; for(int i=0;i<geol.count;i++) { data.name=geol.data.name; data.E=geol.data.E; data.mu=geol.data.mu; data.gamma=geol.data.gamma; data.c=geol.data.c; data.K0=geol.data.K0; data.phi=geol.data.phi; data.f[0]=geol.data.f[0]; data.f[1]=geol.data.f[1]; data.f[2]=geol.data.f[2]; data.f[3]=geol.data.f[3]; data.f[4]=geol.data.f[4]; } return *this; } /************************************************************************/ bool geology::add(AnsiString iname,float iE,float imu,float igamma,float ic,float iK_0,float iphi,float if1,float if2,float if3,float if4,float if5) { geoldata *temp; temp=new geoldata[count+2]; if(count==0) { temp[count].name=iname; temp[count].E=iE; temp[count].mu=imu; temp[count].gamma=igamma; temp[count].c=ic; temp[count].K0=iK_0; temp[count].phi=iphi; temp[count].f[0]=if1; temp[count].f[1]=if2; temp[count].f[2]=if3; temp[count].f[3]=if4; temp[count].f[4]=if5; data=temp; count++; return true; } for(int i=0;i<count;i++) { if(data.name==iname) return false; } for(int i=0;i<count;i++) { temp.name=data.name; temp.E=data.E; temp.mu=data.mu; temp.gamma=data.gamma; temp.c=data.c; temp.K0=data.K0; temp.phi=data.phi; temp.f[0]=data.f[0]; temp.f[1]=data.f[1]; temp.f[2]=data.f[2]; temp.f[3]=data.f[3]; temp.f[4]=data.f[4]; } temp[count].name=iname; temp[count].E=iE; temp[count].mu=imu; temp[count].gamma=igamma; temp[count].c=ic; temp[count].K0=iK_0; temp[count].phi=iphi; temp[count].f[0]=if1; temp[count].f[1]=if2; temp[count].f[2]=if3; temp[count].f[3]=if4; temp[count].f[4]=if5; delete data; data=temp; count++; ischeck=false; return true; } /************************************************************************/ bool geology::set(AnsiString iname,float iE,float imu,float igamma,float ic,float iK_0,float iphi,float if1,float if2,float if3,float if4,float if5,bool change) { for(int i=0;i<count;i++) { if(data.name.AnsiCompare(iname)==0) { data.name=iname; data.E=iE; data.mu=imu; data.gamma=igamma; data.c=ic; data.K0=iK_0; data.phi=iphi; data.f[0]=if1; data.f[1]=if2; data.f[2]=if3; data.f[3]=if4; data.f[4]=if5; ischeck=false; return true; } } return false; } /************************************************************************/ bool geology::dele(int num) { if(num>=0&&num<=count-1) { for(int i=num;i<count-1;i++) { data.name=data[i+1].name; data.E=data[i+1].E; data.mu=data[i+1].mu; data.gamma=data[i+1].gamma; data.c=data[i+1].c; data.K0=data[i+1].K0; data.phi=data[i+1].phi; data.f[0]=data[i+1].f[0]; data.f[1]=data[i+1].f[1]; data.f[2]=data[i+1].f[2]; data.f[3]=data[i+1].f[3]; data.f[4]=data[i+1].f[4]; } delete &data[count-1]; //&data[count-1]=NULL; //Õâ¸öÖ¸Õ븶nullʱΪʲôÓдíÎóÄØ£¿ count--; return true; } return false; } /************************************************************************/ bool geology::empty() { if(count==0) return false; delete []data; data=NULL; //ÎÒÊÔ¹ýÁË£¬data²»»á×Ô¶¯Îª¿Õ¡£ count=0; ischeck=true; return true; } /************************************************************************/ bool geology::iswrong(int *num,int *var,AnsiString *reason) { /*1.nameΪ¿Õ£» 2.µ¯ÐÔÄ£Á¿£¬ÍÁÌåÈÝÖØ£¬ÍÁÌåð¤¾ÛÁ¦£¬Ä¦²ÁϵÊý£¬ÍÁÌå¾²ÍÁѹÁ¦ÏµÊý´óÓÚ0 3.²´ËɱÈ0~0.5£» 4¡£ÍÁÌåĦ²Á½Ç0~180. 5.12¸ö²ÎÊýÈÎÒâÒ»¸öΪ¿Õʱ */ return true; } /************************************************************************/ int geology::getcount() { return count; } /************************************************************************/ int geology::getnum(AnsiString findname) { for(int i=0;i<count;i++) { if(data.name.AnsiCompare(findname)==0) return i; } return -1; } /************************************************************************/ geoldata geology::get(int num) { geoldata temp; temp.name=""; if(num>=0&&num<count) return this->data[num]; return temp; } /************************************************************************/ bool geology::gridout(TStringGrid *StringGrid) { int fixr,fixc,sr,sc; fixr=StringGrid->FixedRows; //fixc=StringGrid->FixedCols; sr=StringGrid->RowCount; sc=StringGrid->ColCount; //if(sr<(count+fixr)|sc<12) //StringgridÐÐÊý»òÁÐÊýÌ«ÉÙʱ·µ»Ø // return false; if(sc<12) //stringgridÖ»ÓÐÁÐÊýÌ«ÉÙʱ·µ»Ø¡£ return false; for(int i=0;i<count;i++) { if(i<sr) //ÅжÏÊÇ·ñ³¬³öÁËstringgridµÄÐÐÊý£¬Èç¹û³¬³öÔò²»ÔÙ´òÓ¡ { StringGrid->Cells[0][i+fixr]=data.name; StringGrid->Cells[1][i+fixr]=data.E; StringGrid->Cells[2][i+fixr]=data.mu; StringGrid->Cells[3][i+fixr]=data.gamma; StringGrid->Cells[4][i+fixr]=data.c; StringGrid->Cells[5][i+fixr]=data.K0; StringGrid->Cells[6][i+fixr]=data.phi; StringGrid->Cells[7][i+fixr]=data.f[0]; StringGrid->Cells[8][i+fixr]=data.f[1]; StringGrid->Cells[9][i+fixr]=data.f[2]; StringGrid->Cells[10][i+fixr]=data.f[3]; StringGrid->Cells[11][i+fixr]=data.f[4]; } } return true; } /************************************************************************/ bool geology::gridout(TStringGrid *StringGrid,AnsiString findname,int row) { int fixr,fixc,sr,sc,r; fixr=StringGrid->FixedRows; //fixc=StringGrid->FixedCols; sr=StringGrid->RowCount; //sc=StringGrid->ColCount; r=row+fixr; //if(sr<(count+fixr)|sc<12) // return false; for(int i=0;i<count;i++) { if(data.name.AnsiCompare(findname)==0&&row>=1&&row<=sr) //rowµÄȡֵ·¶Î§Îª1~sr. { StringGrid->Cells[0][r-1]=data.name; StringGrid->Cells[1][r-1]=data.E; StringGrid->Cells[2][r-1]=data.mu; StringGrid->Cells[3][r-1]=data.gamma; StringGrid->Cells[4][r-1]=data.c; StringGrid->Cells[5][r-1]=data.K0; StringGrid->Cells[6][r-1]=data.phi; StringGrid->Cells[7][r-1]=data.f[0]; StringGrid->Cells[8][r-1]=data.f[1]; StringGrid->Cells[9][r-1]=data.f[2]; StringGrid->Cells[10][r-1]=data.f[3]; StringGrid->Cells[11][r-1]=data.f[4]; return true; } } return false; } /************************************************************************/ bool geology::excelread(Variant Sheet) { int HANG,LIE,i(2),j(1); if(count!=0) { delete []data; count=0; } while(!(Sheet.OlePropertyGet("Cells", i, 1).OlePropertyGet("Value")).IsEmpty()) { HANG=i-1; i++; } while(!(Sheet.OlePropertyGet("Cells", 1, j).OlePropertyGet("Value")).IsEmpty()) { LIE=j; j++; } if(!(LIE==12|LIE==0)) { //ShowMessage("µ¼ÈëÎļþ²»·ûºÏ¹æ¶¨£¬ÇëÖØÐÂÑ¡Ôñ"); return false; } for(i=2;i<=HANG+1;i++) { AnsiString iname=Sheet.OlePropertyGet("Cells", i, 1).OlePropertyGet("Value"); float iE=StrToFloat(Sheet.OlePropertyGet("Cells", i, 2).OlePropertyGet("Value")); float imu=StrToFloat(Sheet.OlePropertyGet("Cells", i, 3).OlePropertyGet("Value")); float igamma=StrToFloat(Sheet.OlePropertyGet("Cells", i, 4).OlePropertyGet("Value")); float ic=StrToFloat(Sheet.OlePropertyGet("Cells", i, 5).OlePropertyGet("Value")); float iK_0=StrToFloat(Sheet.OlePropertyGet("Cells", i, 6).OlePropertyGet("Value")); float iphi=StrToFloat(Sheet.OlePropertyGet("Cells", i, 7).OlePropertyGet("Value")); float if1=StrToFloat(Sheet.OlePropertyGet("Cells", i, 8).OlePropertyGet("Value")); float if2=StrToFloat(Sheet.OlePropertyGet("Cells", i, 9).OlePropertyGet("Value")); float if3=StrToFloat(Sheet.OlePropertyGet("Cells", i, 10).OlePropertyGet("Value")); float if4=StrToFloat(Sheet.OlePropertyGet("Cells", i, 11).OlePropertyGet("Value")); float if5=StrToFloat(Sheet.OlePropertyGet("Cells", i, 12).OlePropertyGet("Value")); add(iname,iE,imu,igamma,ic,iK_0,iphi,if1,if2,if3,if4,if5); } return true; } /************************************************************************/ bool geology::excelwrite(Variant Sheet) { Sheet.OlePropertyGet("Cells", 1, 1).OlePropertySet("Value", "µØÖ·ÀàÐÍÃû³Æ"); Sheet.OlePropertyGet("Cells", 1, 2).OlePropertySet("Value", "ÍÁÌ嵯ÐÔÄ£Á¿"); Sheet.OlePropertyGet("Cells", 1, 3).OlePropertySet("Value", "ÍÁÌå²´ËɱÈ"); Sheet.OlePropertyGet("Cells", 1, 4).OlePropertySet("Value", "ÍÁÌåÈÝÖØ"); Sheet.OlePropertyGet("Cells", 1, 5).OlePropertySet("Value", "ÍÁÌåÕ³¾ÛÁ¦"); Sheet.OlePropertyGet("Cells", 1, 6).OlePropertySet("Value", "ÍÁÌå¾²ÍÁѹÁ¦ÏµÊý"); Sheet.OlePropertyGet("Cells", 1, 7).OlePropertySet("Value", "ÍÁÌåĦ²Á½Ç"); Sheet.OlePropertyGet("Cells", 1, 8).OlePropertySet("Value", "ÍÁÌåĦ²ÁϵÊý1"); Sheet.OlePropertyGet("Cells", 1, 9).OlePropertySet("Value", "ÍÁÌåĦ²ÁϵÊý2"); Sheet.OlePropertyGet("Cells", 1, 10).OlePropertySet("Value", "ÍÁÌåĦ²ÁϵÊý3"); Sheet.OlePropertyGet("Cells", 1, 11).OlePropertySet("Value", "ÍÁÌåĦ²ÁϵÊý4"); Sheet.OlePropertyGet("Cells", 1, 12).OlePropertySet("Value", "ÍÁÌåĦ²ÁϵÊý5"); for(int i=2;i<count+2;i++) { Sheet.OlePropertyGet("Cells", i, 1).OlePropertySet("Value", WideString(data[i-2].name)); Sheet.OlePropertyGet("Cells", i, 2).OlePropertySet("Value", data[i-2].E); Sheet.OlePropertyGet("Cells", i, 3).OlePropertySet("Value", data[i-2].mu); Sheet.OlePropertyGet("Cells", i, 4).OlePropertySet("Value", data[i-2].gamma); Sheet.OlePropertyGet("Cells", i, 5).OlePropertySet("Value", data[i-2].c); Sheet.OlePropertyGet("Cells", i, 6).OlePropertySet("Value", data[i-2].K0); Sheet.OlePropertyGet("Cells", i, 7).OlePropertySet("Value", data[i-2].phi); Sheet.OlePropertyGet("Cells", i, 8).OlePropertySet("Value", data[i-2].f[0]); Sheet.OlePropertyGet("Cells", i, 9).OlePropertySet("Value", data[i-2].f[1]); Sheet.OlePropertyGet("Cells", i, 10).OlePropertySet("Value", data[i-2].f[2]); Sheet.OlePropertyGet("Cells", i, 11).OlePropertySet("Value", data[i-2].f[3]); Sheet.OlePropertyGet("Cells", i, 12).OlePropertySet("Value", data[i-2].f[4]); } return true; } /************************************************************************/ bool geology::binread(std::ifstream &infile) { if(!infile) { //ShowMessage("´ò¿ª³ö´í£¡"); return false; } for(int i=0;i<count;i++) { infile.read((char *)&data,sizeof(data)); } infile.read((char *)&count,sizeof(count)); infile.read((char *)&ischeck,sizeof(ischeck)); infile.close(); return true; } /************************************************************************/ bool geology::binwrite(std::ofstream &outfile) { for(int i=0;i<count;i++) { outfile.write((char *)&data,sizeof(data)); } outfile.write((char *)&count,sizeof(count)); outfile.write((char *)&ischeck,sizeof(ischeck)); outfile.close(); return true; } Ö÷ÒªÊÇsetº¯Êý£¬ÔËÐÐʱÌáʾ²»ÊdzÉÔ±º¯Êý |
» ²ÂÄãϲ»¶
ÊÛSCIÒ»ÇøÎÄÕ£¬ÎÒ:8 O5 51O 54,¿ÆÄ¿ÆëÈ«,¿É+¼±
ÒѾÓÐ9È˻ظ´
ÊÛSCIÒ»ÇøÎÄÕ£¬ÎÒ:8 O5 51O 54,¿ÆÄ¿ÆëÈ«,¿É+¼±
ÒѾÓÐ4È˻ظ´
ÊÛSCIÒ»ÇøÎÄÕ£¬ÎÒ:8 O5 51O 54,¿ÆÄ¿ÆëÈ«,¿É+¼±
ÒѾÓÐ6È˻ظ´
ÊÛSCIÒ»ÇøÎÄÕ£¬ÎÒ:8 O5 51O 54,¿ÆÄ¿ÆëÈ«,¿É+¼±
ÒѾÓÐ4È˻ظ´
ÊÛSCIÒ»ÇøÎÄÕ£¬ÎÒ:8 O5 51O 54,¿ÆÄ¿ÆëÈ«,¿É+¼±
ÒѾÓÐ5È˻ظ´
ÊÛSCIÒ»ÇøÎÄÕ£¬ÎÒ:8 O5 51O 54,¿ÆÄ¿ÆëÈ«,¿É+¼±
ÒѾÓÐ5È˻ظ´
ÊÛSCIÒ»ÇøÎÄÕ£¬ÎÒ:8 O5 51O 54,¿ÆÄ¿ÆëÈ«,¿É+¼±
ÒѾÓÐ8È˻ظ´
ÊÛSCIÒ»ÇøÎÄÕ£¬ÎÒ:8 O5 51O 54,¿ÆÄ¿ÆëÈ«,¿É+¼±
ÒѾÓÐ10È˻ظ´
ÊÛSCIÒ»ÇøÎÄÕ£¬ÎÒ:8 O5 51O 54,¿ÆÄ¿ÆëÈ«,¿É+¼±
ÒѾÓÐ6È˻ظ´
ÊÛSCIÒ»ÇøÎÄÕ£¬ÎÒ:8 O5 51O 54,¿ÆÄ¿ÆëÈ«,¿É+¼±
ÒѾÓÐ6È˻ظ´
» ±¾Ö÷ÌâÏà¹Ø¼ÛÖµÌùÍÆ¼ö£¬¶ÔÄúͬÑùÓаïÖú:
c++×Ô¶¨ÒåÍ·Îļþ¸ñʽ
ÒѾÓÐ7È˻ظ´
MFC Öе¥ÎĵµÓ¦ÓóÌÐò¿ò¼Ü ÈçºÎµ÷ÓÃÆäËû¹¦ÄܵĶԻ°¿ò£¿
ÒѾÓÐ13È˻ظ´
masharp
½ð³æ (СÓÐÃûÆø)
- Ó¦Öú: 1 (Ó×¶ùÔ°)
- ½ð±Ò: 1304.7
- É¢½ð: 20
- Ìû×Ó: 183
- ÔÚÏß: 192.2Сʱ
- ³æºÅ: 1017040
- ×¢²á: 2010-05-12
- רҵ: Á÷ÌåÁ¦Ñ§
2Â¥2014-02-26 09:59:02













»Ø¸´´ËÂ¥