C++ Programming Tutorial

 
 
 
 

Image

 # include <iostream.h>
 # include   <stdlib.h>
 # include    <stdio.h>
 # include    <conio.h>
 # include     <math.h>

 const int max_size=5;

 int n=0;

 char Partial_pivoting=NULL;

 long double input[max_size][max_size]={0};
 long double output[max_size]={0};

 void show_screen( );
 void clear_screen( );
 void get_size_of_linear_equations( );
 void show_input(const int,const int,const int=0);
 void get_input_linear_equation( );
 void sort_system_of_linear_equations(const int);
 void apply_gaussian_method( );
 void generate_result( );
 void show_result( );

 int main( )
    {
       clrscr( );
       textmode(C4350);

       show_screen( );
       get_size_of_linear_equations( );
       get_input_linear_equation( );
       apply_gaussian_method( );
       generate_result( );
       show_result( );

       getch( );
       return 0;
    }


 //--------------------------  show_screen( )  ---------------------------//


 void show_screen( )
    {
       cprintf(\"\\n********************************************************************************\");
       cprintf(\"***********************-                               -************************\");
       cprintf(\"*----------------------- \");

       textbackground(1);
       cprintf(\" Gaussian Elimination Method \");
       textbackground(8);

       cprintf(\" ------------------------*\");
       cprintf(\"*-*********************-                               -**********************-*\");
       cprintf(\"*-****************************************************************************-*\");

       for(int count=0;count<42;count++)
      cprintf(\"*-*                                                                          *-*\");

       gotoxy(1,46);
       cprintf(\"*-****************************************************************************-*\");
       cprintf(\"*------------------------------------------------------------------------------*\");
       cprintf(\"********************************************************************************\");

       gotoxy(1,2);
    }


 //-------------------------  clear_screen( )  ---------------------------//


 void clear_screen( )
    {
       for(int count=0;count<37;count++)
      {
         gotoxy(5,8+count);
         cout<<\"                                                                        \";
      }

       gotoxy(1,2);
    }


 //------------------  get_size_of_linear_equations( )  ------------------//


 void get_size_of_linear_equations( )
    {
       do
      {
         clear_screen( );

         gotoxy(40,11);
         cout<<\"[ Maximum size = 4 ]\";

         gotoxy(6,9);
         cout<<\"Enter the size of the System of Linear Equations = n = \";

         cin>>n;

         if(n<=0 || n>max_size)
        {
           gotoxy(12,25);
           cout<<\"Error : Wrong Input. Press <Esc> to exit or any other key\";

           gotoxy(12,26);
           cout<<\"        to try again.\";

           n=int(getche( ));

           if(n==27)
              exit(0);
        }
      }
       while(n<=0 || n>max_size);

       gotoxy(6,15);
       cout<<\"Do you want to use Partial Pivoting : (Y/N) ? : \";

       cin>>Partial_pivoting;

       gotoxy(1,2);
    }


 //-------------  show_input(const int,const int,const int)  -------------//


 void show_input(const int x,const int y,const int y_cord)
    {
       int counter=0;
       int number_of_inputs=((x*n)+y+x);

       for(int count_1=0;count_1<n;count_1++)
      {
         gotoxy(6,(17+(count_1*2)+y_cord));
         cout<<\"                                                                      \";

         gotoxy(6,(17+(count_1*2)+y_cord));

         for(int count_2=0;count_2<=n;count_2++)
        {
           if(counter==(number_of_inputs+1))
              textbackground(12);

           else
              textbackground(8);

           if(count_2==n)
              gotoxy((wherex( )+5),(17+(count_1*2)+y_cord));

           gotoxy(wherex( ),(17+(count_1*2)+y_cord));
           cprintf(\"      \");

           if(count_2==n)
              gotoxy((wherex( )-5),(17+(count_1*2)+y_cord));

           gotoxy((wherex( )-6),(17+(count_1*2)+y_cord));

           if(counter<=number_of_inputs && counter!=-1)
              {
             if(count_2==n)
                {
                   cout<<\"  =  \";
                   cout<<input[count_1][count_2];
                }

             else if(count_2==0)
                cout<<input[count_1][count_2]<<\" x\"<<(count_2+1);

             else
                cout<<fabs(input[count_1][count_2])<<\" x\"<<(count_2+1);
              }

           else if(count_2==n)
              cout<<\"  =  b\"<<(count_1+1);

           else
              cout<<\"a\"<<(count_1+1)<<(count_2+1)<<\" x\"<<(count_2+1);

           if(count_2<(n-1) && input[count_1][(count_2+1)]>=0)
              cout<<\"  +  \";

           else if(count_2<(n-1))
              cout<<\"  -  \";

           counter++;
        }
      }
    }


 //--------------------  get_input_linear_equation( )  -------------------//


 void get_input_linear_equation( )
    {
       clear_screen( );

       gotoxy(6,9);
       cout<<\"Size of the System of Linear Equations = n = \"<<n;

       gotoxy(6,13);
       cout<<\"System of Linear Equations :\";

       gotoxy(6,14);
       cout<<\"ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ\";

       show_input(0,-1);

       for(int count_1=0;count_1<n;count_1++)
      {
         for(int count_2=0;count_2<=n;count_2++)
        {
           gotoxy(5,35);
           cout<<\"                                                                    \";

           gotoxy(6,35);

           if(count_2<n)
             cout<<\"Enter the value of a\"<<(count_1+1)<<(count_2+1)<<\" =  \";

           else
             cout<<\"Enter the value of b\"<<(count_1+1)<<\" =  \";

           cin>>input[count_1][count_2];

           show_input(count_1,count_2);
        }
      }
    }


 //-------------  sort_system_of_linear_equations(const int)  ------------//


 void sort_system_of_linear_equations(const int start_position)
    {
       for(int count_1=start_position;count_1<(n-1);count_1++)
      {
         for(int count_2=start_position;count_2<(n-1);count_2++)
        {
           long double temp[max_size]={0};

           if(fabs(input[count_2][start_position])<fabs(input[(count_2+1)][start_position]))
              {
             for(int count_3=0;count_3<=n;count_3++)
                temp[count_3]=input[count_2][count_3];

             for(int count_4=0;count_4<=n;count_4++)
                input[count_2][count_4]=input[(count_2+1)][count_4];

             for(int count_5=0;count_5<=n;count_5++)
                input[(count_2+1)][count_5]=temp[count_5];
              }
        }
      }
    }


 //-----------------------  apply_gaussian_method( )  --------------------//


 void apply_gaussian_method( )
    {
       for(int count_1=0;count_1<(n-1);count_1++)
      {
         if(Partial_pivoting==\'Y\' || Partial_pivoting==\'y\')
        sort_system_of_linear_equations(count_1);

         for(int count_2=(count_1+1);count_2<n;count_2++)
        {
           long double multiplier=
              (input[count_2][count_1]/input[count_1][count_1]);

           for(int count_3=0;count_3<=n;count_3++)
              {
             long double temp=(input[count_1][count_3]*multiplier);
             input[count_2][count_3]=(input[count_2][count_3]-temp);
              }
        }
      }
    }


 //------------------------  generate_result( )  -------------------------//


 void generate_result( )
    {
       for(int count_1=(n-1);count_1>=0;count_1--)
      {
         output[count_1]=input[count_1][n];

         for(int count_2=(n-1);count_2>count_1;count_2--)
        input[count_1][count_2]=(input[count_1][count_2]*output[count_2]);

         for(int count_3=(n-1);count_3>count_1;count_3--)
        output[count_1]-=input[count_1][count_3];

         output[count_1]/=input[count_1][count_1];
      }
    }


 //-----------------------------  show_result( )  ------------------------//


 void show_result( )
    {
       clear_screen( );

       gotoxy(6,10);
       cout<<\"Solved System of Linear Equations :\";

       gotoxy(6,11);
       cout<<\"ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ\";

       show_input((n-1),n,-4);

       gotoxy(6,26);
       cout<<\"Result of Given System of Linear Equations :\";

       gotoxy(6,27);
       cout<<\"ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ\";

       for(int count=0;count<n;count++)
      {
         gotoxy(10,(29+count+count));
         cout<<\"x\"<<(count+1)<<\" = \"<<output[count];
      }

       if(Partial_pivoting==\'Y\' || Partial_pivoting==\'y\')
      {
         gotoxy(6,41);
         cout<<\"Note : The given System of Linear Equations is solved by using\";

         gotoxy(6,43);
         cout<<\"       Partial Pivoting.\";
      }

       gotoxy(1,2);
    }

    Related Post:
  1. Program to show the 3D Shearing Transformation along x-axis

  2. Program of Education System that maintains Institute Database using multilevel inheritance

  3. Program to fill a Circle using Scan-Line Circle Fill Algorithm using Polar Coordinates

  4. CREATING A CLASS ACCOUNTS FROM WHICH ARE DERIVED TWO CLASSES CURRENT AND SAVINGS AND THEN ASK THE USER FOR THE TYPE OF ACCOUNT HE WANTS TO CREATE

  5. Program to illustrate an example of structures

  6. Program to show the projection of 3D objects using Standard Perspective Projection w.r.t. an Arbitrary Plane and Center of Projection...

  7. Program to write macro that obtains the largest of three numbers

  8. Program to estimate the Differential value of the function using Euler Method

  9. Program to show the implementation of Cohen-Sutherland Line Clipping Algorithm

  10. Program that takes input of 2 matrix rows and columns data and displays addition of it using + operator overloading

  11. Program of class and objects using private and public data members

  12. Program to estimate the value of Fourth Derivative of the function at the given points from the given data using Central Difference Formula of order 2

  13. Program to fill different types of geometric shapes using Flood Fill Algorithm

  14. Program of Breadth First Search Traversal ( BFS )

  15. Program to estimate the value of First Derivative of the function at the given points from the given data using Central Difference Formula of order 4

  16. Program of class to class conversion

  17. Program of converting class type to basic variable of type string using conversion function

  18. Program of tower of hanoi

  19. Program to fill different types of geometric shapes using Flood Fill Algorithm (Using Linked-List)

  20. Program to perform radix sort