2

I have made a very simple kind of program in c++ language using code blocks in my Windows (10-64 bit) PC. This code was compiled by GCC compiler and an executable file of format *.exe is made. Now, I want to run that binary build or say executable file on my android device or in any other android device but, I find no way to directly do that. I have two apps in my android device that can help me in writing the code, compiling and running/testing it. First is CPPDroid and another is Decoder. I can use these applications to copy my code into one of them and compiling the code then running it but, this process appears to be very big and risky. In copying or opening the whole code in an editor is risky because I may unknowingly edit or modify the code due to the small touch screen of android devices.

I've already tried searching on the internet for the solutions to my problem but was unable to find one. Yeah, there are some answers that feature this problem and try to resolve them but, they were either very hard to understand or unhelpful. I am a newbie and I don't know much about working with android studio for making an app to do it.

This is my code:

#include<bits/stdc++.h>
#include<conio.h>
#define EPSILON 0.00001

using namespace std;

class Bisection
{
    int noofcaparr, *coeffarr, *powerarr, eqn;
    double var_x, result, var_a, var_b, var_c;
    char *eqnprnt;

    public:


        Bisection()
        {
            int noofcaparr = 0;
        }
        Bisection(const Bisection &obj)
        {
            this->noofcaparr = obj.noofcaparr;
            this->coeffarr = obj.coeffarr;
            this->powerarr = obj.powerarr;
            this->eqn = obj.eqn;
            this->var_x = obj.var_x;
            //this->result = obj.result;
            //this->var_a = obj.var_a;
            this->var_b = obj.var_b;
            this->var_c = obj.var_c;
            this->eqnprnt = obj.eqnprnt;
        }

        void geteqn();
        void showeqn();
        double setupeqn();
        void showresult();
        void getvariable();
        double roundoff(double &);
        Bisection bsmethodcomputn(Bisection &);

};

void Bisection::getvariable()
{
    this->var_a = 0;
    cout<<"\n\n\n\t ENTER THE VALUE OF VARIABLE:  ";
    cin>>this->var_a;
}

void Bisection::geteqn()
{
    int c, i, n;
    system("cls");
    cout<<"\n\n\t\t How many terms do you have in your equation? ";
    cout<<"\n\t For Example:  x^3 - 4x - 9 = 0   , has '3' terms     and ";
    cout<<"\n\t               x^4 + x^3 - 7x^2 - x + 5 = 0   , has '5' terms";
    cout<<"\n\t Enter the number of terms present in your equation:  ";
    cin>>this->noofcaparr;
    n = this->noofcaparr-1;

    this->coeffarr =  new int[n];
    this->powerarr = new int[n];

    for(i=0, c=1; i<=n; i++, c++ )
    {
        cout<<endl<<endl<<"\t\t Please enter the "<<c<<" th/st/nd/rd highest degree of x:  ";
        cin>>this->powerarr[i];

        cout<<endl<<endl<<"\t\t Please enter the coefficient of "<<c<<" th/st/nd/rd highest degree of x (with sign -/+):  ";
        cin>>this->coeffarr[i];
    }
/*    cout<<"\n\n\n\t\t Enter the value of x:  ";
    cin>>this->var_a; */
    cout<<endl<<endl<<"\n\n\t Values Set!";
    getch();


}


void Bisection::showeqn()
{
    int i, n;
    n = this->noofcaparr-1;
    system("cls");
    cout<<endl<<endl<<"\t\t Your equation is:   ";

        for(i=0; i<=n; i++ )
        {

            if(this->powerarr[i]==0)
            {
                if(i==0)
                {
                    if(this->coeffarr[i]>= 0)
                    {
                        if(this->coeffarr[i]==0)
                        {
                            cout<<" +0 ";
                        }

                        else
                        {
                            if(this->coeffarr[i]==1)
                            {
                                cout<<" 1";
                            }

                            else
                            {
                                cout<<" "<<(this->coeffarr[i])<<" ";
                            }
                        }
                    }
                    else
                    {
                        if(this->coeffarr[i]== -1)
                        {
                            cout<<" -"<<"1";
                        }
                        else
                        {
                            cout<<" "<<(this->coeffarr[i])<<" ";
                        }
                    }
                }
                else
                {
                    if(this->coeffarr[i]>= 0)
                    {
                        if(this->coeffarr[i]==0)
                            cout<<" +0 ";

                        else
                            cout<<" +"<<(this->coeffarr[i])<<" ";
                    }
                    else
                    {
                        cout<<" "<<(this->coeffarr[i])<<" ";
                    }
                }
            }

            else
            {
                if(this->powerarr[i]==1)
                {
                    if(i==0)
                    {
                        if(this->coeffarr[i]>= 0)
                        {
                            if(this->coeffarr[i]==0)
                            {
                                cout<<" +0 ";
                            }
                            else
                            {
                                if(this->coeffarr[i]==1)
                                {
                                    cout<<"x";
                                }
                                else
                                {
                                    cout<<" +"<<(this->coeffarr[i])<<"x";
                                }
                            }
                        }
                        else
                        {
                            if(this->coeffarr[i]== -1)
                            {
                                cout<<" -"<<"x ";
                            }
                            else
                            {
                                cout<<(this->coeffarr[i])<<"x";
                            }
                        }
                    }
                    else
                    {
                        if(this->coeffarr[i]>= 0)
                        {
                            cout<<"+"<<(this->coeffarr[i])<<"x";
                        }
                        else
                        {
                            cout<<(this->coeffarr[i])<<"x";
                        }
                    }
                }
                else
                {
                    if(i==0)
                    {
                        if(this->coeffarr[i]>= 0)
                        {
                            if(this->coeffarr[i]==1)
                            {
                                cout<<"x^"<<this->powerarr[i]<<"  ";
                            }
                            else
                            {
                                if(this->coeffarr[i]==0)
                                {
                                    cout<<" +0 ";
                                }
                                else
                                {
                                    cout<<" "<<(this->coeffarr[i])<<" "<<"x^"<<this->powerarr[i]<<"  ";
                                }
                            }

                        }
                        else
                        {
                            if(this->coeffarr[i]== -1)
                            {
                                cout<<" -"<<"x^"<<this->powerarr[i]<<"  ";
                            }
                            else
                            {
                                cout<<" "<<(this->coeffarr[i])<<" "<<"x^"<<this->powerarr[i]<<"  ";
                            }
                        }
                    }
                    else
                    {
                        if(this->coeffarr[i]>= 0)
                        {
                            cout<<" +"<<(this->coeffarr[i])<<" "<<"x^"<<this->powerarr[i]<<"  ";
                        }
                        else
                        {
                            cout<<" "<<(this->coeffarr[i])<<" "<<"x^"<<this->powerarr[i]<<"  ";
                        }
                    }
                }
            }
        }
    cout<<" = 0  = f(x) {let}";
}

double Bisection::setupeqn()
{
    this->result = 0;
    double rslt, rndoff_res;
    rslt = this->result;
    int n = this->noofcaparr - 1;
    for (int i=0; i <= n; i++)
    {
        double pwr, cfr;
        double x;
        x = this->var_a;
        pwr= this->powerarr[i];
        cfr = this->coeffarr[i];
        rslt += (pow(x,pwr)*cfr);
        rndoff_res = this->roundoff(rslt);
        rslt = rndoff_res;
        //cout<<endl<<endl<<endl<<"\t Value of var_a: "<<x;
        //cout<<endl<<endl<<endl<<"\t Value of powerarr: "<<pwr;
        //cout<<endl<<endl<<endl<<"\t Value of coeffarr: "<<cfr;
        //cout<<"\n\n\t result +=  (pow(this->var_a, this->powerarr[i])* this->coeffarr[i]) = "<<rslt;
        this->result= rslt;
    }


    //cout<<endl<<endl<<endl<<"\t Value of result: "<<rslt;
    return (this->result);
}

void Bisection::showresult()
{

    cout<<endl<<endl<<"\t\t This is your result:  "<<this->result;

}

double Bisection::roundoff(double &res)
{
    // 37.66666 * 100 =3766.66
    // 3766.66 + .5 =37.6716    for rounding off value
    // then type cast to int so value is 3766
    // then divided by 100 so the value converted into 37.66
    ///double round_off_result = (int)(res * 100000 + .5);
    ///return (double)round_off_result / 100000;
    double round_off_result = res;
    setprecision(4);
    return round_off_result;
}

Bisection Bisection::bsmethodcomputn(Bisection &obj)
{
    double temp_c;
    Bisection obj2 = *this;

    cout<<"\n\n\t First value is = "<<this->result<<"\t\t Second value is = "<<obj.result;
    cout<<endl<<endl<<endl;
    //void bisection(double a, double b)

        if (this->result * obj.result >= 0)
        {

            cout << "\t \t You have not assumed right a and b\n";

            cout<<"\n\n\t First value is = "<<this->var_a<<"\t\t Second value is = "<<obj.var_a;
            //return;
        }



        else
        {

            cout<<"\n\n\t First value is = "<<this->var_a<<"\t\t Second value is = "<<obj.var_a;
            double a = this->var_a;
            double b = obj.var_a;
            //Bisection obj2 = *this ;

            obj2.var_a = a;
            obj2.setupeqn();
            double c = obj2.var_a;
            int counter = 1;

            while ((b-a) >= EPSILON)
            {
                // Find middle point
                temp_c = c;
                c = (a+b)/2;
                //c = obj2.roundoff(c);
                obj2.var_a = c;

                cout<<endl<<endl<<endl<<"\n\t\t\t\t "<<counter<<").";
                cout<<endl<<endl<<endl<<"\t Value of c: "<<obj2.var_a;


                obj2.setupeqn();

                cout<<endl<<endl<<endl<<"\t Value of result:  "<<obj2.result;

                // Check if middle point is root
                if (obj2.result == 0.0001)
                    break;

                else
                {
                    if(temp_c==c)
                        break;
                // Decide the side to repeat the steps
                    else
                    {
                        if (obj2.result* this->result < 0)
                        {
                            b = c;
                        }
                        else
                            a = c;
                    }
                }

                counter++;
            }

            cout << "\n\n\n\n\t\t\t\t *** The value of root is : " << c<<" ***"<<endl<<endl<<endl;
            getch();

        }

}

int main()
{
    Bisection a;

    a.geteqn();
    a.showeqn();

    char choice;

    do
    {
    a.getvariable();
    a.setupeqn();
    a.showresult();
    Bisection b = a;
    b.getvariable();
    b.setupeqn();
    b.showresult();

    a.bsmethodcomputn(b);

    cout<<"\n\n\n\t Do you want to continue? (Y/N)";
    cin>>choice;
    }while(choice=='Y'||choice=='y');
    getch();
    return(0);
}

I have the windows executable of this program but I don't know how to directly run this program on an android device.

I actually created this program to share with my classmates so that they can check their solution that whether it is correct or not. They are not programmers, they do not know how to write, compile or run a program. So, they cannot do the cppdroid or decoder procedure. I also don't want to give them my code. But, I want to share this program with them so that they can successfully use it. Now I am unable to understand how to achieve it. This program is very simple it takes some input and after calculations, it gives the required output, that's it. It is not very complex program. I hope that there will be any working way to get this thing done.

No Name
  • 41
  • 3

1 Answers1

4

EXE is a Windows executable. Executable files are binaries tied to the OS and are not compatible between OSes. You need to build for ARM (or ARM64), and even so, console apps in Android are not easily installed or run because they require shell access. If you are giving this to someone, forget completely that they will be able to run it in a shell (or perhaps you thought that it will automatically rendered as GUI app, which is not the case).

If you are interested in Android, you should get a good Android book and learn more on the available APIs etc.

Android, iOS, Linux, Windows are way different ecosystems and programming between them has significant differences.

Development in Android or iOS is not done in these devices inline, you want proper IDEs. For Windows, there 's Android Studio. For iOS, you need a Mac and Xcode.

In short, you are currently very far from reaching what one tries to reach with lots of reading, learning curve, investments and debugging.

Get a good C++ book (judging from the bits/stdc++ include and the using namespace std your current book is not good), then start learning APIs on Android, Windows, iOS, etc along with the languages that they require to function (Java, Objective-C, Swift, Kotlin, [...]). It will take years, but there is no point in fooling yourself like most bad books attempt to.

Michael Chourdakis
  • 10,345
  • 3
  • 42
  • 78