Showing posts with label Cplusplus. Show all posts
Showing posts with label Cplusplus. Show all posts

Thursday, April 27, 2017

Tuesday, April 18, 2017

C++ code for Derivative using Newton Backward Difference Formula

This is the solution for finding Derivative using Newton's Backward Difference Formula in C++


#include <iostream>
#include <conio.h>
using namespace std;

class DerivativeBackward
{
public:
    void askN();
    void askX();
    void askF();
    void askXX();
    void forwardTable();
    void calcd1();
    void calcd2();
    void findH();
    void solve();
    void fillDelF();
    void findS();
private:
    double XX, x[10] , f[10][10] , p[10],diff[10][10],P1,delF[10],f1,f2;
    int n;
    double h,s;

};

void DerivativeBackward::askX()
{
    cout << endl;
    for(int i = 0; i<n; i++ )
    {
        cout << "ENter X[" << i  << "] : ";
        cin >> x[i];
    }
    cout << endl;
}

void DerivativeBackward::askF()
{

    for(int j = 0; j<n; j++ )
    {
        cout << "ENter F[" << j  << "] : ";
        cin >> f[0][j];
    }
    cout << endl;
}
void DerivativeBackward::askXX()
{

    cout << "Enter X for which the value is to be found: ";
    cin >> XX;
}

void DerivativeBackward::forwardTable()
{
    for(int i = 1; i < n; i++)
    {
        for(int j = 0; j< n-i;j++)
        {
            f[i][j] = (f[i-1][j+1]-f[i-1][j]);
            if(f[i][j] < 0.0000009 && f[i][j] > 0 || f[i][j] >-0.0000009 && f[i][j]<0)
            {
                    f[i][j] = 0;
            }
        }
    }
    cout << endl;
    cout << "Sn\tXi\tf(Xi)\t";
    for(int i = 0; i <n-1;i++)
    {
        cout << i+1 << " diff\t";
    }
    cout << endl;
    for(int i = 0; i < n; i++)
    {
         cout <<i+1 <<"\t" << x[i]<< "\t";
        for(int j = 0; j< n-i;j++)
        {
            cout  << f[j][i] << "\t";
        }
        cout << endl;
    }
}

void DerivativeBackward::findH()
{
    h = x[1] - x[0];
    cout << "h = " <<h;
}
void DerivativeBackward::findS()
{
    s = (XX - x[n-1])/h;
    cout << "s = " <<s;
}
void DerivativeBackward::solve()
{
    findH();
    findS();
    fillDelF();
    calcd1();
    calcd2();


    cout <<endl << "The value of f1 :" << f1;
    cout <<endl << "The value of f2 :" << f2;
    cout  << endl << endl;
}


void DerivativeBackward::fillDelF()
{
    for(int i = 1;i<10;i++)
    {
        if(i<n)
         delF[i] = f[i][n-i-1];
        else
            delF[i] = 0;
    }
    for(int i = 1;i<10;i++)
    {
        cout<< delF[i];
    }
}

void DerivativeBackward::calcd1()
{
    f1 = 1 / h * ( delF[1] + 1/2.0 * (2 * s +1 ) * delF[2] + 1 / (6.0) * (3*s*s + 6 *s +2)*delF[3]
        + 1 /(24.0) *( 4*s*s*s+18*s*s+22*s+6)*delF[4]);
}

void DerivativeBackward::calcd2()
{
    f2 = 1 / (h*h) * (delF[2] + 1/6.0 * (6*s+6) * delF[3] + 1/24.0 *(12*s*s+36*s+22)*delF[4]);

}
void DerivativeBackward::askN()
{
    cout << "Enter the number of values: ";
    cin >> n;
}
int main()
{

    DerivativeBackward d1;
    d1.askN();
    d1.askX();
    d1.askF();
    d1.askXX();
    d1.forwardTable();
    d1.solve();
}

C++ code for Derivative using Newton Forward Difference Formula

This is the solution for finding Derivative using Newton Forward Difference Formula in C++.


#include <iostream>
#include <conio.h>
using namespace std;

class DerivativeForward
{
public:
    void askN();
    void askX();
    void askF();
    void askXX();
    void forwardTable();
    void calcd1();
    void calcd2();
    void findH();
    void solve();
    void fillDelF();
    void findS();
private:
    double XX, x[10] , f[10][10] , p[10],diff[10][10],P1,delF[10],f1,f2;
    int n;
    double h,s;

};

void DerivativeForward::askX()
{
    cout << endl;
    for(int i = 0; i<n; i++ )
    {
        cout << "ENter X[" << i  << "] : ";
        cin >> x[i];
    }
    cout << endl;
}

void DerivativeForward::askF()
{

    for(int j = 0; j<n; j++ )
    {
        cout << "ENter F[" << j  << "] : ";
        cin >> f[0][j];
    }
    cout << endl;
}
void DerivativeForward::askXX()
{

    cout << "Enter X for which the value is to be found: ";
    cin >> XX;
}

void DerivativeForward::forwardTable()
{
    for(int i = 1; i < n; i++)
    {
        for(int j = 0; j< n-i;j++)
        {
            f[i][j] = (f[i-1][j+1]-f[i-1][j]);
            if(f[i][j] < 0.0000009 && f[i][j] > 0 || f[i][j] >-0.0000009 && f[i][j]<0)
            {
                    f[i][j] = 0;
            }
        }
    }
    cout << endl;
    cout << "Sn\tXi\tf(Xi)\t";
    for(int i = 0; i <n-1;i++)
    {
        cout << i+1 << " diff\t";
    }
    cout << endl;
    for(int i = 0; i < n; i++)
    {
         cout <<i+1 <<"\t" << x[i]<< "\t";
        for(int j = 0; j< n-i;j++)
        {
            cout  << f[j][i] << "\t";
        }
        cout << endl;
    }
}

void DerivativeForward::findH()
{
    h = x[1] - x[0];

}
void DerivativeForward::findS()
{
    s = (XX - x[0])/h;

}
void DerivativeForward::solve()
{
    findH();
    findS();
    fillDelF();
    calcd1();
    calcd2();


    cout <<endl << "The value of f1 :" << f1;
    cout <<endl << "The value of f2 :" << f2;
    cout  << endl << endl;
}


void DerivativeForward::fillDelF()
{
    for(int i = 1;i<10;i++)
    {
        if(i<n)
         delF[i]=f[i][0];
        else
            delF[i] = 0;
    }
}

void DerivativeForward::calcd1()
{
    f1 = 1 / h * ( delF[1] + 1/2.0 * (2 * s -1 ) * delF[2] + 1 / (6.0) * (3*s*s - 6 *s +2)*
        delF[3] + 1 /(24.0) *( 4*s*s*s-18*s*s+22*s-6)*delF[4]);
}

void DerivativeForward::calcd2()
{
    f2 = 1 / (h*h) * (delF[2] + 1/6.0 * (6*s-6) * delF[3] + 1/24.0 *(12*s*s-36*s+22)*delF[4]);

}
void DerivativeForward::askN()
{
    cout << "Enter the number of values: ";
    cin >> n;
}
int main()
{

    DerivativeForward d1;
    d1.askN();
    d1.askX();
    d1.askF();
    d1.askXX();
    d1.forwardTable();
    d1.solve();
}

C++ code showing Hierarchical Inheritance to calculate Area

This is the solution for T.U.2068 Q.N.3

#include <iostream>

using namespace std;

class Shape
{
protected:
    int A;
public:
    Shape()
    {
        A=0;
    }
    void show();
};

class Triangle:public Shape
{
    int h, b;
public:
    void Geth();
    void Getb();
    void Showhb();
    void CalTriA();
};

class Rectangle:public Shape
{
    int l, b;
public:
    void Getl();
    void Getb();
    void Showlb();
    void CalRecA();
};

void Shape::show()
{
    cout << endl << "Area=" << A << endl ;
}

void Triangle::Geth()
{
    cout << endl << "Enter height of the triangle:" ;
    cin >> h ;
}

void Triangle::Getb()
{
    cout << endl << "Enter base of the triangle:" ;
    cin >> b ;
}

void Triangle::Showhb()
{
    cout << endl << "Triangle:" << endl ;
    cout << "Height=" << h << endl << "Base=" << b << endl ;
}

void Triangle::CalTriA()
{
    A = (h*b)/2;
}

void Rectangle::Getl()
{
    cout << endl << "Enter length of Rectangle:" ;
    cin >> l ;
}

void Rectangle::Getb()
{
    cout << endl << "Enter breadth of Rectangle:" ;
    cin >> b ;
}

void Rectangle::Showlb()
{
    cout << endl << "Rectangle" << endl ;
    cout << "Length=" << l << endl << "Breadth=" << b << endl ;
}

void Rectangle::CalRecA()
{
    A = l*b ;
}


int main()
{
    Triangle T;
    T.Geth();
    T.Getb();
    Rectangle R;
    R.Getl();
    R.Getb();
    T.Showhb();
    T.CalTriA();
    T.show();
    R.Showlb();
    R.CalRecA();
    R.show();
    return 0;
}

C++ code showing Inheritance and Data Conversion

This is the solution for T.U. 2067 Q.N.3

#include <iostream>

using namespace std;

class clock
{
protected:
    int hr, min, sec ;
public:
    clock()
    {
        hr = min = sec = 0;
    }
    clock(int x)
    {
        hr = min = sec = x ;
    }
    void Show();
};

class wall_clock:public clock
{
    int TotalTime;
public:
    wall_clock():clock()
    {
        TotalTime = 0 ;
    }
    wall_clock(int x):clock(x)
    {

    }
    void Add(int, int, int);
    void ShowTime();
};

void clock::Show()
{
    cout << endl << "Initially" << endl ;
    cout << endl << hr << ":" << min << ":" << sec << endl ;
}

void wall_clock::Add(int a, int b, int c)
{
    hr+=a;
    min+=b;
    sec+=c;
}

void wall_clock::ShowTime()
{
    if(sec>60)
    {
        min += sec/60;
        sec = sec%60;
    }
    if(min>60)
    {
        hr += min/60 ;
        min = min%60;
    }
    cout << endl << hr << ":" << min << ":" << sec << endl ;
}

int main()
{
    wall_clock WC1,WC2;
    WC1 = 0 ;
    WC2 = 0 ;
    WC1.Show();
    WC2.Show();
    WC1.Add(1,17,65);
    WC2.Add(4,45,49);
    WC1.ShowTime();
    WC2.ShowTime();
    return 0;
}

C++ code showing Hierarchical Inheritance

This is the solution for T.U. 2066 Q.N. 3

#include <iostream>

using namespace std;

class Student
{
protected:
    float avg;
public:
    void Show();
};

class ComputerScience:public Student
{
    float OOPL, OS, NM ;
public:
    void GetMarks1();
    void ShowMarks1();
    void CalAvg1();
};

class Mathematics:public Student
{
    float Calculus, LA, Geometry ;
public:
    void GetMarks2();
    void ShowMarks2();
    void CalAvg2();
};

void Student::Show()
{
    cout << endl << "Average=" << avg << endl ;
}

void ComputerScience::GetMarks1()
{
    cout << endl << "Enter marks of:" << endl ;
    cout << endl << "OOPL:"  ;
    cin >> OOPL ;
    cout << endl << "NM:" ;
    cin >>  NM ;
    cout << endl << "OS:" ;
    cin >> OS ;
}

void ComputerScience::ShowMarks1()
{
    cout << endl << "Computer Science:" << endl ;
    cout << endl << "OOPL=" << OOPL << endl << "NM=" << NM << endl << "OS=" << OS << endl ;
}

void ComputerScience::CalAvg1()
{
    avg = (OOPL + NM + OS)/3 ;
}

void Mathematics::GetMarks2()
{
    cout << endl << "Enter Marks of:" << endl ;
    cout << endl << "Calculus:" ;
    cin >> Calculus ;
    cout << endl << "LA:" ;
    cin >> LA ;
    cout << endl << "Geometry:" ;
    cin >> Geometry ;
}

void Mathematics::ShowMarks2()
{
    cout << endl << "Mathematics:" << endl ;
    cout << endl << "Calculus=" << Calculus << endl << "LA=" << LA << endl << "Geometry=" << 
    Geometry << endl ;
}

void Mathematics::CalAvg2()
{
    avg = (Calculus + LA + Geometry)/3 ;
}

int main()
{
    ComputerScience CS;
    CS.GetMarks1();
    CS.CalAvg1();
    Mathematics M;
    M.GetMarks2();
    M.CalAvg2();
    CS.ShowMarks1();
    CS.Show();
    M.ShowMarks2();
    M.Show();
    return 0;
}

Monday, April 17, 2017

C++ code for Unary Operator Overloading(--) using Friend Function

This is the solution that increases an integer value by 1 by overloaded operator using Friend Function (T.U. 2072)

#include <iostream>

using namespace std;

class Decrement
{
    int a;
public:
    Decrement()
    {
        a=10;
    }
    Decrement(int x)
    {
        a=x;
    }
    friend operator++(Decrement &I,int); //Use & while using Friend Function
    friend operator++(Decrement &I);
    void print();
};

operator++(Decrement &I,int)
{
    I.a--;
}
operator++(Decrement &I)
{
    --I.a;
}

void Decrement::print()
{
    cout << endl << "a=" << a << endl ;
}

int main()
{
    Decrement D1;
    D1.print();
    D1--;
    D1.print();
    Decrement D2(100);
    D2.print();
    --D2;
    D2.print();
    return 0;
}

C++ code for Unary Operator Overloading (++)

This is the solution that increases an integer value by 1 by overloaded operator (T.U. 2073)
#include <iostream>

using namespace std;

class Increment
{
    int a;
public:
    Increment()
    {
        a=0;
    }
    Increment(int x)
    {
        a=x;
    }
    operator++(int)
    {
        a++;
    }
    operator++()
    {
        ++a;
    }
    void print();
};

void Increment::print()
{
    cout << endl << "a=" << a << endl ;
}

int main()
{
    Increment I1(4);
    I1.print();
    I1++;
    I1.print();
    Increment I2(100);
    I2.print();
    ++I2;
    I2.print();
    return 0;
}

C++ code for Simpson's 1/3 Rule

This is the solution for finding Integration using Simpson's 1/3 Rule


#include <iostream>
#include <math.h>

using namespace std;


class Simpsons1b3
{
public:
    Simpsons1b3()
    {
        k = 2;
    }
    void askInterval();
    void solve();
    double f(double x);
    void findH();
    void findX1();
private:
    double I,h,xn,x0,k,x1;

};

void Simpsons1b3::askInterval()
{

    cout << "Enter Xn: ";
    cin >> xn;
    cout << "Enter X0: ";
    cin >> x0;
}

void Simpsons1b3::findH()
{
    h= (xn - x0)/k;
}

void Simpsons1b3::findX1()
{

    x1 = x0 + h;
}


double Simpsons1b3::f(double x)
{
    return exp(x);
}

void Simpsons1b3::solve()
{
    askInterval();
    findH();
    findX1();
    I = h / 3.0 * ( f(x0) +4 * f(x1) + f(xn) );
    cout << endl << "The required answer is : " << I << endl;
}
int main()
{
    Simpsons1b3 s1;
    s1.solve();
    return 0;
}


C++ code to Convert Centigrade to Fahrenheit

This is the solution to convert Centigrade into Fahrenheit (T.U. 2066)

#include <iostream>

using namespace std;

class Temperature
{
    float centigrade, fahrenheit ;
public:
    Temperature()
    {
        centigrade=0.0;
    }
    void GetTemp();
    void Conversion();
    void print();
};

void Temperature::GetTemp()
{
    cout << endl << "Enter temperature in centigrade:" ;
    cin >> centigrade;
}

void Temperature::Conversion()
{
    fahrenheit = ((9*centigrade)/5) + 32 ;
}

void Temperature::print()
{
    cout << endl << "Temperature in Centigrade=" << centigrade <<
 endl << "Temperature in Fahrenheit=" << fahrenheit << endl ;
}

int main()
{
    Temperature t1;
    t1.GetTemp();
    t1.Conversion();
    t1.print();
    return 0;
}

C++ code for Word Count of entered Line of Text

This is the solution for counting the number of Words in given String in C++ (T.U. 2066)

#include <iostream>
#include<string.h>

using namespace std;

class WordCount
{
    string s;
    int counts;
public:
    WordCount()
    {
        counts=1;
    }
    void GetString();
    void ReadCount();
    void print();
};

void WordCount::GetString()
{
    cout << endl << "Type your text:" ;
    getline(cin,s);
}

void WordCount::ReadCount()
{
    if(s[0]==' ')
    {
        counts=1;
    }
    for(int i=1; i<s.length(); i++)
    {
        if(s[i]==' ')
        {
            if(s[i+1]==' ')
            {
                counts = counts ;
            }
            else
            {
                counts++;
            }
        }
    }
}

void WordCount::print()
{
    cout << endl << "The string you entered is: " ;
    cout << s ;
    cout << endl << "Word Count=" << counts << endl ;
}

int main()
{
    WordCount wc;
    wc.GetString();
    wc.ReadCount();
    wc.print();
    return 0;
}

C++ code for finding the Cube of a Number using Inline Function

This is the solution for finding Cube of a given number using Inline Function in C++ (T.U. 2066)

#include <iostream>

using namespace std;

class cube
{
    int a, acube;
public:
    void geta();
    inline void cubea();
    void show();
};

void cube::geta()
{
    cout << endl << "Enter a number:" ;
    cin >> a ;
}

void cube::cubea()
{
    acube = a*a*a ;
}

void cube::show()
{
    cout << endl << "Entered number(a)=" << a << endl << "Cube of a=" << acube << endl ;
}


int main()
{
    cube c1;
    c1.geta();
    c1.cubea();
    c1.show();
    return 0;
}

C++ code to Convert Feet into Meter

This is the solution to convert Feet into Meter (T.U. 2067)
#include <iostream>

using namespace std;

class Feet2Meter
{
    float feet, meter ;
public:

    void GetFeet();
    void Conversion();
    void print();
};


void Feet2Meter::GetFeet()
{
    cout << endl << "Enter distance in feet:" ;
    cin >> feet ;
}

void Feet2Meter::Conversion()
{
    meter = 0.3048*feet ;
}

void Feet2Meter::print()
{
    cout << endl << "Distance in feet=" << feet << endl << "Distance in meter=" << meter ;
}

int main()
{
    Feet2Meter f;
    f.GetFeet();
    f.Conversion();
    f.print();
    return 0;
}

C++ code to Convert Inch into Centimeter

This is the solution to convert Inch into Centimeter in C++ (T.U. 2068)

#include <iostream>

using namespace std;

class InchtoCentimeter
{
    float Inch, Centimeter ;
public:

    void GetInch();
    void Conversion();
    void print();
};


void InchtoCentimeter::GetInch()
{
    cout << endl << "Enter inch:" ;
    cin >> Inch ;
}

void InchtoCentimeter::Conversion()
{
    Centimeter = 2.54*Inch ;
}

void InchtoCentimeter::print()
{
    cout << endl << "Inch=" << Inch << endl << "Centimeter=" << Centimeter << endl ;
}

int main()
{
    InchtoCentimeter d;
    d.GetInch();
    d.Conversion();
    d.print();
    return 0;
}

C++ code for finding the Square of a Number using Inline Function

This is the solution for finding Square of a number using Inline Function (T.U. 2067, 2068)

#include <iostream>

using namespace std;

class square
{
    int a, asqr ;
public:
    void geta();
    inline void squarea();
    void print();
};

void square::geta()
{
    cout << endl << "Enter a:" ;
    cin >> a ;
}

void square::squarea()
{
    asqr = a*a ;
}

void square::print()
{
    cout << endl << "Entered number(a)=" << a << endl << "Square of a=" << asqr << endl ;
}

int main()
{
    square s1;
    s1.geta();
    s1.squarea();
    s1.print();
    return 0;
}

C++ code for subtracting Complex Numbers by Operator Overloading

This is the C++ code for subtracting two Complex Numbers by Overloading Binary(-) Operator (T.U. 2066)

#include <iostream>

using namespace std;

class Complex
{
    float real, img ;
public:
    Complex()
    {
        real=0;
        img=0;
    }
    Complex(int x, int y)
    {
        real = x;
        img = y;
    }
    Complex operator-(Complex);
    void print();
};

void Complex::print()
{
    cout << endl << real << "+i" << img << endl ;
}

Complex Complex::operator-(Complex c1)
{
    Complex c;
    c.real = real-c1.real ;
    c.img = img-c1.img ;
    return c;
}

int main()
{
    Complex c1(4,6), c2(6,4);
    Complex c3;
    c3 = c1-c2 ;
    cout << endl << "First complex number=" << endl ;
    c1.print();
    cout << endl << "Second complex number=" << endl ;
    c2.print();
    cout << endl << "Difference=" << endl ;
    c3.print();
    return 0;
}

C++ code for Unary Operator Overloading (--)

This is the solution that decreases an integer value by 1 by overloaded operator (T.U. 2071)

#include <iostream>

using namespace std;

class decrement
{
    int a;
public:
    decrement()
    {
        a=0;
    }
    decrement(int x)
    {
        a=x;
    }
    operator--(int)
    {
        a--;
    }
    operator--()
    {
        --a;
    }
    void print();
};

void decrement::print()
{
    cout << endl << "a=" << a << endl ;
}

int main()
{
    decrement d1(4);
    d1.print();
    d1--;
    d1.print();
    decrement d2(100);
    d2.print();
    --d2;
    d2.print();
    return 0;
}

C++ code for Least Square Method

This is the solution for Least Square Method

#include <iostream>
#include <math.h>
using namespace std;

class LeastSquare
{

public:
    LeastSquare()
    {
        Ex = Ey = Exy = Exx = 0;
    }
    void askN();
    void askX();
    void askY();
    void findXY();
    void findXX();
    void findA();
    void findB();
    void solve();

private:
    double a, b , x[10],y[10],xy[10],xx[10];
    int num;
    double Ex,Ey,Exy,Exx;

};

void LeastSquare::askN()
{
    cout << "Enter the no of values: ";
    cin >> num ;
}
void LeastSquare::askX()
{
   cout << "Enter the values of X[] : \n";
    for(int i = 0 ; i <num;i++)
    {
        cout << "X[" << i << "]: ";
        cin >>x[i];
        Ex += x[i];
    }
}
void LeastSquare::askY()
{
    cout << "Enter the values of Y[] : \n";
    for(int i = 0 ; i <num;i++)
    {
        cout << "Y[" << i << "]: ";
        cin >>y[i];
        Ey += y[i];
    }
}

void LeastSquare::findXY()
{
    for(int i = 0; i < num; i++)
    {
        xy[i] = x[i] * y[i];
        Exy += xy[i];
    }

}
void LeastSquare::findXX()
{
    for(int i = 0; i < num; i++)
    {
        xx[i] = x[i] * x[i];
        Exx += xx[i];
    }

}
void LeastSquare::findA()
{
    a = Ey/num - b * Ex / num;
}
void LeastSquare::findB()
{
    b = (num * Exy - Ex * Ey) / (num * Exx - pow(Ex,2.0));

}

void LeastSquare::solve()
{
    askN();
    askX();
    askY();
    findXX();
    findXY();
    findB();
    findA();
    cout <<endl << "The Required eqn of straight line is: ";
    cout << endl << "y = " <<  a << " + " << b << "x";
}

int main()
{
    LeastSquare l;
    l.solve();

    return 0;
}

C++ code for Fixed Point Iteration Method

This is the solution for finding Root using Fixed Point Iteration method in C++

#include <iostream>
#include <math.h>
using namespace std;

class FixedPoint
{
public:
    void askEqn();
    double g(double x);
    void solve();
    void findError();
    void askX0();
    void display();
private:
    double a,b,c;
    double Error;
    double x0,x1;


};

void FixedPoint::askX0()
{
    cout << "Enter initial value of X0: ";
    cin >> x0;
}

void FixedPoint::askEqn()
{
    cout << "For the eqn ax*x + bx + c = 0 , Enter a,b,c,d:\n";
    cin >>a>>b>>c;
}
double FixedPoint::g(double x)
{
    return -(a*x*x + c) / b;
}

void FixedPoint::findError()
{
    Error = fabs( (x1-x0)/x1 );
}

void FixedPoint::solve()
{
    askEqn();
    askX0();
    cout << endl << endl << "S.N.\tXi\tXi+1\tError\n";
    do{
        x1 = g(x0);
        findError();
        display();
        x0 = x1;
    }while(Error>=0.0009);

    cout << endl<< "The root is : " << x1 <<  endl;
}
void FixedPoint::display()
{
    static int i;
    cout << ++i << "\t" << x0 << "\t" << x1 << "\t" << Error << endl;
}
int main()
{
    FixedPoint f1;
    f1.solve();
    return 0;
}

C++ code for Gauss Siedel method

This is the solution for Gauss Siedel method in C++

#include <iostream>

using namespace std;


class GaussSiedel
{

public:
    GaussSiedel()
    {
        x0=x1=x2 = 0;
    }
    void askEqn();
    void no_Iterate();
    void solve();
    void calcX0();
    void calcX1();
    void calcX2();

private:
    double a0,b0,c0,a1,b1,c1,a2,b2,c2,d0,d1,d2;
    double x0,x1,x2;
    double num;

};

void GaussSiedel::askEqn()
{
    cout << "For the eqn a0x0 + b0x1 + c0x2 = d0 , Enter a0,b0,c0,d0:\n";
    cin >>a0 >>b0>>c0>>d0;
    cout << "For the eqn a1x0 + b1x1 + c1x2 = d1 , Enter a1,b1,c1,d1:\n";
    cin >>a1 >>b1>>c1>>d1;
    cout << "For the eqn a2x0 + b2x1 + c2x2 = d2 , Enter a2,b2,c2,d2:\n";
    cin >>a2>>b2>>c2>>d2;
}

void GaussSiedel::no_Iterate()
{

    cout << "Enter up to how much iteration do you want to go: ";
    cin >> num;
}
void GaussSiedel::calcX0()
{
    x0 = ( d0 - b0 * x1 - c0 * x2) /a0;
}

void GaussSiedel::calcX1()
{
    x1 = ( d1 - a1 * x0 - c1 * x2) /b1;
}

void GaussSiedel::calcX2()
{
    x2 = ( d2 - b2 * x1 - a2 * x0) / c2;
}

void GaussSiedel::solve()
{
    for(int i = 0;i<num;i++)
    {
        calcX0();
        calcX1();
        calcX2();

        cout << endl << endl <<"Iteration " << i+1 << ": \n";
        cout << "X0 = " << x0 << endl << "X1 = " << x1 << endl << "X2 = " << x2 ;
    }


}

int main()
{
    GaussSiedel g1;
    g1.askEqn();
    g1.no_Iterate();
    g1.solve();
    return 0;
}