loading...
مرجع مهندسی نرم افزار
آخرین ارسال های انجمن
حامد شیرزاد بازدید : 862 پنجشنبه 03 آذر 1390 نظرات (0)
 
    #include
    using namespace std;
     
    class Root{
    private:
            static unsigned long double pow(unsigned long double number, 
int power){
                    unsigned long double retVal = number;
                    for(int i=0; i
                            retVal *= number;
                    }
                    return retVal;
            }
    public:
            static unsigned long double nroot(unsigned long double number, int root)
{
                    if(number < 0){
                            throw "ERROR - It is possible that tere were no real 
answers.nNumber entered was less than 0."
;
                    }
                    unsigned long double low = 0, high = (number/2)+1, mid = 
(low+high)/2;
                    for(;(low < high) && ((pow(mid, root)-number)>0.000001 ||
 (pow(mid, root)-number)<-0.000001); mid = (low+high)/2){
                            if(pow(mid, root) < number){
                                    low = mid;
                            }
                            else if(pow(mid, root) > number){
                                    high = mid;
                            }
                            else{
                                    return mid;
                            }
                    }
                    return (low+high)/2;
            }
            static unsigned long double sqrt(unsigned long double number){
                    return nroot(number, 2);
            }
    };
     
    int main(...){
            try{
                    cout << endl << Root::nroot(123.14159, 15) << endl;
            }
            catch(char* error){
                    cout << error << endl;
            }
     
            return 0;
    } 
حامد شیرزاد بازدید : 611 پنجشنبه 03 آذر 1390 نظرات (0)
 
    #include <windows.h>
    #include <iostream>
     
    #pragma comment(lib, "user32.lib")
     
    using std::cout;
    using std::cin;
     
    int main() {
       SYSTEM_INFO siSysInfo;
     
       // Copy the hardware information to the SYSTEM_INFO structure.
       GetSystemInfo(&siSysInfo);
     
       // Display the contents of the SYSTEM_INFO structure.
     
       cout << "Hardware information: n"; 
       cout << "  OEM ID: " << siSysInfo.dwOemId << "n";
       cout << "  Number of processors: " << siSysInfo.dwNumberOfProcessors << "n";
       cout << "  Page size: " << siSysInfo.dwPageSize << "n";
       cout << "  Processor type: " << siSysInfo.dwProcessorType << "n";
       cout << "  Minimum application address:" << siSysInfo.lpMinimumApplicationAddress << "n";
       cout << "  Maximum application address: " << siSysInfo.lpMaximumApplicationAddress << "n";
       cout << "  Active processor mask: " << siSysInfo.dwActiveProcessorMask << "n";
       cin.get();
       return 0;
    }
حامد شیرزاد بازدید : 793 پنجشنبه 03 آذر 1390 نظرات (0)
 
    // cubic equation solver example using Cardano's method
    #include <cmath>
    #include <iostream>
    #define THIRD 0.333333333333333
    #define ROOTTHREE 1.73205080756888       
     
    using namespace std;
     
    // this function returns the cube root if x were a negative number aswell
    double cubeRoot(double x)
    {
        if (x < 0)
            return -pow(-x, THIRD);
        else
            return pow(x, THIRD);
    }
     
    void solveCubic(double a, double b, double c, double d)
    {
        // find the discriminant
        double f, g, h;
        f = (3 * c / a - pow(b, 2) / pow(a, 2)) / 3;
        g = (2 * pow(b, 3) / pow(a, 3) - 9 * b * c / pow(a, 2) + 27 * d / a) / 27;
        h = pow(g, 2) / 4 + pow(f, 3) / 27;
        // evaluate discriminant
        if (f == 0 && g == 0 && h == 0)
        {
            // 3 equal roots
            double x;
            // when f, g, and h all equal 0 the roots can be found by the following line
            x = -cubeRoot(d / a);
            // print solutions
            cout
                << "x = " << endl
                << " " << x << endl
                << " " << x << endl
                << " " << x << endl << endl;
        }
        else if (h <= 0)
        {
            // 3 real roots
            double q, i, j, k, l, m, n, p;
            // complicated maths making use of the method
            i = pow(pow(g, 2) / 4 - h, 0.5);
            j = cubeRoot(i);
            k = acos(-(g / (2 * i)));
            m = cos(k / 3);
            n = ROOTTHREE * sin(k / 3);
            p = -(b / (3 * a));
            // print solutions
            cout
                << "x = " << endl
                << " " << 2 * j * m + p << endl
                << " " << -j * (m + n) + p << endl
                << " " << -j * (m - n) + p << endl << endl;
        }
        else if (h > 0)
        {
            // 1 real root and 2 complex roots
            double r, s, t, u, p;
            // complicated maths making use of the method
            r = -(g / 2) + pow(h, 0.5);
            s = cubeRoot(r);
            t = -(g / 2) - pow(h, 0.5);
            u = cubeRoot(t);
            p = -(b / (3 * a));
            // print solutions
            cout
                << "x = " << endl
                << " " << (s + u) + p << endl
                << " " << -(s + u) / 2 + p << " +" << (s - u) * ROOTTHREE / 2 << "i" << endl
                << " " << -(s + u) / 2 + p << " " << -(s - u) * ROOTTHREE / 2 << "i" << endl << endl;
        }
    }
     
     
    int main()
    {
        double a, b, c, d;
        // introduction
        cout << "Cubic Equation Solver" << endl;
        cout << "ax^3 + bx^2 + cx + d = 0" << endl;
        cout << "with a, b, c, d are real, and a is not zero" << endl << endl;
        // infinite loop
        while (1)
        {
            // get the co-efficients of x
            cout << "a = ";
            cin >> a;
            cout << "b = ";
            cin >> b;
            cout << "c = ";
            cin >> c;
            cout << "d = ";
            cin >> d;
            solveCubic(a, b, c, d);
        }
        return 0;
    }
حامد شیرزاد بازدید : 681 پنجشنبه 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;
} 
حامد شیرزاد بازدید : 1111 پنجشنبه 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;
}

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

درباره ما
به نام آنکه جان را فکرت آموخت در این وبلاگ سعی می شود به صورت تخصصی به مباحث مربوط به مهندسی نرم افزار به خصوص برنامه نویسی کامپیوتری پرداخته شود. مدیر وبلاگ : حامد شیرزاد
اطلاعات کاربری
  • فراموشی رمز عبور؟
  • آمار سایت
  • کل مطالب : 431
  • کل نظرات : 9
  • افراد آنلاین : 1
  • تعداد اعضا : 109
  • آی پی امروز : 11
  • آی پی دیروز : 46
  • بازدید امروز : 54
  • باردید دیروز : 99
  • گوگل امروز : 0
  • گوگل دیروز : 1
  • بازدید هفته : 1,468
  • بازدید ماه : 5,392
  • بازدید سال : 33,412
  • بازدید کلی : 698,587
  • کدهای اختصاصی

    قالب وبلاگ