静态法:
#include <iostream>
#include <cmath>
using namespace std;
int main(){
double q, t, r, u, x, x1, x2,n1,e1,e0=1.602;
double p1 = 981,g = 9.80,l = 2.00e-3,b = 8.23e-3,p = 0.101e6,d = 5.00e-3,n = 1.83e-5;
cout<<"先输入时间,再输入电压:"<<endl;
cin>>t>>u;
r = sqrt(9 * n*l / (2 * p1*g*t));
x1 = ((n*l) / (t*(1 + b / (p*r))));
x2 = x1*x1*x1;
x = sqrt(x2);
q = 18 * 3.14*x*d / (sqrt(2 * p1*g)*u);
n1=q/(1.6e-19);
if(n1-int(n1)>=0.5) n1=int(n1)+1;
else if(n1-int(n1)<0.5||n1-int(n1)>=0) n1=int(n1);
else cout<<"error";
e1=q/n1;
cout<<"油滴所带电量q="<<q<<endl;
cout<<"实验数据所得电荷量e="<<e1<<endl;
cout<<"基本电荷相对误差结果u="<<abs(100*(e1*1e19-e0)/e0)<<"%"<<endl;
system("pause");
return 0;
}
动态法:
#include <iostream>
#include <cmath>
using namespace std;
int main(){
double q, r, u, x ,n1,e1,w,tg,te;
double p1 = 981,g = 9.794,l = 2.00e-3,b = 8.22e-3,P = 0.1013e6,d = 5.00e-3,n = 1.83e-5,c=1.602e-19;
cout<<"先输入下降时间,再输入上升时间,再输入上升时的电压(注意不是平衡电压,是平衡电压的1.5倍):"<<endl;
cin >> tg>>te>>u;
r = sqrt(9 * n*l / (2 * p1*g*tg));
x=sqrt((n*l)/(1+b/(P*r)));
q = ((18*3.14)/sqrt(2*p1*g))*x*x*x*(d/u)*(1/tg+1/te)*sqrt(1/tg);
n1=q/(1.602e-19);
if(n1-int(n1)>=0.5) n1=int(n1)+1;
else if(n1-int(n1)<0.5||n1-int(n1)>=0) n1=int(n1);
else cout<<"error";
e1=q/n1;
w=(e1-c)/c;
if(w<0) w=0-w;
else w=w;
cout<<"油滴带电量q= "<<q<<endl;
cout<<"基本电荷带电量e= "<<e1<<endl;
cout<<"相对误差= "<<w*100<<"%"<<endl;
system("pause");
return 0;
}