void ItemAttributeMgr::Clear(Attr attr) { PyRep *oldValue = NULL; if(GetNotify() == true && !IsRechargable(attr)) { // get old value oldValue = PyGet(attr); } // clear the attribute EVEAdvancedAttributeMgr::Clear(attr); // delete the attribute from DB (no matter if it really is there) if(GetSave() == true) { m_factory.db().EraseAttribute(m_item.itemID(), attr); } if(GetNotify() == true) { std::map<Attr, TauCap>::const_iterator i = m_tauCap.find(attr); if(i != m_tauCap.end()) { // build the special list for rechargables PyList *l = new PyList; l->AddItem( PyGet( attr ) ); l->AddItemLong( Win32TimeNow() ); l->AddItem( _PyGet( GetReal( i->second.tau ) / 5.0 ) ); l->AddItem( PyGet( i->second.cap ) ); oldValue = l; } // send change _SendAttributeChange(attr, oldValue, new PyFloat(GetReal(attr))); } }
static void CollectInfo(){ printf("请输入您的姓名:\n"); name = GetLine(); printf("请输入您的身高(m):\n"); height = GetReal(); printf("请输入您的体重(kg):\n"); weight = GetReal(); }
void GetCoefficients(double *pa, double *pb) { printf("Ten program oblicza pierwiastek równania a*x=b\n"); printf("Podaj a: "); *pa = GetReal(); printf("Podaj b: "); *pb = GetReal(); if (*pa==0) Error("wspólczynnik `a' powinien być różny od 0"); }
void Reader::GetToken() { while (isspace(ch_)) { GetCh(); } switch (ch_) { case '(': token_ = ReaderTokenType::LParen; GetCh(); break; case ')': token_ = ReaderTokenType::RParen; GetCh(); break; case '*': case '+': token_ = ReaderTokenType::Symbol; symbolName_ = std::string(1, ch_); GetCh(); break; case '-': GetCh(); if (isdigit(ch_)) { GetReal(); realVal_ = -realVal_; } else { token_ = ReaderTokenType::Symbol; symbolName_ = std::string(1, '-'); } break; case '.': token_ = ReaderTokenType::Dot; GetCh(); break; case EOF: token_ = ReaderTokenType::EndOfInput; break; default: if (isdigit(ch_)) { GetReal(); } else if (isalpha(ch_)) { GetSymbol(); } else { token_ = ReaderTokenType::Undefined; GetCh(); } break; } }
int main() { double n1,n2,n3,average; printf("This program averages three numbers.\n"); printf("1st number: "); n1=GetReal(); printf("2nd number: "); n2=GetReal(); printf("3nd number: "); n3=GetReal(); average=(n1+n2+n3)/3; printf("The average is %g\n",average); }
void ItemAttributeMgr::SetIntEx(Attr attr, const int_t &v, bool persist) { PyRep *oldValue = NULL; if(GetNotify() == true && !IsRechargable(attr)) { // get old value oldValue = PyGet(attr); } // set the attribute value EVEAdvancedAttributeMgr::SetInt(attr, v); // check if we shall save to DB if(GetSave() == true && (persist || IsPersistent(attr))) { // save to DB m_factory.db().UpdateAttribute_int(m_item.itemID(), attr, v); } if(GetNotify() == true) { std::map<Attr, TauCap>::const_iterator i = m_tauCap.find(attr); if(i != m_tauCap.end()) { // build the special list for rechargables PyList *l = new PyList; l->AddItemInt( v ); l->AddItemLong( Win32TimeNow() ); l->AddItem( _PyGet( GetReal( i->second.tau ) / 5.0 ) ); l->AddItem( PyGet( i->second.cap ) ); oldValue = l; } // send change _SendAttributeChange(attr, oldValue, new PyFloat(v)); } }
/* Reduce a number to its best type (i.e. no complex numbers with 0i, no doubles with 0's after the decimal point, etc */ void ReduceNumber(VyNumber** num){ /* Check that, if it is a double, it isnt an int in disguise */ if(num[0]->type == REAL){ double d = GetDouble(num); /* If it is, change it to an int */ if(d == (int)(d)){ num[0]->type = INT; IntNum* iNum = NumberToSubtype(num); iNum->i = (int)(d); } } /* Check that, if it is a complex number, the imaginary part isn't 0 */ else if(num[0]->type == COMPLEX){ if(EqualsZero(GetImaginary(num))){ /* Make it equal the real part */ VyNumber** realPart = GetReal(num); num[0]->type = realPart[0]->type; switch(num[0]->type){ case INT: ((IntNum*)(NumberToSubtype(num)))->i = GetInt(realPart); break; case REAL: ((RealNum*)(NumberToSubtype(num)))->d = GetDouble(realPart); break; } } } }
static double GetScore(int judge) { double score; while(TRUE){ printf("Score for judge #%d: ",judge); score=GetReal(); if(score>=MinScore && score<=MaxScore) break; printf("That score is out of range. Try again.\n"); } return score; }
/* Asks user for an input and only accepts a number between * 0 and 1 as a valid input. Otherwise it keeps asking * for a valid input. Returns the valid input at the end. */ double GetPercent() { double result = 0; while (true) { result = GetReal(); if ((result >= 0.0) && (result <= 1.0)) break; cout << "Please enter a percent value berween " << "0 and 1." << endl; } return result; }
/* Check whether the number equals 0 */ int EqualsZero(VyNumber** num){ /* Use ANDS and ORS to check */ if((num[0]->type == INT && GetInt(num) == 0) ||(num[0]->type == REAL && GetDouble(num) == 0) ||(num[0]->type == COMPLEX && EqualsZero(GetReal(num)) && EqualsZero(GetImaginary(num))) ||(num[0]->type == RATIO && GetNumerator(num) == 0)){ return 1; } else { return 0; } }
int main(){ int year; float weight; printf("请输入你的出生年:\n"); year = GetInteger(); printf("请输入你的体重:\n"); weight = GetReal(); int w = weight; printf("float转换为int:%d\n",w); int age = 2015 - year; printf("你的年龄是%d,你的体重是%f\n",age,weight); }
int main(){ string name; int year; float weight; printf("请输入你的姓名:\n"); name = GetLine(); //从键盘中获取一行字符串 printf("请输入你的出生年:\n"); year = GetInteger(); printf("请输入你的体重:\n"); weight = GetReal(); int age = 2015 - year; printf("姓名:%-5.10s\t年龄:%-5d\t体重:%.2f\n",name,age,weight); }
int main(void) { int looptimes, ri; double x, y; looptimes = GetInteger(); for (ri = 1; ri <= looptimes; ++ri) { x = GetReal(); y = x == 0 ? 0 : 1 / x; printf("f(%.2f) = %.1f\n", x, y); } return 0; }
int main(){ string name; int year; float weight; printf("请输入你的姓名:\n"); name = GetLine(); //从键盘中获取一行字符串 printf("请输入你的出生年:\n"); year = GetInteger(); printf("请输入你的体重:\n"); weight = GetReal(); int age = 2015 - year; printf("你好,%s,你%d岁了,你的体重是%f\n",name,age,weight); }
int main() { double miles; double kms; printf("Enter the distance in miles> "); miles = GetReal(); kms = KMS_PER_MILE * miles; printf("That equals %g kilometers.\n", kms); return 0; }
static Int32 Factor(void) { Int32 type; switch(Token) { case tINTCONST: vm_genI(op_pushint,GetInt()); NextToken(); type=INT_TYPE; break; case tREALCONST: vm_genR(op_pushreal,GetReal()); NextToken(); type=REAL_TYPE; break; case tSTRINGCONST: vm_genS(op_pushstring,GetString()); NextToken(); type=STRING_TYPE; break; case tNOT: NextToken(); type=Factor(); vm_gen0(op_not); break; case tLPAREN: SkipToken(tLPAREN); type=Expr(); SkipToken(tRPAREN); break; case tLBRACK: ArrayInitializer(); type=ARRAY_TYPE; break; default: type=Rhs(); break; } return type; }
void ChangeTimeInterval(double *time) { string str; while(TRUE) { printf("\nWant to change time interval? "); str=GetLine(); if ( StringEqual(str,"y") || StringEqual(str,"yes") ) { printf("\nTime Interval= "); *time=GetReal(); break; } if ( StringEqual(str,"n") || StringEqual(str,"no") ) { break; } } }
int main() { cout << "Enter radius: "; double radius = GetReal(); double area = 0; double x = radius / Num_rects; for (int i = 0; i < Num_rects; i++) { double xC = x * i; double h = sqrt(pow(radius,2) - pow(xC,2)); area += h * x; } cout << "Approximate area of a quarter Arch of radius " << radius << " is " << area << "." << endl; cout << "Area of a quarter Arch from PI of radius " << radius << " is " << (PI * pow(radius,2))/4 << "." << endl; cout << "Approximate Circle is " << area * 4 << "." << endl; cout << "PI circle is " << (PI * pow(radius,2)) << "." << endl; return 0; }
static void GetCoefficients(double *a1, double *a2, double *b1, double *b2, double *c1, double *c2){ printf("Enter first equation\n"); printf("A1 : "); *a1 = GetReal(); printf("B1 : "); *b1 = GetReal(); printf("C1 : "); *c1 = GetReal(); printf("\nEnter second equation\n"); printf("A2 : "); *a2 = GetReal(); printf("B2 : "); *b2 = GetReal(); printf("C2 : "); *c2 = GetReal(); }
bool GetValue(size_t row, double& value, bool force = false) const { return GetReal(row, value, force); }
int main (int argc, char *argv[]) { #include "tsil_names.h" TSIL_REAL x, y, z, u, v, s, qq; TSIL_COMPLEX val; TSIL_DATA result; int i, j, k, p, foo, tally[3], nwarn, nfail, npass; char c; TSIL_COMPLEX Mvalue, Uvalue[4], Vvalue[4], Svalue[2], Tvalue[6], Bvalue[2]; TSIL_COMPLEX Tbarvalue[6], UUvalue[4][3], VVvalue[4][3], SSvalue[2][3]; TSIL_COMPLEX TTvalue[6][3]; TSIL_REAL xx, yy, zz, uu, vv; /* gcc complains unless the following are initialized; this may be a gcc bug? Fortunately, it doesn't hurt to initialize them. */ int permU = 0; int permS = 0; int permT11 = 0; int permT12 = 0; int permT21 = 0; int permT22 = 0; int permT31 = 0; int permT32 = 0; if (argc == 1) TSIL_Error ("main", "Must supply test data filename(s)...", 2); nwarn = nfail = npass = 0; printf("===== TSIL TEST SUITE =====\n"); #if defined (TSIL_TEST_STU) printf("** Testing STU Evaluation only!\n"); #elif defined (TSIL_TEST_ST) printf("** Testing ST Evaluation only!\n"); #endif /* We don't need no stinkin' TSIL_Warnings here. */ fclose (stderr); /* Loop over input files */ for (i = 1; i < argc; i++) { if ((fp = fopen(argv[i], "r")) == NULL) { TSIL_Warn ("Test program", "Invalid file name"); continue; } printf ("\nTest %d: ", i); printf ("%s\n", argv[i]); fflush (stdout); /* Skip any lines starting with '(' (comments): */ while ((c = fgetc (fp)) == '(') SkipLine (fp); /* Put back the last character after we find a non-comment line */ ungetc ((int) c, fp); /* Read in parameters */ xx = x = GetReal (); yy = y = GetReal (); zz = z = GetReal (); uu = u = GetReal (); vv = v = GetReal (); s = GetReal (); qq = GetReal (); /* Calculate everything... */ #if defined(TSIL_TEST_STU) TSIL_SetParametersSTU (&result, x, z, u, v, qq); #elif defined(TSIL_TEST_ST) TSIL_SetParametersST (&result, x, u, v, qq); #else TSIL_SetParameters (&result, x, y, z, u, v, qq); #endif TSIL_Evaluate (&result, s); for (j = 0; j < 3; j++) tally[j] = 0; /* ...and test results: */ #if defined(TSIL_TEST_STU) val = GetComplex (); val = GetComplex (); val = GetComplex (); /* U */ for (j = 2; j < 4; j+=2) { val = GetComplex (); Uvalue[j] = result.U[j].value; TSIL_Compare (uname[j], val, Uvalue[j], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } CheckConsistent (Uvalue[2], TSIL_GetFunction(&result,"Uxzuv")); val = GetComplex (); val = GetComplex (); /* T */ for (j = 1; j < 6; j+=2) { val = GetComplex (); Tvalue[j] = result.T[j].value; TSIL_Compare (tname[j], val, Tvalue[j], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; val = GetComplex (); } CheckConsistent (Tvalue[1], TSIL_GetFunction(&result,"Tuxv")); CheckConsistent (Tvalue[3], TSIL_GetFunction(&result,"Txuv")); CheckConsistent (Tvalue[5], TSIL_GetFunction(&result,"Tvxu")); /* S */ for (j = 1; j < 2; j+=2) { val = GetComplex (); Svalue[j] = result.S[j].value; TSIL_Compare (sname[j], val, Svalue[j], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } CheckConsistent (Svalue[1], TSIL_GetFunction(&result,"Suxv")); /* B */ for (j = 0; j < 2; j+=2) { val = GetComplex (); Bvalue[j] = result.B[j].value; TSIL_Compare (bname[j], val, Bvalue[j], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } CheckConsistent (Bvalue[0], TSIL_GetFunction(&result,"Bxz")); val = GetComplex (); val = GetComplex (); val = GetComplex (); /* V */ for (j = 2; j < 4; j+=2) { val = GetComplex (); Vvalue[j] = result.V[j].value; TSIL_Compare (vname[j], val, Vvalue[j], TSIL_PASS_V, TSIL_WARN_V, &foo); tally[foo]++; } CheckConsistent (Vvalue[2], TSIL_GetFunction(&result,"Vxzuv")); val = GetComplex (); /* Tbar */ val = GetComplex (); for (j = 1; j < 6; j+=2) { val = GetComplex (); Tbarvalue[j] = result.Tbar[j].value; TSIL_Compare (tbarname[j], val, Tbarvalue[j], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; val = GetComplex (); } val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); /* UU */ for (j = 2; j < 4; j+=2) { for (k = 0; k < 3; k++) { val = GetComplex (); UUvalue[j][k] = result.U[j].bold[k]; TSIL_Compare (uuname[j][k], val, UUvalue[j][k], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } } val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); /* VV */ for (j = 2; j < 4; j+=2) { for (k = 0; k < 3; k++) { val = GetComplex (); VVvalue[j][k] = result.V[j].bold[k]; TSIL_Compare (vvname[j][k], val, VVvalue[j][k], TSIL_PASS_V, TSIL_WARN_V, &foo); tally[foo]++; } } val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); /* TT */ for (j = 1; j < 6; j+=2) { for (k = 0; k < 3; k++) { val = GetComplex (); TTvalue[j][k] = result.T[j].bold[k]; TSIL_Compare (ttname[j][k], val, TTvalue[j][k], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } val = GetComplex (); val = GetComplex (); val = GetComplex (); } /* SS */ for (j = 1; j < 2; j+=2) { for (k = 0; k < 3; k++) { val = GetComplex (); SSvalue[j][k] = result.S[j].bold[k]; TSIL_Compare (ssname[j][k], val, SSvalue[j][k], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } } #elif defined(TSIL_TEST_ST) val = GetComplex (); val = GetComplex (); val = GetComplex (); /* U */ for (j = 2; j < 4; j+=2) { val = GetComplex (); } val = GetComplex (); val = GetComplex (); /* T */ for (j = 1; j < 6; j+=2) { val = GetComplex (); Tvalue[j] = result.T[j].value; TSIL_Compare (tname[j], val, Tvalue[j], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; val = GetComplex (); } CheckConsistent (Tvalue[1], TSIL_GetFunction(&result,"Tuxv")); CheckConsistent (Tvalue[3], TSIL_GetFunction(&result,"Txuv")); CheckConsistent (Tvalue[5], TSIL_GetFunction(&result,"Tvxu")); /* S */ for (j = 1; j < 2; j+=2) { val = GetComplex (); Svalue[j] = result.S[j].value; TSIL_Compare (sname[j], val, Svalue[j], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } CheckConsistent (Svalue[1], TSIL_GetFunction(&result,"Suxv")); /* B */ for (j = 0; j < 2; j+=2) { val = GetComplex (); } val = GetComplex (); val = GetComplex (); val = GetComplex (); /* V */ for (j = 2; j < 4; j+=2) { val = GetComplex (); } val = GetComplex (); /* Tbar */ val = GetComplex (); for (j = 1; j < 6; j+=2) { val = GetComplex (); Tbarvalue[j] = result.Tbar[j].value; TSIL_Compare (tbarname[j], val, Tbarvalue[j], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; val = GetComplex (); } val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); /* UU */ for (j = 2; j < 4; j+=2) { for (k = 0; k < 3; k++) { val = GetComplex (); } } val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); /* VV */ for (j = 2; j < 4; j+=2) { for (k = 0; k < 3; k++) { val = GetComplex (); } } val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); /* TT */ for (j = 1; j < 6; j+=2) { for (k = 0; k < 3; k++) { val = GetComplex (); TTvalue[j][k] = result.T[j].bold[k]; TSIL_Compare (ttname[j][k], val, TTvalue[j][k], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } val = GetComplex (); val = GetComplex (); val = GetComplex (); } /* SS */ for (j = 1; j < 2; j+=2) { for (k = 0; k < 3; k++) { val = GetComplex (); SSvalue[j][k] = result.S[j].bold[k]; TSIL_Compare (ssname[j][k], val, SSvalue[j][k], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } } #else /* M */ val = GetComplex (); Mvalue = result.M.value; CheckConsistent (Mvalue, TSIL_GetFunction(&result,"M")); TSIL_Compare ("M", val, Mvalue, TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; /* U */ for (j = 0; j < 4; j++) { val = GetComplex (); Uvalue[j] = result.U[j].value; TSIL_Compare (uname[j], val, Uvalue[j], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } CheckConsistent (Uvalue[0], TSIL_GetFunction(&result,"Uzxyv")); CheckConsistent (Uvalue[1], TSIL_GetFunction(&result,"Uuyxv")); CheckConsistent (Uvalue[2], TSIL_GetFunction(&result,"Uxzuv")); CheckConsistent (Uvalue[3], TSIL_GetFunction(&result,"Uyuzv")); /* T */ for (j = 0; j < 6; j++) { val = GetComplex (); Tvalue[j] = result.T[j].value; TSIL_Compare (tname[j], val, Tvalue[j], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } CheckConsistent (Tvalue[0], TSIL_GetFunction(&result,"Tvyz")); CheckConsistent (Tvalue[1], TSIL_GetFunction(&result,"Tuxv")); CheckConsistent (Tvalue[2], TSIL_GetFunction(&result,"Tyzv")); CheckConsistent (Tvalue[3], TSIL_GetFunction(&result,"Txuv")); CheckConsistent (Tvalue[4], TSIL_GetFunction(&result,"Tzyv")); CheckConsistent (Tvalue[5], TSIL_GetFunction(&result,"Tvxu")); /* S */ for (j = 0; j < 2; j++) { val = GetComplex (); Svalue[j] = result.S[j].value; TSIL_Compare (sname[j], val, Svalue[j], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } CheckConsistent (Svalue[0], TSIL_GetFunction(&result,"Svyz")); CheckConsistent (Svalue[1], TSIL_GetFunction(&result,"Suxv")); /* B */ for (j = 0; j < 2; j++) { val = GetComplex (); Bvalue[j] = result.B[j].value; TSIL_Compare (bname[j], val, Bvalue[j], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } CheckConsistent (Bvalue[0], TSIL_GetFunction(&result,"Bxz")); CheckConsistent (Bvalue[1], TSIL_GetFunction(&result,"Byu")); /* V */ for (j = 0; j < 4; j++) { val = GetComplex (); Vvalue[j] = result.V[j].value; TSIL_Compare (vname[j], val, Vvalue[j], TSIL_PASS_V, TSIL_WARN_V, &foo); tally[foo]++; } CheckConsistent (Vvalue[0], TSIL_GetFunction(&result,"Vzxyv")); CheckConsistent (Vvalue[1], TSIL_GetFunction(&result,"Vuyxv")); CheckConsistent (Vvalue[2], TSIL_GetFunction(&result,"Vxzuv")); CheckConsistent (Vvalue[3], TSIL_GetFunction(&result,"Vyuzv")); /* Tbar */ for (j = 0; j < 6; j++) { val = GetComplex (); Tbarvalue[j] = result.Tbar[j].value; TSIL_Compare (tbarname[j], val, Tbarvalue[j], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } /* UU */ for (j = 0; j < 4; j++) { for (k = 0; k < 3; k++) { val = GetComplex (); UUvalue[j][k] = result.U[j].bold[k]; TSIL_Compare (uuname[j][k], val, UUvalue[j][k], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } } /* VV */ for (j = 0; j < 4; j++) { for (k = 0; k < 3; k++) { val = GetComplex (); VVvalue[j][k] = result.V[j].bold[k]; TSIL_Compare (vvname[j][k], val, VVvalue[j][k], TSIL_PASS_V, TSIL_WARN_V, &foo); tally[foo]++; } } /* TT */ for (j = 0; j < 6; j++) { for (k = 0; k < 3; k++) { val = GetComplex (); TTvalue[j][k] = result.T[j].bold[k]; TSIL_Compare (ttname[j][k], val, TTvalue[j][k], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } } /* SS */ for (j = 0; j < 2; j++) { for (k = 0; k < 3; k++) { val = GetComplex (); SSvalue[j][k] = result.S[j].bold[k]; TSIL_Compare (ssname[j][k], val, SSvalue[j][k], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } } #endif if (tally[FAIL] > 0) { nfail++; printf ("FAILED FOR INPUT PARAMETERS:\n"); printf ("x = %.6lf;\n", (double) x); printf ("y = %.6lf;\n", (double) y); printf ("z = %.6lf;\n", (double) z); printf ("u = %.6lf;\n", (double) u); printf ("v = %.6lf;\n", (double) v); printf ("s = %.6lf;\n", (double) s); printf ("qq = %.6lf;\n", (double) qq); } else if (tally[WARN] > 0) { printf ("PASS WITH WARNING\n"); nwarn++; } else { printf ("PASS\n"); npass++; } if (1 == Doperms) { for (p = 0; p < 4; p++) { for (j = 0; j < 3; j++) tally[j] = 0; x = xx; y = yy; z = zz; u = uu; v = vv; if (1 == p) { swapR (&x, &y); swapR (&z, &u); } if (2 == p) { swapR (&x, &z); swapR (&y, &u); } if (3 == p) { swapR (&x, &u); swapR (&y, &z); } /* Calculate everything... */ TSIL_SetParameters (&result, x, y, z, u, v, qq); TSIL_Evaluate (&result, s); Permuteresults (&result, p); printf ("\nTest %d, permutation %d (", i, p); printf ("%s", argv[i]); printf ("): "); /* ...and check that permuted results agree as they should: */ /* M */ val = result.M.value; TSIL_Compare ("M", val, Mvalue, TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; /* U */ for (j = 0; j < 4; j++) { val = result.U[j].value; TSIL_Compare (uname[j], val, Uvalue[j], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } /* T */ for (j = 0; j < 6; j++) { val = result.T[j].value; TSIL_Compare (tname[j], val, Tvalue[j], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } /* S */ for (j = 0; j < 2; j++) { val = result.S[j].value; TSIL_Compare (sname[j], val, Svalue[j], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } /* B */ for (j = 0; j < 2; j++) { val = result.B[j].value; TSIL_Compare (bname[j], val, Bvalue[j], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } /* V */ for (j = 0; j < 4; j++) { val = result.V[j].value; TSIL_Compare (vname[j], val, Vvalue[j], TSIL_PASS_V, TSIL_WARN_V, &foo); tally[foo]++; } /* Tbar */ for (j = 0; j < 6; j++) { val = result.Tbar[j].value; TSIL_Compare (tbarname[j], val, Tbarvalue[j], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } /* UU */ for (j = 0; j < 4; j++) { for (k = 0; k < 3; k++) { val = result.U[j].bold[k]; TSIL_Compare (uuname[j][k], val, UUvalue[j][k], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } } /* VV */ for (j = 0; j < 4; j++) { for (k = 0; k < 3; k++) { val = result.V[j].bold[k]; TSIL_Compare (vvname[j][k], val, VVvalue[j][k], TSIL_PASS_V, TSIL_WARN_V, &foo); tally[foo]++; } } /* TT */ for (j = 0; j < 6; j++) { for (k = 0; k < 3; k++) { val = result.T[j].bold[k]; TSIL_Compare (ttname[j][k], val, TTvalue[j][k], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } } /* SS */ for (j = 0; j < 2; j++) { for (k = 0; k < 3; k++) { val = result.S[j].bold[k]; TSIL_Compare (ssname[j][k], val, SSvalue[j][k], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } } if (tally[FAIL] > 0) { nfail++; printf ("\nFAILED FOR INPUT PARAMETERS:\n"); printf ("x = %.3lf;\n", (double) x); printf ("y = %.3lf;\n", (double) y); printf ("z = %.3lf;\n", (double) z); printf ("u = %.3lf;\n", (double) u); printf ("v = %.3lf;\n", (double) v); printf ("s = %.3lf;\n", (double) s); printf ("qq = %.3lf;\n", (double) qq); } else if (tally[WARN] > 0) { nwarn++; printf ("\nPASS WITH WARNING\n"); } else { printf ("\nPASS\n"); npass++; } } } if (1 == Doextraperms) { for (p = 4; p < 8; p++) { x = xx; y = yy; z = zz; u = uu; v = vv; if (p == 4) { swapR (&x, &v); permU = 1; permT11 = 1; permT12 = 1; permT21 = 3; permT22 = 5; permT31 = 5; permT32 = 3; permS = 1; } if (p == 5) { swapR (&y, &v); permU = 0; permT11 = 0; permT12 = 2; permT21 = 2; permT22 = 0; permT31 = 4; permT32 = 4; permS = 0; } if (p == 6) { swapR (&z, &v); permU = 3; permT11 = 0; permT12 = 4; permT21 = 4; permT22 = 0; permT31 = 2; permT32 = 2; permS = 0; } if (p == 7) { swapR (&u, &v); permU = 2; permT11 = 1; permT12 = 5; permT21 = 5; permT22 = 1; permT31 = 3; permT32 = 3; permS = 1; } for (j = 0; j < 3; j++) tally[j] = 0; /* Calculate everything... */ TSIL_SetParameters (&result, x, y, z, u, v, qq); TSIL_Evaluate (&result, s); printf ("\nTest %d, permutation %d (", i, p); printf ("%s", argv[i]); printf ("): "); /* ...and check results: */ /* U */ for (j = 0; j < 4; j++) { val = Uvalue[j]; if (j == permU) { TSIL_Compare (uname[j], val, result.U[j].value, TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } } /* T */ for (j = 0; j < 6; j++) { val = Tvalue[j]; if (j == permT11) { TSIL_Compare (tname[j], val, result.T[permT12].value, TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } if (j == permT21) { TSIL_Compare (tname[j], val, result.T[permT22].value, TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } if (j == permT31) { TSIL_Compare (tname[j], val, result.T[permT32].value, TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } } /* S */ for (j = 0; j < 2; j++) { val = Svalue[j]; if (j == permS) { TSIL_Compare (sname[j], val, result.S[j].value, TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } } /* V */ for (j = 0; j < 4; j++) { val = Vvalue[j]; if (j == permU) { TSIL_Compare (vname[j], val, result.V[j].value, TSIL_PASS_V, TSIL_WARN_V, &foo); tally[foo]++; } } /* Tbar */ for (j = 0; j < 6; j++) { val = Tbarvalue[j]; if (j == permT11) { TSIL_Compare (tbarname[j], val, result.Tbar[permT12].value, TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } if (j == permT21) { TSIL_Compare (tbarname[j], val, result.Tbar[permT22].value, TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } if (j == permT31) { TSIL_Compare (tbarname[j], val, result.Tbar[permT32].value, TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } } /* UU */ for (j = 0; j < 4; j++) { for (k = 0; k < 3; k++) { val = UUvalue[j][k]; if (j == permU) { TSIL_Compare (uuname[j][k], val, result.U[j].bold[k], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } } } /* VV */ for (j = 0; j < 4; j++) { for (k = 0; k < 3; k++) { val = VVvalue[j][k]; if (j == permU) { TSIL_Compare (vvname[j][k], val, result.V[j].bold[k], TSIL_PASS_V, TSIL_WARN_V, &foo); tally[foo]++; } } } /* TT */ for (j = 0; j < 6; j++) { for (k = 0; k < 3; k++) { val = TTvalue[j][k]; if (j == permT11) { TSIL_Compare (ttname[j][k], val, result.T[permT12].bold[k], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } if (j == permT21) { TSIL_Compare (ttname[j][k], val, result.T[permT22].bold[k], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } if (j == permT31) { TSIL_Compare (ttname[j][k], val, result.T[permT32].bold[k], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } } } /* SS */ for (j = 0; j < 2; j++) { for (k = 0; k < 3; k++) { val = SSvalue[j][k]; if (j == permS) { TSIL_Compare (ssname[j][k], val, result.S[j].bold[k], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } } } if (tally[FAIL] > 0) { nfail++; printf ("\nFAILED FOR INPUT PARAMETERS:\n"); printf ("x = %.16lf;\n", (double) x); printf ("y = %.16lf;\n", (double) y); printf ("z = %.16lf;\n", (double) z); printf ("u = %.16lf;\n", (double) u); printf ("v = %.16lf;\n", (double) v); printf ("s = %.16lf;\n", (double) s); printf ("qq = %.16lf;\n", (double) qq); } else if (tally[WARN] > 0) { nwarn++; printf ("\nPASS\n"); } else { printf ("\nPASS\n"); npass++; } } } fclose (fp); printf ("\n===== Done with input file "); printf ("%s", argv[i]); printf (" =====\n"); } printf ("\n== FINAL RESULTS ==\n"); printf ("Total input files: %d\n", (argc - 1)); printf ("Total tests performed: %d\n", (1 + Doperms * 3 + Doextraperms * 4) * (argc - 1)); printf ("Pass: %d\n", npass); printf ("Warn: %d\n", nwarn); printf ("Fail: %d\n", nfail); return 0; }
//------------------------------------------------------------------------------ const wxString& Variable::GetGeneratingString(Gmat::WriteMode mode, const wxString &prefix, const wxString &useName) { #ifdef DEBUG_GEN_STRING MessageInterface::ShowMessage (wxT("Variable::GetGeneratingString() this=<%p>'%s', mode=%d, prefix='%s', ") wxT("useName='%s'\n mExpr='%s', mRealValue=%f, mIsNumber=%d, mValueSet=%d\n"), this, GetName().c_str(), mode, prefix.c_str(), useName.c_str(), mExpr.c_str(), mRealValue, mIsNumber, mValueSet); #endif bool generateStr = false; if (mode == Gmat::SHOW_SCRIPT) { #ifdef DEBUG_GEN_STRING MessageInterface::ShowMessage(wxT(" mode is SHOW_SCRIPT, so generating string\n")); #endif generateStr = true; } else { if (mIsNumber) { Real rval = GetReal(); // Write value if it is set from user or non-zero if (mValueSet || rval != 0.0) { #ifdef DEBUG_GEN_STRING MessageInterface::ShowMessage (wxT(" '%s' is a non-zero number or set by user, so generating string\n"), mExpr.c_str()); #endif generateStr = true; } } else { #ifdef DEBUG_GEN_STRING MessageInterface::ShowMessage (wxT(" '%s' is not a number, so generating string\n"), mExpr.c_str()); #endif generateStr = true; } } if (generateStr) { //generatingString = wxT("GMAT ") + GetName() + wxT(" = ") + mExpr + wxT(";"); //generatingString = wxT("GMAT ") + GetName() + wxT(" = ") + mInitialValue + wxT(";"); generatingString = wxT("GMAT ") + GetName() + wxT(" = ") + GmatStringUtil::ToString(mRealValue, 16, false, 1) + wxT(";"); generatingString = generatingString + inlineComment + wxT("\n"); } #ifdef DEBUG_GEN_STRING MessageInterface::ShowMessage (wxT("Variable::GetGeneratingString() returning\n<%s>\n"), generatingString.c_str()); #endif return generatingString; }
int main() { bool endSim = false; Randomize(); while (true) { double invalidElectResult = 0; int voters; double spread; double votingError; int trialRuns; Vector<int> elections; while (true) { cout << "Enter number of voters (or 0 to end simulation): "; voters = GetInteger(); if (voters == 0) { endSim = true; break; } else if (voters < 0) cout << "Enter a positive integer." << endl; else break; } if (endSim) break; while (true) { cout << "Enter percentage spread between candidates (0 - 1.0): "; spread = GetReal(); if (spread >=0 && spread <= 1.0) break; else cout << "Spread must be between 0 and 1.0" << endl; } while (true) { cout << "Enter voting error percentage: (0 - 1.0): "; votingError = GetReal(); if (votingError >=0 && votingError <= 1.0) break; else cout << "Voting error must be between 0 and 1.0" << endl; } while (true) { cout << "Enter number of times to run the trial: "; trialRuns = GetInteger(); if (trialRuns >= 1) break; else cout << "Enter a positive integer" << endl; } for (int i = 0; i < trialRuns; i++) { invalidElectResult = RunElectionTrial(voters, spread, votingError); cout << "Trial " << i + 1 << ": "; cout << "Chance of an invalid election result after 500 trials = " << invalidElectResult << "%" << endl; elections.add(invalidElectResult); } scoreStatsT scores = calculateStatistics(elections); cout << "Scores: MIN = " << scores.min << endl; cout << "Scores: MAX = " << scores.max << endl; cout << "Scores: AVG = " << scores.avg << endl; cout << "Scores: NUM = " << scores.num << endl; cout << "********************************************************" << endl << endl; } return 0; }
PyRep *EVEAttributeMgr::PyGet(Attr attr) const { return _PyGet(GetReal(attr)); }