Diploma Thesis Percolation Simulation
C++ Sourcecode Documentation

www.AndreasKrueger.de/thesis/code

Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

measure.h

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////// 
00002 // measure.h    (v0.98 - 27.9.2001)                          //
00003 //                                                            //
00004 // "average +/- standarddeviation" ('errorbar numbers')       //
00005 // class for fuzzy mathematics with real measurements in c++  //
00006 // just define the errors, this class does the propagation    //
00007 // by predefined derivatives of most standard ops & fns           //
00008 //                                                            //
00009 // (Copyright) 8.12.2000 Andreas Krueger (cpp__at__AndreasKrueger__dot__de)   //
00010 //                                                           //
00011 // very easy to use:                                        //
00012 //   typedef measure<double> measure;                      //
00013 //   measure a=measure(42,2.7);                           //
00014 //   measure b=measure(21,1.4);                          //
00015 //   cout << a/b;                                       //
00016 // the result is: 2±0.185225                            //
00017 // the question was (42±2.7) / (21±1.4) = ?             //
00018 //                                                       //
00019 ////////////////////////////////////////////////////////////
00020 //                                                        //
00021 // most everyday-life functions are implemented:         //
00022 // +, -, *, /, pow, sqrt, exp, log, log10, fabs,         //
00023 // sin, cos, tan, asin, acos, atan,                     //
00024 // << and >> for cout and cin                           //
00025 //                                                      //
00026 // special:                                              //
00027 // bool overlap(a,b): "are two errorbars overlapping?"    // 
00028 //                                                         //
00029 //////////////////////////////////////////////////////////////
00030 //                                                           //           
00031 ///////////////////////////////////////////////////////////////
00032 // legal stuff:                                              //
00033 // Copyright 2000,2001 Andreas Krueger(cpp__at__AndreasKrueger__dot__de)//
00034 //                                                           //
00035 // SHAREWARE:                                                //
00036 // a) Use it freely! But always mention my name & eMail!     //
00037 // b) If you change it, I need a copy. Please mail it to me! //
00038 // c) Use it on your own risk! This is version 0.97          //
00039 // d) If for commercial purposes, I get 10% of your profits  //
00040 // e) Don't remove this legal&adresses - part!               //
00041 ///////////////////////////////////////////////////////////////
00042 // addresses:                                                //
00043 //  support-mailinglist   ClassMeasure@eGroups.de            //
00044 //  ->  subscribe list    ClassMeasure-subscribe@eGroups.de  //
00045 //  ->  mailinglist-home  www.egroups.com/group/classmeasure //
00046 //  contact author        cpp__at__AndreasKrueger__dot__de                          //
00047 //  www home              www.AndreasKrueger.de/cpp/measure  //
00048 ///////////////////////////////////////////////////////////////
00049 // N.B.:                                                     //
00050 // The errors will always _increase_ with each operation     //
00051 // e.g. a = ((a+b)/c) * c - b = a                            //
00052 // but the error is much bigger then                         //
00053 //                                                           //
00054 // So try to find the "shortest" way of calculation          //
00055 ///////////////////////////////////////////////////////////////
00056 // history                                                   //
00057 // v0.98: #include <math.h>; #include <iostream>             //
00058 // v0.97: removed STL-bug                                    //
00059 //        by "operator@@<T>" -> "operator@@<>"               //
00060 // v0.95: ported to unix (g++)                               //
00061 //        (answer_)random_errors_set                                             //
00062 // v0.92: works well in Visual-C++                           //
00063 ///////////////////////////////////////////////////////////////
00064 
00065 #ifndef LOADED_MEASURE
00066 #define LOADED_MEASURE
00067 #endif
00068 
00069 // your +/- sign (in octal):
00070 #ifdef _WIN32
00071 #define ASCII_PLUSMINUS "\361"
00072 #else
00073 #define ASCII_PLUSMINUS "\261"
00074 #endif
00075 
00076 #define RANDOM_ERRORS
00077 // turn this switch off, 
00078 // only if the numbers DO NOT have _independent_ random errors
00079 // then the sums in binary-operators & functions would be "sum fabs()" 
00080 // otherwise all sums will be "sqrt(sum squares)" (DEFAULT)
00081 // (irrelevant for unary operators & functions)
00082 
00083 #include <math.h>
00084 #include <iostream>
00085 using std::ostream;
00086 using std::istream;
00087 using std::cout;
00088 using std::cin;
00089 using std::endl;
00090 using std::flush;
00091 
00092 template<class T> class measure;
00093 // template<class T> T av(void);     // predefine them here is not possible using Digital-cxx
00094 // template<class T> T sdev(void);
00095 template<class T> void set_av(const T& av);
00096 template<class T> void set_sdev(const T& sdev);
00097 template<class T> ostream& operator<<(ostream& os, const measure<T>& rhs);
00098 template<class T> istream& operator>>(istream& is, measure<T>& rhs);
00099 template<class T> measure<T>& operator+=(measure<T>& lhs, const measure<T>& rhs);
00100 template<class T> measure<T>& operator-=(measure<T>& lhs, const measure<T>& rhs);
00101 template<class T> measure<T>& operator*=(measure<T>& lhs, const measure<T>& rhs);
00102 template<class T> measure<T>& operator/=(measure<T>& lhs, const measure<T>& rhs);
00103 template<class T> measure<T> pow(const measure<T>& lhs, const measure<T>& rhs);
00104 template<class T> measure<T> log(const measure<T>& arg);
00105 template<class T> measure<T> log10(const measure<T>& arg);
00106 template<class T> measure<T> fabs(const measure<T>& arg);
00107 template<class T> measure<T> sin(const measure<T>& arg);
00108 template<class T> measure<T> cos(const measure<T>& arg);
00109 template<class T> measure<T> tan(const measure<T>& arg);
00110 template<class T> measure<T> asin(const measure<T>& arg);
00111 template<class T> measure<T> acos(const measure<T>& arg);
00112 template<class T> measure<T> atan(const measure<T>& arg);
00113 template<class T> measure<T> exp(const measure<T>& arg);
00114 template<class T> measure<T> sqrt (const measure<T>& arg);
00115 template<class T> bool overlap(const measure<T>& lhs, const measure<T>& rhs);
00116 
00117 template<class T> measure<T>& operator+=(measure<T>& lhs, const T& rhs);
00118 template<class T> measure<T> operator+(const measure<T>& lhs, const measure<T>& rhs);
00119 template<class T> measure<T> operator+(const measure<T>& lhs, const T& rhs);
00120 template<class T> measure<T> operator+(const T& lhs, const measure<T>& rhs);
00121 template<class T> measure<T>& operator-=(measure<T>& lhs, const T& rhs);
00122 template<class T> measure<T> operator-(const measure<T>& lhs, const measure<T>& rhs);
00123 template<class T> measure<T> operator-(const measure<T>& lhs, const T& rhs);
00124 template<class T> measure<T> operator-(const T& lhs, const measure<T>& rhs);
00125 template<class T> measure<T>& operator*=(measure<T>& lhs, const T& rhs);
00126 template<class T> measure<T> operator*(const measure<T>& lhs, const measure<T>& rhs);
00127 template<class T> measure<T> operator*(const measure<T>& lhs, const T& rhs);
00128 template<class T> measure<T> operator*(const T& lhs, const measure<T>& rhs);
00129 template<class T> measure<T>& operator/=(measure<T>& lhs, const T& rhs);
00130 template<class T> measure<T> operator/(const measure<T>& lhs, const measure<T>& rhs);
00131 template<class T> measure<T> operator/(const measure<T>& lhs, const T& rhs);
00132 template<class T> measure<T> operator/(const T& lhs, const measure<T>& rhs);
00133 template<class T> measure<T> operator-(const measure<T>& rhs);
00134 template<class T> measure<T> operator+(const measure<T>& rhs);
00135 template<class T> measure<T> pow(const T& lhs , const measure<T>& rhs);
00136 template<class T> measure<T> pow(const measure<T>& lhs, const T& rhs);
00137 template<class T> measure<T> pow(const measure<T>& lhs, const int& rhs);
00138 template<class T> measure<T> pow(const int& lhs, const measure<T>& rhs);
00139 template<class T> bool overlap(const measure<T>& lhs, const T& rhs);
00140 template<class T> bool overlap(const T& lhs, const measure<T>& rhs);
00141 bool random_errors_set();
00142 const char* answer_random_errors_set();
00143 
00144 // for binary ops: add squares or add fabs
00145 // depending on if RANDOM_ERRORS
00146 template<class T> 
00147 T square_add(T lhs, T rhs){     return sqrt( pow(lhs,2) + pow(rhs,2) );}
00148 template<class T> 
00149 T fabs_add(T lhs, T rhs){return fabs(lhs) + fabs(rhs);}
00150 template<class T> T sum2(T lhs, T rhs){
00151 #ifdef RANDOM_ERRORS    
00152         return square_add<T>(lhs, rhs);
00153 #else                   
00154         return fabs_add<T>(lhs, rhs);
00155 #endif
00156 }
00157 
00158 // the class body
00159 template<class T> class measure {
00160         T value, stddev;
00161 public:
00162         measure (const T& av=(T)0, const T& sdev=(T)0) 
00163                          : value(av), stddev(::fabs(sdev))
00164                         {};
00165     T   av(void) {return value;};
00166     T sdev(void) {return stddev;};
00167         void set_av(const T& av)     {value=av;};
00168         void set_sdev(const T& sdev) {stddev=::fabs(sdev);};
00169     measure& operator+=(const measure& rhs);
00170     measure& operator+=(const T& rhs);
00171     measure& operator-=(const measure& rhs);
00172     measure& operator-=(const T& rhs);
00173     measure& operator*=(const measure& rhs);
00174     measure& operator*=(const T& rhs);
00175     measure& operator/=(const measure& rhs);
00176     measure& operator/=(const T& rhs);
00177         measure& operator++(int dummy) {value++;return *this;};
00178         measure& operator--(int dummy) {value--;return *this;};
00179 
00180 #ifdef _MSC_VER
00181     friend measure operator-(const measure& rhs);
00182         friend measure operator+(const measure& rhs);
00183         friend measure operator+(const measure& lhs, const measure& rhs);
00184         friend measure operator+(const measure& lhs, const T& rhs);
00185     friend measure operator+(const T& lhs,          const measure& rhs);
00186         friend measure operator-(const measure& lhs, const measure& rhs);
00187     friend measure operator-(const measure& lhs, const T& rhs);
00188     friend measure operator-(const T& lhs,          const measure& rhs);
00189     friend measure operator*(const measure& lhs, const measure& rhs);
00190     friend measure operator*(const measure& lhs, const T& rhs);
00191     friend measure operator*(const T& lhs,          const measure& rhs);
00192     friend measure operator/(const measure& lhs, const measure& rhs);
00193     friend measure operator/(const measure& lhs, const T& rhs);
00194     friend measure operator/(const T& lhs,          const measure& rhs);
00195     friend bool overlap(const measure& lhs, const measure& rhs);
00196     friend bool overlap(const measure& lhs, const T& rhs);
00197     friend bool overlap(const T& lhs,          const measure& rhs);
00198         friend ostream& operator<<(ostream& os, const measure& i);
00199         friend istream& operator>>(istream& is, measure& i);
00200         friend measure pow(const measure& lhs, const measure& rhs);
00201         friend measure pow(const measure& lhs, const T& rhs);
00202         friend measure pow(const measure& lhs, const int& rhs);
00203         friend measure pow(const T& lhs,   const measure& rhs);
00204         friend measure pow(const int& lhs, const measure& rhs);
00205         friend measure log(const measure& arg);
00206         friend measure log10(const measure& arg);
00207         friend measure fabs(const measure& arg);
00208         friend measure exp(const measure& arg);
00209         friend measure sqrt(const measure& arg);
00210         friend measure sin(const measure& arg);
00211         friend measure cos(const measure& arg);
00212         friend measure tan(const measure& arg);
00213         friend measure asin(const measure& arg);
00214         friend measure acos(const measure& arg);
00215         friend measure atan(const measure& arg);
00216 #else 
00217         friend measure operator-<>(const measure& rhs);
00218         friend measure operator+<>(const measure& rhs);
00219         friend measure operator+<>(const measure& lhs, const measure& rhs);
00220         friend measure operator+<>(const measure& lhs, const T& rhs);
00221     friend measure operator+<>(const T& lhs,          const measure& rhs);
00222         friend measure operator-<>(const measure& lhs, const measure& rhs);
00223     friend measure operator-<>(const measure& lhs, const T& rhs);
00224     friend measure operator-<>(const T& lhs,          const measure& rhs);
00225     friend measure operator*<>(const measure& lhs, const measure& rhs);
00226     friend measure operator*<>(const measure& lhs, const T& rhs);
00227     friend measure operator*<>(const T& lhs,          const measure& rhs);
00228     friend measure operator/<>(const measure& lhs, const measure& rhs);
00229     friend measure operator/<>(const measure& lhs, const T& rhs);
00230     friend measure operator/<>(const T& lhs,          const measure& rhs);
00231     friend bool overlap<>(const measure& lhs, const measure& rhs);
00232     friend bool overlap<>(const measure& lhs, const T& rhs);
00233     friend bool overlap<>(const T& lhs,          const measure& rhs);
00234         friend ostream& operator<<<>(ostream& os, const measure& i);
00235         friend istream& operator>><>(istream& is, measure& i);
00236         friend measure pow<>(const measure& lhs, const measure& rhs);
00237         friend measure pow<>(const measure& lhs, const T& rhs);
00238         friend measure pow<>(const measure& lhs, const int& rhs);
00239         friend measure pow<>(const T& lhs,   const measure& rhs);
00240         friend measure pow<>(const int& lhs, const measure& rhs);
00241         friend measure log<>(const measure& arg);
00242         friend measure log10<>(const measure& arg);
00243         friend measure fabs<>(const measure& arg);
00244         friend measure exp<>(const measure& arg);
00245         friend measure sqrt<>(const measure& arg);
00246         friend measure sin<>(const measure& arg);
00247         friend measure cos<>(const measure& arg);
00248         friend measure tan<>(const measure& arg);
00249         friend measure asin<>(const measure& arg);
00250         friend measure acos<>(const measure& arg);
00251         friend measure atan<>(const measure& arg);
00252 #endif
00253         
00254         // TODO:
00255         // operator% for modulo - but how?
00256         // better operator>> for keyboard input of "v +/- s"
00257         // remove the "friend" whereever possible (?)
00258         // operator?? for overlap( , )
00259         // cast between two different measure<T> types
00260         // general error propagation for any unary&binary function
00261         //
00262         // NOT NECESSARY (?):
00263         // cast operator T_to_measure<T>: this is done by default constructor
00264         // operator=  and   measure(const measure& x)
00265         // 
00266         // improve PERFORMANCE: 
00267         // less temp's where possible
00268         // direct implementation of
00269         //  pow(measure, T), pow(T, measure)
00270         //  pow(measure, int), pow(int, measure)
00271         //  sqrt instead of pow(arg,0.5)
00272         //  exp  instead of pow(e,arg)
00273 };
00274 
00275 // core functions that directly manipulate the implementation
00276 
00277 // input, output
00278 template<class T>
00279 ostream& operator<<(ostream& os, const measure<T>& rhs) {
00280         return os<<rhs.value<<ASCII_PLUSMINUS<<rhs.stddev;
00281 }
00282 template<class T>
00283 istream& operator>>(istream& is, measure<T>& rhs) {
00284         T value, stddev;
00285         is >> value;    rhs.value=value;
00286         is >> stddev;   rhs.stddev=fabs(stddev);
00287         return is;
00288 }
00289 
00290 // plus, minus, multiply, divide, pow, log, log10, fabs
00291 // sin, cos, tan, asin, acos, atan
00292 template<class T> 
00293 measure<T>& measure<T>::operator+=(const measure<T>& rhs){
00294         stddev =sum2<T>(stddev, rhs.stddev);
00295         value +=rhs.value;
00296         return *this;
00297 }
00298 template<class T> 
00299 measure<T>& measure<T>::operator-=(const measure<T>& rhs){
00300         stddev =sum2<T>(stddev, rhs.stddev);
00301         value -=rhs.value;
00302         return *this;
00303 }
00304 template<class T> 
00305 measure<T>& measure<T>::operator*=(const measure<T>& rhs){
00306         stddev =sum2<T>(stddev*rhs.value, rhs.stddev*value);
00307         value *=rhs.value;
00308         return *this;
00309 }
00310 template<class T> 
00311 measure<T>& measure<T>::operator/=(const measure<T>& rhs){
00312         stddev =sum2<T>(stddev/rhs.value, rhs.stddev*value/(rhs.value*rhs.value));
00313         value /=rhs.value;
00314         return *this;
00315 }
00316 template<class T> 
00317 measure<T> pow(const measure<T>& lhs, const measure<T>& rhs){
00318         measure<T> temp;
00319         temp.stddev=sum2<T>(lhs.stddev*rhs.value*pow(lhs.value,rhs.value-1), 
00320                                         rhs.stddev*log(lhs.value)*pow(lhs.value,rhs.value));
00321         temp.value=pow(lhs.value, rhs.value);
00322         return temp;
00323 }
00324 template<class T> 
00325 measure<T> log(const measure<T>& arg){
00326         measure<T> temp;
00327         temp.stddev=arg.stddev/fabs(arg.value);
00328         temp.value=log(arg.value);
00329         return temp;
00330 }
00331 template<class T> 
00332 measure<T> log10(const measure<T>& arg){
00333         measure<T> temp;
00334         temp.stddev=arg.stddev/(fabs(arg.value)*log(10));
00335         temp.value=log10(arg.value);
00336         return temp;
00337 }
00338 template<class T> 
00339 measure<T> fabs(const measure<T>& arg){
00340         measure<T> temp;
00341         temp.stddev=arg.stddev;
00342         temp.value=fabs(arg.value);
00343         return temp;
00344 }
00345 // sin, cos, tan, asin, acos, atan
00346 template<class T> measure<T> sin(const measure<T>& arg){
00347         measure<T> temp;
00348         temp.stddev=arg.stddev*fabs(cos(arg.value));
00349         temp.value=sin(arg.value);
00350         return temp;
00351 }
00352 template<class T> measure<T> cos(const measure<T>& arg){
00353         measure<T> temp;
00354         temp.stddev=arg.stddev*fabs(sin(arg.value));
00355         temp.value=cos(arg.value);
00356         return temp;
00357 }
00358 template<class T> measure<T> tan(const measure<T>& arg){
00359         measure<T> temp;
00360         temp.stddev=arg.stddev/(cos(arg.value)*cos(arg.value));
00361         temp.value=tan(arg.value);
00362         return temp;
00363 }
00364 template<class T> measure<T> asin(const measure<T>& arg){
00365         measure<T> temp;
00366         temp.stddev=arg.stddev/sqrt(1- arg.value*arg.value);
00367         temp.value=asin(arg.value);
00368         return temp;
00369 }
00370 template<class T> measure<T> acos(const measure<T>& arg){
00371         measure<T> temp;
00372         temp.stddev=arg.stddev/sqrt(1- arg.value*arg.value);
00373         temp.value=acos(arg.value);
00374         return temp;
00375 }
00376 template<class T> measure<T> atan(const measure<T>& arg){
00377         measure<T> temp;
00378         temp.stddev=arg.stddev/(1+ arg.value*arg.value);
00379         temp.value=atan(arg.value);
00380         return temp;
00381 }
00382 // bool overlap (a,b)
00383 // are two numbers equal within the errorbars?
00384 template<class T> bool overlap(const measure<T>& lhs, const measure<T>& rhs){
00385         return (fabs(lhs.value-rhs.value)) < (lhs.stddev + rhs.stddev);
00386 }
00387 
00388 // derived functions that don't directly manipulate the implementation
00389 
00390 // plus, minus, multiply, divide, pow, exp, sqrt, overlap
00391 // plus:
00392 template<class T> 
00393 measure<T>& measure<T>::operator+=(const T& rhs){
00394         this += measure<T>(rhs,0);
00395         return *this;
00396 }
00397 template<class T>
00398 measure<T> operator+(const measure<T>& lhs, const measure<T>& rhs){
00399         measure<T> temp=lhs;
00400         temp+=rhs;
00401         return temp;
00402 }
00403 template<class T>
00404 measure<T> operator+(const measure<T>& lhs, const T& rhs){
00405         return lhs + measure<T>(rhs,0);
00406 }
00407 template<class T>
00408 measure<T> operator+(const T& lhs, const measure<T>& rhs){
00409         return measure<T>(lhs,0) + rhs ;
00410 }
00411 // minus:
00412 template<class T> 
00413 measure<T>& measure<T>::operator-=(const T& rhs){
00414         this -= measure<T>(rhs,0);
00415         return *this;
00416 }
00417 template<class T>
00418 measure<T> operator-(const measure<T>& lhs, const measure<T>& rhs){
00419         measure<T> temp=lhs;
00420         temp-=rhs;
00421         return temp;
00422 }
00423 template<class T>
00424 measure<T> operator-(const measure<T>& lhs, const T& rhs){
00425         return lhs - measure<T>(rhs,0);
00426 }
00427 template<class T>
00428 measure<T> operator-(const T& lhs, const measure<T>& rhs){
00429         return measure<T>(lhs,0) - rhs ;
00430 }
00431 // multiply:
00432 template<class T> 
00433 measure<T>& measure<T>::operator*=(const T& rhs){
00434         this *= measure<T>(rhs,0);
00435         return *this;
00436 }
00437 template<class T>
00438 measure<T> operator*(const measure<T>& lhs, const measure<T>& rhs){
00439         measure<T> temp=lhs;
00440         temp*=rhs;
00441         return temp;
00442 }
00443 template<class T>
00444 measure<T> operator*(const measure<T>& lhs, const T& rhs){
00445         return lhs * measure<T>(rhs,0);
00446 }
00447 template<class T>
00448 measure<T> operator*(const T& lhs, const measure<T>& rhs){
00449         return measure<T>(lhs,0) * rhs ;
00450 }
00451 // divide:
00452 template<class T> 
00453 measure<T>& measure<T>::operator/=(const T& rhs){
00454         this /= measure<T>(rhs,0);
00455         return *this;
00456 }
00457 template<class T>
00458 measure<T> operator/(const measure<T>& lhs, const measure<T>& rhs){
00459         measure<T> temp=lhs;
00460         temp/=rhs;
00461         return temp;
00462 }
00463 template<class T>
00464 measure<T> operator/(const measure<T>& lhs, const T& rhs){
00465         return lhs / measure<T>(rhs,0);
00466 }
00467 template<class T>
00468 measure<T> operator/(const T& lhs, const measure<T>& rhs){
00469         return measure<T>(lhs,0) / rhs ;
00470 }
00471 // change the sign:
00472 template<class T> measure<T> operator-(const measure<T>& rhs){
00473         return ((T)0-rhs);
00474 }
00475 // do nothing (a= +a):
00476 template<class T> measure<T> operator+(const measure<T>& rhs){
00477         return rhs;
00478 }
00479 // pow
00480 template<class T>
00481 measure<T> pow(const T& lhs , const measure<T>& rhs){
00482         return pow(measure<T>(lhs,0), rhs);
00483 }
00484 template<class T>
00485 measure<T> pow(const measure<T>& lhs, const T& rhs){
00486         return pow(lhs, measure<T>(rhs,0));
00487 }
00488 // comment these two out, if T=int
00489 template<class T>
00490 measure<T> pow(const measure<T>& lhs, const int& rhs){
00491         return pow(lhs, measure<T>((T)rhs,0));
00492 }
00493 template<class T>
00494 measure<T> pow(const int& lhs, const measure<T>& rhs){
00495         return pow(measure<T>((T)lhs,0), rhs);
00496 }
00497 // exp, sqrt
00498 template<class T>
00499 measure<T> exp(const measure<T>& arg){ return pow(exp(1),arg);}
00500 template<class T>
00501 measure<T> sqrt (const measure<T>& arg){ return pow(arg, 0.5);}
00502 // overlap
00503 template<class T> bool overlap(const measure<T>& lhs, const T& rhs){
00504         return overlap(lhs, measure<T>(rhs,0));
00505 }
00506 template<class T> bool overlap(const T& lhs, const measure<T>& rhs){
00507         return overlap(measure<T>(lhs,0), rhs);
00508 }
00509 
00510 // helpers:
00511 bool random_errors_set(){
00512 #ifdef RANDOM_ERRORS
00513         return true;
00514 #else 
00515         return false;
00516 #endif
00517 }
00518 
00519 const char* answer_random_errors_set(){
00520         return random_errors_set()?"yes":" no";
00521 }
00522 
00523 // tests (you can remove them, if you want to)
00524 void test_measureclass(){
00525         cout <<"\nWelcome!\nTEST the measure<double> class:"<<endl;
00526         typedef measure<double> measure;
00527         measure a=measure(5, 0.5);
00528         measure b=measure(2, 0.2);
00529         double c=2;
00530         measure d,e,f,g;
00531         cout <<"\na="<<a<<"\t\tb="<<b<<"\t\tc="<<c<<endl;
00532 
00533         cout<<endl;
00534         cout<<"calculate a +-*/ b"<<flush;
00535         cout <<"\na+b= "<<a+b<<"\na-b= "<<a-b<<"\na*b= "<<a*b<<"\na/b= "<<a/b<<endl;
00536 
00537         cout<<endl;
00538         cout<<"calculate a +-*/ c"<<flush;
00539         cout <<"\na+c= "<<a+c<<"\na-c= "<<a-c<<"\na*c= "<<a*c<<"\na/c= "<<a/c<<endl;
00540 
00541         cout<<endl;
00542         cout<<"calculate c +-*/ a"<<flush;
00543         cout <<"\nc+a= "<<c+a<<"\nc-a= "<<c-a<<"\nc*a= "<<c*a<<"\nc/a= "<<c/a<<endl;
00544 
00545         cout<<endl;
00546         cout<<"calculate pow(*,*);"<<flush;
00547         cout <<"\npow(a,b)= "<<pow(a,b)<<"\npow(a,c)= "<<pow(a,c);
00548         cout <<"\npow(b,a)= "<<pow(b,a)<<"\npow(c,a)= "<<pow(c,a)<<endl;;
00549 
00550         cout <<"\n+a= "<<+a<<"\n-a= "<<-a<<endl;
00551         a++;
00552         cout <<"a++;  a= "<<a<<endl;
00553         a--;
00554         cout <<"a--;  a= "<<a<<endl;
00555         
00556         cout<<endl;
00557         cout<<"calculate log/log10/exp/sqrt (a= "<<a<<")"<<flush;
00558         cout <<"\n  log(a)= "<<log(a)<<"\nlog10(a)= "<<log10(a);
00559         cout <<"\n  exp(a)= "<<exp(a)<<"\n sqrt(a)= "<<sqrt(a)<<endl;;
00560 
00561         cout<<endl;
00562         cout<<"calculate sin/cos/tan (a= "<<a<<")"<<flush;
00563         cout <<"\nsin(a)= "<<sin(a)<<"\ncos(a)= "<<cos(a)<<"\ntan(a)= "<<tan(a)<<endl;
00564         cout<<endl;
00565         a= measure(0.5,0.05);
00566         cout<<"calculate asin/acos/atan (a= "<<a<<")"<<flush;
00567         cout <<"\nasin(a)= "<<asin(a)<<"\nacos(a)= "<<acos(a)<<"\natan(a)= "<<atan(a)<<endl;
00568 
00569         a=measure(4, 0.5);
00570         b=measure(6, 1.2);
00571         c=7;
00572         cout <<"\na= "<<a<<"\tb= "<<b<<"\tc= "<<c<<endl;
00573         cout <<"overlap(a,b)="<<overlap(a,b);
00574         cout <<"\t  overlap(b,a)="<<overlap(b,a)<<endl;
00575         cout <<"overlap(b,c)="<<overlap(b,c);
00576         cout <<"\t  overlap(c,b)="<<overlap(c,b)<<endl;
00577 
00578         cout<<"\nPlease send your experiences with this class to   cpp__at__AndreasKrueger__dot__de\n"<<endl;
00579 }
00580 
00581 void interactive_test_measureclass(){
00582         typedef measure<double> measure;
00583         measure a,b;    
00584         cout <<"Type in two numbers with errors:";
00585         cin >> a >>b;
00586         cout <<"a= "<<a<<"\t  b= "<<b<<endl;
00587         cout <<"a+b= "<<a+b<<endl;
00588         cout <<"a*b= "<<a*b<<endl;
00589         cout <<"pow(a,b)= "<<pow(a,b)<<endl;
00590         cout <<"(RANDOM_ERRORS: "<<answer_random_errors_set()<<")"<<endl;
00591 }
00592 




Diploma Thesis Sourcecode Documentation
check out the text and the executable binaries

www.AndreasKrueger.de/thesis/code