我使用Windows(10-64位)PC中的代码块用c ++语言编写了一种非常简单的程序。该代码由GCC编译器编译,并生成了* .exe格式的可执行文件。现在,我想在我的android设备或任何其他android设备上运行该二进制版本或说可执行文件,但是,我找不到直接执行此操作的方法。 我的Android设备中有两个应用程序,可以帮助我编写代码,编译和运行/测试它。第一个是 CPPDroid ,另一个是 Decoder 。我可以使用这些应用程序将我的代码复制到其中一个程序中,然后编译代码然后运行它,但是此过程似乎非常大且冒险。在编辑器中复制或打开整个代码是有风险的,因为由于Android设备的触摸屏较小,我可能会在不知不觉中编辑或修改代码。
我已经尝试在Internet上搜索解决我的问题的方法,但是找不到。是的,有一些答案可以解决此问题,并尝试解决这些问题,但是它们要么很难理解,要么无益。我是新手,对使用android studio制作应用程序了解得不多。
这是我的代码:
#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);
}
我有该程序的Windows可执行文件,但我不知道如何在Android设备上直接运行该程序。
我实际上创建了此程序以与同学共享,以便他们可以检查自己的解决方案是否正确。他们不是程序员,他们不知道如何编写,编译或运行程序。因此,他们无法执行 cppdroid 或 decoder 过程。我也不想给他们我的代码。 但是,我想与他们共享此程序,以便他们可以成功使用它。现在我无法理解如何实现它。该程序非常简单,它需要一些输入,经过计算后,它会提供所需的输出,仅此而已。它不是很复杂的程序。我希望会有任何可行的方法来完成此任务。
答案 0 :(得分:1)
EXE是Windows可执行文件。可执行文件是与操作系统绑定的二进制文件,并且在操作系统之间不兼容。您需要针对ARM(或ARM64)进行构建,即使如此,Android中的控制台应用程序也需要外壳程序访问,因此不容易安装或运行。如果您将此内容提供给某人,请完全忘记他们可以在外壳程序中运行它(或者您可能认为它会自动呈现为GUI应用程序,并非如此)。
如果您对Android感兴趣,则应该获得一本不错的Android书,并详细了解可用的API等。
Android,iOS,Linux,Windows是不同的生态系统,它们之间的编程存在显着差异。
在这些设备中,未在这些设备中进行Android或iOS上的开发,您需要适当的IDE。对于Windows,有Android Studio。对于iOS,您需要Mac和Xcode。
简而言之,通过大量的阅读,学习,投资和调试,您目前还远没有达到一个人想要达到的目标。
获取good C++ book(从您目前所著的bits/stdc++
包含和using namespace std
来看),然后开始在Android,Windows,iOS等系统上学习API他们需要功能的语言(Java,Objective-C,Swift,Kotlin等)。这将需要几年,但是像大多数坏书一样,自欺欺人是没有意义的。