int Insert(ZGGZ tp[], int n) { if (n == 0) return -1; int count = n; int i; Disp(tp,count); while(1){ int k; stringinput(tp[count].num, 10, "编号"); k = Locate(tp, count, tp[count].num, 1); if (k < 0) continue; for (i = count; i > k; --i) { tp[i] = tp[i-1]; } stringinput(tp[k].num, 10, "新编号"); stringinput(tp[k].name, 15, "新姓名"); tp[k].jbgz = numberinput("新基本工资"); tp[k].jj = numberinput("新奖金"); tp[k].kk = numberinput("新扣款"); //完成相关计算 tp[k].yfgz = tp[k].jbgz + tp[k].jj - tp[k].kk; tp[k].sk = tp[k].yfgz * 0.4; tp[k].sfgz = tp[k].yfgz - tp[k].sk; count++; saveflag = 1; Disp(tp, count); return count; } }
int main() { ZGGZ gz[N];//60个职工 FILE *fp; int select; char choice; int count=0; fp=fopen("db","ab+"); //判断文件是否打开成功 if(fp==NULL) { printf("\n----------cannot open file"); exit(0); } while(!feof(fp)) { if(fread( &gz[count], sizeof(ZGGZ),1,fp )==1) count++; } fclose(fp); menu(); while(1) { printf("please enter your choice(0-9)\n"); scanf("%d",&select); if(select==0) { if(saveflag==1) { printf("file has changed,do you save it?(y/n)"); getchar(); scanf("%c",&choice); if(choice=='y'||choice=='Y') { Save(gz,count); printf("thank you for your useness\n"); } else printf("thank you for your useness\n"); break; } else { printf("thank you for your useness\n"); break; } } switch(select) { case 1:count=Add(gz,count);break; case 2:count=Del(gz,count);break; case 3:Qur(gz,count);break; case 4:Modify(gz,count);break; case 5:Insert(gz,count);break; case 6:Count(gz,count);break; case 7:Sort(gz,count);break; case 8:Save(gz,count);break; case 9:Disp(gz,count);break; default :Wrong();break; } } return 0; }
FloatArray Element::GetDisplacement(int inode) { FloatArray Disp(Dof); for (int iDof = 0; iDof < Dof; iDof++) { Disp.at(iDof) = Displacement.at(inode*Dof + iDof); } return Disp; }
void Modify(ZGGZ tp[], int n) { if (n == 0) return; int count = n; int k; char select; if (count == 0) { return ; } Disp(tp, count); printf("请输入修改编号\n"); stringinput(tp[count].num, 10, "编号"); if (strcmp(tp[count].num, "0") == 0) { return ; } k = Locate(tp, count, tp[count].num, 1); if (k < 0) return;//未找到直接返回主菜单 printf("修改编号? y or n\n"); scanf("%c", &select);getchar(); if ( select == 'y' || select == 'Y') stringinput(tp[k].num, 10, "新编号"); printf("修改姓名? y or n\n"); scanf("%c", &select);getchar(); if ( select == 'y' || select == 'Y') stringinput(tp[k].name, 15, "新姓名"); printf("修改基本工资? y or n\n"); scanf("%c", &select);getchar(); if ( select == 'y' || select == 'Y') tp[k].jbgz = numberinput("新基本工资"); printf("修改奖金? y or n\n"); scanf("%c", &select);getchar(); if ( select == 'y' || select == 'Y') tp[k].jj = numberinput("新奖金"); printf("修改扣款? y or n\n"); scanf("%c", &select);getchar(); if ( select == 'y' || select == 'Y') tp[k].kk = numberinput("新扣款"); //完成相关计算 tp[k].yfgz = tp[k].jbgz + tp[k].jj - tp[k].kk; tp[k].sk = tp[k].yfgz * 0.4; tp[k].sfgz = tp[k].yfgz - tp[k].sk; saveflag = 1; Disp(tp, count); }
void Analyzer::printresults() { output<<"\n"; output<<" ---- result of analysis -----\n"; output<<"\n"; output.setf(ios::right); output.setf(ios::scientific, ios::floatfield); NodeIter& theNodes = theDomain->getNodes(); Node* theNode; while((theNode = theNodes()) != 0){ int tag=theNode->getTag(); int ndof=theNode->getNumberDOF(); Vector Disp=theNode->getDisp(); output << setw(10) << tag; for(int i=0; i<ndof; i++) output << setw(15) << setprecision(5) << Disp(i); output<<"\n"; } output.flush(); }
static DWORD DJUpdateHostEntry( PHOSTSFILELINE pLine, PCSTR pszShortName, PCSTR pszFqdnName, PCSTR pszRemoveName1, PCSTR pszRemoveName2 ) { DWORD ceError = ERROR_SUCCESS; PHOSTFILEALIAS *aliasPos; //This updates our hostname in a line of the hosts file // 1. pszFqdnName will be added as the primary name in the host entry // 2. pszShortName will be added as the first alias // 3. Whatever was previously the primary name and first alias will be // added as the second and third aliases // 4. If pszRemoveName1 and or pszRemoveName2 are not null, they will // be removed from the alias list if (pszFqdnName == NULL && pszShortName != NULL) { pszFqdnName = pszShortName; pszShortName = NULL; } else if (pszFqdnName != NULL && pszShortName != NULL && !strcasecmp(pszFqdnName, pszShortName)) { pszShortName = NULL; } DJ_LOG_INFO("Adding %s (fqdn %s) to /etc/hosts ip %s, " "removing %s, %s, %s, %s", Disp(pszShortName), Disp(pszFqdnName), Disp(pLine->pEntry->pszIpAddress), Disp(pszShortName), Disp(pszFqdnName), Disp(pszRemoveName1), Disp(pszRemoveName2)); if (pszFqdnName != NULL && (pLine->pEntry->pszCanonicalName == NULL || strcasecmp(pLine->pEntry->pszCanonicalName, pszFqdnName))) { if (pLine->pEntry->pszCanonicalName != NULL) { ceError = DJAddAlias(pLine, pLine->pEntry->pszCanonicalName, FALSE, NULL); BAIL_ON_CENTERIS_ERROR(ceError); CTFreeString(pLine->pEntry->pszCanonicalName); pLine->pEntry->pszCanonicalName = NULL; } ceError = CTAllocateString(pszFqdnName, &pLine->pEntry->pszCanonicalName); BAIL_ON_CENTERIS_ERROR(ceError); pLine->bModified = TRUE; } aliasPos = &pLine->pEntry->pAliasList; if (pszShortName != NULL) { if (pLine->pEntry->pAliasList == NULL || strcasecmp(pLine->pEntry->pAliasList->pszAlias, pszShortName)) { ceError = DJAddAlias(pLine, pszShortName, TRUE, NULL); BAIL_ON_CENTERIS_ERROR(ceError); } //Skip over this so we don't delete it aliasPos = &(*aliasPos)->pNext; } { PCSTR removeStrings[] = { pszShortName, pszFqdnName, pszRemoveName1, pszRemoveName2 }; while (*aliasPos != NULL) { int i; for(i=0; i<sizeof(removeStrings)/sizeof(removeStrings[0]); i++) { if(removeStrings[i] != NULL && !strcasecmp((*aliasPos)->pszAlias, removeStrings[i])) { //Remove it PHOSTFILEALIAS remove = *aliasPos; (*aliasPos) = remove->pNext; DJFreeAlias(remove); pLine->bModified = TRUE; goto removed_entry; } } //Advance to the next entry because nothing was removed. aliasPos = &(*aliasPos)->pNext; removed_entry: ; } } error: return ceError; }
//http://klas-physics.googlecode.com/svn/trunk/src/general/Integrator.cpp (reference) void CVXS_Voxel::EulerStep(void) { double dt = p_Sim->dt; //bool EqMode = p_Sim->IsEquilibriumEnabled(); if (IS_ALL_FIXED(DofFixed)){ //if fixed, just update the position and forces acting on it (for correct simulation-wide summing S.LinMom = Vec3D<double>(0,0,0); S.Pos = OriginalPos + ExtInputScale*ExternalDisp; S.AngMom = Vec3D<double>(0,0,0); S.Angle.FromRotationVector(Vec3D<double>(ExtInputScale*ExternalTDisp)); dS.Force = CalcTotalForce(); } else { Vec3D<> ForceTot = CalcTotalForce(); //TotVoxForce; //DISPLACEMENT S.LinMom = S.LinMom + ForceTot*dt; Vec3D<double> Disp(S.LinMom*(dt*_massInv)); //vector of what the voxel moves if(p_Sim->IsMaxVelLimitEnabled()){ //check to make sure we're not going over the speed limit! vfloat DispMag = Disp.Length(); vfloat MaxDisp = p_Sim->GetMaxVoxVelLimit()*p_Sim->pEnv->pObj->GetLatticeDim(); if (DispMag>MaxDisp) Disp *= (MaxDisp/DispMag); } S.Pos += Disp; //update position (source of noise in float mode??? if (IS_FIXED(DOF_X, DofFixed)){S.Pos.x = OriginalPos.x + ExtInputScale*ExternalDisp.x; S.LinMom.x = 0;} if (IS_FIXED(DOF_Y, DofFixed)){S.Pos.y = OriginalPos.y + ExtInputScale*ExternalDisp.y; S.LinMom.y = 0;} if (IS_FIXED(DOF_Z, DofFixed)){S.Pos.z = OriginalPos.z + ExtInputScale*ExternalDisp.z; S.LinMom.z = 0;} //ANGLE Vec3D<> TotVoxMoment = CalcTotalMoment(); //debug S.AngMom = S.AngMom + TotVoxMoment*dt; //convert Angular velocity to quaternion form ("Spin") Vec3D<double> dSAngVel(S.AngMom * _inertiaInv); CQuat<double> Spin = 0.5 * CQuat<double>(0, dSAngVel.x, dSAngVel.y, dSAngVel.z) * S.Angle; //current "angular velocity" S.Angle += CQuat<double>(Spin*dt); //see above S.Angle.NormalizeFast(); //Through profiling, quicker to normalize every time than check to see if needed then do it... // TODO: Only constrain fixed angles if one is non-zero! (support symmetry boundary conditions while still only doing this calculation) (only works if all angles are constrained for now...) if (IS_FIXED(DOF_TX, DofFixed) && IS_FIXED(DOF_TY, DofFixed) && IS_FIXED(DOF_TZ, DofFixed)){ S.Angle.FromRotationVector(Vec3D<double>(ExtInputScale*ExternalTDisp)); S.AngMom = Vec3D<>(0,0,0); } } //SCALE // S.ScaleMom = S.ScaleMom + CalcTotalScaleForce()*p_Sim->dt; vfloat TempFact = 1.0; if(p_Sim->pEnv->IsTempEnabled()){ //TempFact = (1+(p_Sim->pEnv->CurTemp-p_Sim->pEnv->TempBase)*GetCTE()); //LocalVXC.GetBaseMat(VoxArray[i].MatIndex)->GetCTE()); double ThisTemp = p_Sim->pEnv->pObj->GetBaseMat(GetMaterial())->GetCurMatTemp(); double ThisCTE = GetCTE(); double TempBase = p_Sim->pEnv->GetTempBase(); TempFact = (1+(ThisTemp - TempBase)*ThisCTE); //To allow selective temperature actuation for each different material } if (TempFact < MIN_TEMP_FACTOR) TempFact = MIN_TEMP_FACTOR; S.Scale = TempFact*OriginalSize; //Recalculate secondary: S.AngVel = S.AngMom * _inertiaInv; S.Vel = S.LinMom * _massInv; //vfloat LastKinE = S.KineticEnergy; if(p_Sim->StatToCalc & CALCSTAT_KINE) S.KineticEnergy = 0.5*Mass*S.Vel.Length2() + 0.5*Inertia*S.AngVel.Length2(); //1/2 m v^2 ////Testing: //if (EqMode && S.KineticEnergy < LastKinE){ // S.LinMom *= 0.99; //Vec3D<double>(0,0,0); // S.AngMom *= 0.99; //= Vec3D<double>(0,0,0); // S.Vel *= 0.99; //= Vec3D<>(0,0,0); // S.AngVel*= 0.99; // = Vec3D<>(0,0,0); // //S.KineticEnergy = 0; // S.KineticEnergy = 0.5*Mass*S.Vel.Length2() + 0.5*Inertia*S.AngVel.Length2(); //1/2 m v^2 //} }
int Del(ZGGZ tp[],int n) { /*函数用于先在数组tp中找到满足条件的记录,然后删除该记录。*/ /*-1 delete by number,----------2 delete by name\n"*/ if (n == 0) return -1; int count = n; int i; int select; char choice; int k = -1; while (1) { //输入相关信息 printf("1)按编号删除\n2)按姓名删除\n"); scanf("%d", &select); if (select == 1) {//按编号删除 Disp(tp, count); stringinput(tp[count].num, 10, "编号"); if (strcmp(tp[count].num, "0") == 0) { menu(); break; } while (1) { if (k == 0) break; k = Locate(tp, count, tp[count].num, 1); printf("%d\n", k); if (k >= 0) {//找到目标,进行删除 for (i = k; i < count; ++i) { tp[i] = tp[i+1]; /*printf("i = %d\n", i);*/ } k = 0;//此处k=0表示删除完成,while开始处检测是否有此标记 continue; } printf("编号不存在,重新输入\n"); stringinput(tp[count].num, 10, "编号"); } } else if (select == 2) {//按姓名删除 Disp(tp, count); stringinput(tp[count].name, 15, "姓名"); if (strcmp(tp[count].name, "0") == 0) { menu(); break; } while (1) { if (k == 0) break; k = Locate(tp, count, tp[count].name, 2); printf("%d\n", k); if (k >= 0) {//找到目标,进行删除 for (i = k; i < count; ++i) { tp[i] = tp[i+1]; printf("i = %d\n", i); } k = 0;//此处k=0表示删除完成,while开始处检测是否有此标记 continue; } printf("姓名不存在,重新输入\n"); stringinput(tp[count].name, 15, "姓名"); } } else {//输入错误 printf("请输入正确选项!\n"); break; } count--; saveflag = 1; //如果还要删除,继续;否则退出。 printf("如果还要删除,输入(y or n):"); scanf("%c", &choice);getchar(); if(choice == 'y' || choice == 'Y') continue; printf("\n\n\n\n\n"); menu();//添加操作完成后显示菜单供选择 break; } return count;//删除完成 }