loading...
مرجع مهندسی نرم افزار
آخرین ارسال های انجمن
حامد شیرزاد بازدید : 700 پنجشنبه 03 آذر 1390 نظرات (0)
#include <iostream>
#include <iomanip>
#include <cmath>
#include <ctime>
 
long double Pow(const long double x, const int power)
{
        // x ^ 0 is 1
        if (power == 0)
                return 1;
 
        // x ^ 1 is x
        if (power == 1)
                return x;
 
        int c, i, k;
        long double res;
        long double px;
 
        // We observe that x ^ power could be written as a product of
        // factors, in which we may find: x ^ 1, x ^ 2, x ^ 4, x ^ 8 ...
        // A factor appears in the product if in the binary representation
        // of "power", the corresponding digit is 1. The result is multiplied
        // with "power", only if the digit is 1. E.g: x ^ 13 = x ^ 8 + x ^ 4 + x ^ 1,
        // because 13 in binary is 1101.
        // To convert the power to binary, we must divide it with 2 at every iteration.
        for (i = 1, px = x, res = 1, k = power; k; k /= 2)
        {
                c = k % 2; // Obtain the digit
                // Check if the digit is 1. Only if it is 1 then we
                // multiply res with px
                if (c)
                        res *= px;
                px *= px;
        }
 
        return res;
}
 
int main()
{
        // Recommended, because Pow may return a big number.
        std::cout << std::setprecision(10);
       
        // This is here to demonstrate the ability of the function:
        time_t start = clock();
        std::cout << "<cmath> pow() took: ";
        for (unsigned long long int i = 0; i < 999999999; i++)
                double x = pow(300.0f, 4);
        time_t stop = clock();
        // <cmath> pow takes between 1950 - 2100 ticks for me.
        std::cout << stop - start << " ticks!n";
 
        start = clock();
        std::cout << "My pow() took: ";
        for (unsigned long long int i = 0; i < 999999999; i++)
                double x = Pow(300.0f, 4);
        stop = clock();
        // The above Pow takes between 1000 - 1150 ticks for me.
        std::cout << stop - start << " ticks!n";
 
        std::cin.get();
        return 0;
} 
حامد شیرزاد بازدید : 1145 پنجشنبه 03 آذر 1390 نظرات (0)
#include <iostream.h>
 
int main()
{
 
  double
    Temperature,
    PressureMeasured,
    DewPoint;
 
  // Get Temperature as input from the user
  cout << "nPlease enter the current Temperature (Celsius): ";
  cin >> Temperature;
 
  // Get PressureMeasured as input from the user
  cout << "nPlease enter the current Measured Pressure (hPa): ";
  cin >> PressureMeasured;
 
  // Get Dew Point as input from the user
  cout << "nPlease enter the current Dew Point (Celsius): ";
  cin >> DewPoint;
 
  const double
    eso = 6.1078,
    c0   = 0.99999683,
    c1   = -0.90826951e-2,
    c2   = 0.78736169e-4,
    c3   = -0.61117958e-6,
    c4   = 0.43884187e-8,
    c5   = -0.29883885e-10,
    c6   = 0.21874425e-12,
    c7   = -0.17892321e-14,
    c8   = 0.11112018e-16,
    c9   = -0.30994571e-19;
 
  // 2.  Es     = eso*(p**(-8))
  //
  // Es = Pv when Temperature is at Dew Point
  // Es checked against 1958 Smithsonian Meterological Tables,
  //  Smithsonian Institute, Washington, D.C. for accuracy
  double p;
  p = c0+(DewPoint*(c1+(DewPoint*(c2+(DewPoint*(c3+(DewPoint*(c4+(DewPoint*(c5+(DewPoint*(c6+(DewPoint*(c7+(DewPoint*(c8+(DewPoint*c9)))))))))))))))));
 
  double
    SaturationPressure,
    DryAirPressure,
    WaterVaporPressure,
    Density;
 
  SaturationPressure = eso * pow(p, -8);
  WaterVaporPressure = SaturationPressure;
 
  DryAirPressure = PressureMeasured - WaterVaporPressure;
 
  const float
    GasConstantDry = 287.05,
    GasConstantVapor = 461.495;
 
  // Air Density Calculation
  Density = (DryAirPressure*100/(GasConstantDry*(Temperature+273.15))) +
              (WaterVaporPressure*100/(GasConstantVapor*(Temperature+273.15)));
 
  cout << "nThe Air Density is " << Density << " kg/m^3.nn";
 
  return 0;
}
حامد شیرزاد بازدید : 1856 پنجشنبه 03 آذر 1390 نظرات (0)


مثلث متساوی الاضلاعی را در نظر بگیرید. وسط های ضلع های آن را به هم وصل کنید ومثلث متساوی الاضلاعی که در وسط پدید می آید را از آن حذف نمائید .





اکنون سه مثلث متساوی الاضلاع باقی مانده در شکل را در نظر بگیرید ,وسط های ضلع ها را در هر مثلث به هم وصل کرده واز درون هر یک, مثلث متساوی الاضلاعی که در وسط پدید می آید را حذف نمائید .



با تکرار این روش در دو گام بعدی این شکل ها حاصل می شوند :



 



 


 اگر این فرآیند را تا بی نهایت تکرار کنیم، شکل به دست آمده را مثلث سیرپینسکی گویند .

حامد شیرزاد بازدید : 679 پنجشنبه 03 آذر 1390 نظرات (0)
 
    #include <iostream>
    #include <string>
     
    bool Find(std::string input, const std::string &substring)
    {
            // If the substring length is bigger than input length, what's the point to continue?
            if (substring.length() > input.length())
                    return false;
     
            // If both arguments are equal, what's the point to continue?
            if (input == substring)
                    return true;
     
            int substr_length = substring.length(); // Find 'substring' length
            unsigned int index = 0;
            while (index < input.length())
            {
                    std::string to_compare = "";
                    int f_pos = input.find(substring[0]); // Position in 'input' of the first 'substring' character
                    if (f_pos == input.npos) // Couldn't find?
                            return false;
                    for (int i = f_pos; i <= substr_length + f_pos - 1; i++)
                            to_compare += input[i]; // Build a substring
     
                    // Compare it with the 'substring' parameter
                    if (to_compare != substring)
                    {
                            int find = input.find(substring[0]); // Position in 'input' of the first 'substring' character
                            if (find != input.npos)
                                    input.erase(find, substr_length - 1); // Erase the substring if it wasn't equal with 'substring'
                    }
                    else
                            return true;
     
                    index++;
            }
     
            // To avoid a warning
            return false;
    }
     
    int main()
    {
            // A simple test:
            if (Find("alex", "lex"))
                    std::cout << "Found substring!" << std::endl;
            else
                    std::cout << "Didn't find substring!" << std::endl;
     
            return 0;
    } 
حامد شیرزاد بازدید : 679 پنجشنبه 03 آذر 1390 نظرات (0)
bool isnumeric( char str[] )
{
    int dpt_cnt = 0;
    int dpt_loc = 0;
    int com_loc = -1;
    bool hascom = false;
 
    int len = (signed int)strlen( str ) + 1;
    for ( int i=0; i<len; i++ ) {
 
        if ( str[i] == '' ) {
            if ((( i - com_loc ) != 4 ) && ( i > 3 )
              && ( hascom == true )
              && ( !(dpt_loc > com_loc))) {
                return false;
            }
            break;
        }
        if ( str[i] == '.' ) {
            dpt_loc = i;
            if ( ( dpt_cnt > 0 ) ||
                 ((dpt_loc - com_loc) != 4 ) &&
                 ( hascom == true ) ) {
                    return false;
            }
            dpt_cnt++;
        }
        if ( str[i] == ',' ) {
            hascom = true;
            if ( ( i == 0 ) ||
                 ((( i - com_loc ) != 4 ) && ( i > 3 )) ) {
                return false;
            }
            com_loc = i;
        }
        if (( str[i] == '-' ) && ( i > 0 )) {
            return false;
        }
        if ( int(str[i])<48 || int(str[i])>57 ) {
            if (( str[i] != '.' ) && ( str[i] != '-' )
                && ( str[i] != ',' )) {
               return false;
            }
        }
 
    }
    return true;
}

تعداد صفحات : 46

درباره ما
به نام آنکه جان را فکرت آموخت در این وبلاگ سعی می شود به صورت تخصصی به مباحث مربوط به مهندسی نرم افزار به خصوص برنامه نویسی کامپیوتری پرداخته شود. مدیر وبلاگ : حامد شیرزاد
اطلاعات کاربری
  • فراموشی رمز عبور؟
  • آمار سایت
  • کل مطالب : 431
  • کل نظرات : 9
  • افراد آنلاین : 1
  • تعداد اعضا : 109
  • آی پی امروز : 15
  • آی پی دیروز : 56
  • بازدید امروز : 266
  • باردید دیروز : 420
  • گوگل امروز : 0
  • گوگل دیروز : 0
  • بازدید هفته : 3,330
  • بازدید ماه : 5,981
  • بازدید سال : 25,082
  • بازدید کلی : 793,610
  • کدهای اختصاصی

    قالب وبلاگ