#include <bits/stdc++.h>
#define Pi 3.1415926 //定义圆周率的取值
#define DENSITY 981 //油滴的密度
#define b (6.17e-6) //粘滞系数修正常数
#define g 9.8 //重力加速度
#define d 5e-3 //极板间距离
#define p 76 //大气压强
#define e 1.603e-19 //元电荷
#define ETA (1.83e-5) //粘滞系数
using namespace std;
class Data
{
private:
double voltage;
double av_time;
double Total_charge;
double av_charge;
int NumOfcharges;
public:
Data()
{
voltage = av_time = Total_charge = av_charge = NumOfcharges = 0;
}
void input(int I)
{
cout<<"第"<<I<<"组实验数据"<<endl;
cout<<"请输入所测电压值U/v:"<<endl;
cin>>voltage;
cout<<"请输入所测时间数据t/s(第1~6次并以空格隔开):"<<endl;
double time = 0;
double total_times = 0;
for(int i = 0;i < 6; i++)
{
cin>>time;
total_times += time;
}
av_time = total_times/6;
cout<<"平均时间:T = "<<setprecision(1)<<fixed<<av_time<<"s"<<endl;
}
void compute()
{
Total_charge = (1.43e-14)/( voltage*pow((av_time*(1+0.02*sqrt(av_time))),1.5));
NumOfcharges = Total_charge/1.602e-19;
av_charge = Total_charge/NumOfcharges;
}
void compute(double L)
{
L *= 0.001;
Total_charge = ((18*Pi*d)/(voltage*sqrt(2*DENSITY*g)))*pow((ETA*L)/(av_time*(1+(b/(p*(sqrt((9*ETA*L)/(2*DENSITY*g*av_time))))))),1.5);
NumOfcharges = Total_charge/1.602e-19;
av_charge = Total_charge/NumOfcharges;
}
double get()
{
printf(" %e %02d %e\n",Total_charge,NumOfcharges,av_charge);
}
void show()
{
printf("总电荷值:%eC\n电子数:%d\n电子平均电荷值:%eC\n\n",Total_charge,NumOfcharges,av_charge);
}
};
int main()
{
cout<<"Welcome To Robert Millikan's Sweet Lab."<<endl;
cout<<"———————————————————"<<endl;
cout<<"请输入你需要计算的数据组数:"<<endl;
int N;
cin>>N;
cout<<"请确认油滴匀速上升或下降的距离: \nL = 2mm ? (Y/N)"<<endl;
char C;
cin>>C;
double L;
if(C!='Y')
{
cout<<"请输入油滴匀速上升或下降的距离 L/mm:"<<endl;
cin>>L;
}
cout<<"取电子电荷的公认值:e = 1.602e-19 C(即1.602*10^-19C).\n"<<endl;
vector<Data> Datas;
vector<Data>::iterator iter;
for(int I = 1;I <= N; I++)
{
Data data;
data.input(I);
if(C!='Y') data.compute(L);
else data.compute();
data.show();
Datas.push_back(data);
}
cout<<"————————————————————————————"<<endl;
cout<<"数据处理与实验结果:"<<endl;
cout<<"油滴编号 q/(e-19C) n e/(e-19C)"<<endl;
int J = 1;
for(iter = Datas.begin(); iter < Datas.end(); iter++)
{
cout<<" "<<J;
J++;
iter->get();
}
cout<<"————————————————————————————"<<endl;
cout<<"Andrews Millikan: Well,It's so cool!"<<endl;
printf("Press any key to continue...");
getchar();
getchar();
return 0;
}
——————————————————————————————————————————————————————
Sample1:
3
Y
50
23.9 23.6 23.0 23.1 23.7 23.8
106
12.3 12.5 12.3 12.2 12.2 12.8
135
8.6 8.6 8.5 8.5 8.9 8.6
——————————————————————————————————————————————————————
Sample2:
3
N
1.5
50
23.9 23.6 23.0 23.1 23.7 23.8
106
12.3 12.5 12.3 12.2 12.2 12.8
135
#define Pi 3.1415926 //定义圆周率的取值
#define DENSITY 981 //油滴的密度
#define b (6.17e-6) //粘滞系数修正常数
#define g 9.8 //重力加速度
#define d 5e-3 //极板间距离
#define p 76 //大气压强
#define e 1.603e-19 //元电荷
#define ETA (1.83e-5) //粘滞系数
using namespace std;
class Data
{
private:
double voltage;
double av_time;
double Total_charge;
double av_charge;
int NumOfcharges;
public:
Data()
{
voltage = av_time = Total_charge = av_charge = NumOfcharges = 0;
}
void input(int I)
{
cout<<"第"<<I<<"组实验数据"<<endl;
cout<<"请输入所测电压值U/v:"<<endl;
cin>>voltage;
cout<<"请输入所测时间数据t/s(第1~6次并以空格隔开):"<<endl;
double time = 0;
double total_times = 0;
for(int i = 0;i < 6; i++)
{
cin>>time;
total_times += time;
}
av_time = total_times/6;
cout<<"平均时间:T = "<<setprecision(1)<<fixed<<av_time<<"s"<<endl;
}
void compute()
{
Total_charge = (1.43e-14)/( voltage*pow((av_time*(1+0.02*sqrt(av_time))),1.5));
NumOfcharges = Total_charge/1.602e-19;
av_charge = Total_charge/NumOfcharges;
}
void compute(double L)
{
L *= 0.001;
Total_charge = ((18*Pi*d)/(voltage*sqrt(2*DENSITY*g)))*pow((ETA*L)/(av_time*(1+(b/(p*(sqrt((9*ETA*L)/(2*DENSITY*g*av_time))))))),1.5);
NumOfcharges = Total_charge/1.602e-19;
av_charge = Total_charge/NumOfcharges;
}
double get()
{
printf(" %e %02d %e\n",Total_charge,NumOfcharges,av_charge);
}
void show()
{
printf("总电荷值:%eC\n电子数:%d\n电子平均电荷值:%eC\n\n",Total_charge,NumOfcharges,av_charge);
}
};
int main()
{
cout<<"Welcome To Robert Millikan's Sweet Lab."<<endl;
cout<<"———————————————————"<<endl;
cout<<"请输入你需要计算的数据组数:"<<endl;
int N;
cin>>N;
cout<<"请确认油滴匀速上升或下降的距离: \nL = 2mm ? (Y/N)"<<endl;
char C;
cin>>C;
double L;
if(C!='Y')
{
cout<<"请输入油滴匀速上升或下降的距离 L/mm:"<<endl;
cin>>L;
}
cout<<"取电子电荷的公认值:e = 1.602e-19 C(即1.602*10^-19C).\n"<<endl;
vector<Data> Datas;
vector<Data>::iterator iter;
for(int I = 1;I <= N; I++)
{
Data data;
data.input(I);
if(C!='Y') data.compute(L);
else data.compute();
data.show();
Datas.push_back(data);
}
cout<<"————————————————————————————"<<endl;
cout<<"数据处理与实验结果:"<<endl;
cout<<"油滴编号 q/(e-19C) n e/(e-19C)"<<endl;
int J = 1;
for(iter = Datas.begin(); iter < Datas.end(); iter++)
{
cout<<" "<<J;
J++;
iter->get();
}
cout<<"————————————————————————————"<<endl;
cout<<"Andrews Millikan: Well,It's so cool!"<<endl;
printf("Press any key to continue...");
getchar();
getchar();
return 0;
}
——————————————————————————————————————————————————————
Sample1:
3
Y
50
23.9 23.6 23.0 23.1 23.7 23.8
106
12.3 12.5 12.3 12.2 12.2 12.8
135
8.6 8.6 8.5 8.5 8.9 8.6
——————————————————————————————————————————————————————
Sample2:
3
N
1.5
50
23.9 23.6 23.0 23.1 23.7 23.8
106
12.3 12.5 12.3 12.2 12.2 12.8
135
8.6 8.6 8.5 8.5 8.9 8.6