Pages

Subscribe:

About Template

Random Posts

C++ Program that Converts Arabic Numerals to Roman Numerals


Name: Arabic to Roman Numerals Converter
Roman Numeral Examples: I,V,X,C,D,M
Arabic Numeral Examples: 0,1,2,3,4,5,6,7,8,9
Description: This program converts Arabic Numerals into Roman Numerals. 
As you can see in the screenshot below, you can enter any Arabic number you want. I entered number 99,999,3456, then, it displayed their corresponding Roman Numeral Format.
 



//Below are the Codes of the Program:
#include <iostream.h>
#include <string.h>
#include <math.h>


int main()
{
    char ans, ch;


       cout<< " [1] Conversion of Arabic Number to Roman Number Format\n";
   do
   {


   cout<< " Let's test your keyboard. Type this number [1]: ";
   cin>> ch;


   if(ch=='1')
   {
        int yr, m, cm, d, c, xc, l, x, ix, v, i;


        cout<< " Enter any ARABIC NUMBER you want: ";
      cin>> yr;
       cout<<"\n In Roman Numeral Format:  ";
       for(m = 1000;yr >= m; yr -= 1000)
           {cout<<"M";}
      for(cm = 900; yr >= cm; yr -= 900)
          {cout<< "CM";}
       for(d = 500;yr >= d; yr -= 500)
           {cout<<"D";}
       if(yr >= 400){ cout<<"CD"; yr -= 400; }
       else {
               for(c = 100;yr >= c; yr -= 100)
                   {cout<<"C";}
           }
      for(xc = 90; yr >= xc; yr -= 90)
          {cout<< "XC";}
       for(l = 50;yr >= l; yr -= 50)
           {cout<<"L";}
       if(yr >= 40){ cout<<"XL"; yr -= 40; }
       else {
                for(x = 10;yr >= x; yr -= 10)
                   {cout<<"X";}
           }
      for(ix = 9; yr >= ix; yr -= 9)
          {cout<< "IX";}
       for(v = 5;yr >= v; yr -= 5)
           {cout<<"V";}
       if(yr >= 4){ cout<<"IV"; yr -= 4; }
       else {
                for(i = 1;yr >= i; yr -= 1)
                   {cout<<"I";}
            }


         }
         else
       {
       cout<< " Invalid input number!\n";
      cout<< endl;
       }


      cout<< "\n\n Try Again?[y/n]: ";
      cin>> ans;
    }while(ans=='y'||ans=='Y');
    cout<< " Thank You!\n";


   cin.get();
   cin.get();


   return 0;


}
Continue Reading...


C++ Program of The Cramer's Rule


Name: Cramer's Rule
Cramer's rule is a theorem, which gives an expression for the solution of a system of linear equations with as many equations as unknowns, valid in those cases where there is a unique solution. The solution is expressed in terms of the determinants of the (square) coefficient matrix and of matrices obtained from it by replacing one column by the vector of right hand sides of the equations. 
Description of the Program: This program computes the determinant and shows the result of the 3 unknown variables using  Cramer's Rule.

As you can see in the screenshot below, I entered just the example equations. First equation is (3X)^3+(4X)^2+5X=6, second is (2X)^3+(7X)^2+5X=3, and the last equation (X)^3+(3X)^2+4X=2
After entering all the coefficients of the equation in the screenshot above, it displayed the determinant of the three equations which is 22. Then, the individual determinants, 45,-7, and 5 after substituting the number on the right side of the equality in their corresponding column. Lastly, it displayed the result of the three unknown variables,X1,X2,and X3. 


//Below are Codes of the Program:

#include<iostream.h>
void input(int array[][3], int array1[][1]);
int determinent(int array[][3]);
int calculate(int array[][3], int a, int b, int c);
int copy(int array[][3], int array1[][1], int a);
void comp_copy(int array[][3], int array1[][3]);
int main()
{
    cout<<"Enter a 3 by 3 matrix from a given system. First, enter the 1st row, then,\n";
   cout<<"\nthe first entry on the right side of the equality.  \n\n";
    cout<<"Provide a space for each number. \n";
   cout<<"\nLike this:\n\n";
    cout<<"  3  4  5    6 -> 6 is the number on the right side of the equality\n";
    cout<<"  2  7  5    3 \n";
    cout<<"  1  3  4    2 \n";
    bool sahi=true;
    while(sahi)
    {
        cout<<"Enter now...\n";
        int matrix[3][3];
        int matrix1[3][1];
        int reserve[3][3];
        int det00, detr[3], sp1=0,cont=0, teen=1;
        char in;
        input(matrix, matrix1);
        comp_copy(reserve, matrix);
        det00=determinent(matrix);
        while(sp1<3)
        {
            detr[cont]=copy(matrix, matrix1, sp1);
            comp_copy(matrix,reserve);
            cont++;
            sp1++;
        }
        cont=0;
        while(cont<3)
        {
            cout<<"x"<<teen<<" = "<<  detr[cont]<<" /"<<det00<<endl;
            cont++;
            teen++;
        }
        cout<<"If you want to exit press n else press any key\n";
        cin>>in;
        if(in=='n' || in=='N')
            return 1;
    }
    return 0;
}
void input(int array[][3], int array1[][1])
{
    int rows=0, col=0, x=0;
    while(rows<3)
    {
        col=0;
        while(col<3)
        {
            cin>>array[rows][col];
            col++;
        }
        cin>>array1[x][0];
        x++;
        rows++;
    }
}
int determinent(int array[][3])
{
    int rows=1, col=1;
    int z=0;
         int temp=0;
         int cont=1;
         int x=0;
         while(x<3)
         {
             temp=temp+cont*(array[0][x]*calculate(array,rows, col, z));
             col=col*0;
             z=z+cont;
             cont=cont*-1;
             x++;
         }
    cout<<"\nDeterminant of the matrix above is "<<temp<<"\n\n";
    return temp;
}
int calculate(int array[][3], int a, int b, int c)
{
    int temp1;
    temp1=(array[a][b]*array[a+1][b+1+c])-(array[a+1][b]*array[a][b+1+c]);
    return temp1;
}
int copy(int array[][3], int array1[][1], int a)
{
    int col=0;
    int temp;
    while(col<3)
    {
        array[col][a]=array1[col][0];
        col++;
    }
    int i=0, j=0;
    while(i<3)
    {
        j=0;
        while(j<3)
        {
            cout<<array[i][j]<<"  ";
            j++;
        }
        cout<<endl;
        i++;
    }
    temp=determinent(array);
    return temp;
}
void comp_copy(int array[][3], int array1[][3])
{
    int rows=0, col=0;
    while(rows<3)
    {
        col=0;
        while(col<3)
        {
            array[rows][col]=array1[rows][col];
            col++;
        }
        rows++;
    }
}

Continue Reading...