// integral_function
//arb2014_integral_function_without_file
#include<iostream>
#include<math.h>
#include<iomanip>
#include<string>
using namespace std;
const int lengthColumn=20;
const int Indent=7;
const int lengthTable=43;
//////////////////////////
double Fi(double x)
{
return cos(x)*cos(x);
}
///////////////////////////////
double Psi(double x)
{
return (1-x*x)/(1+x*x);
}
/////////////////////////
double F(double x,double t)
{
return Psi(x)*Fi(x+ t/(1+x*x));
}
///////////////////////////////////////
void create(double* x, int n)
{
int i;
for(i=0;i<n;i++)
{
cout<<"x["<<i<<"]=";
cin>>x[i];
}
}
/////////////////////////////////////////
void show(double* x, int n)
{
int i;
for(i=0;i<n;i++)
cout<<x[i]<<' ';
cout<<endl;
}
/////////////////////////////////////////
double Integral(double a, double b, double e, double t)
{
double h,J1,J2;
int i,n;
n=1;
h=(b-a)/n;
J2=h*F(a+h/2, t);
do
{
J1=J2;
n=n*2;
h=(b-a)/n;
J2=0;
for (i=0;i<=n-1;i++)
J2=J2+F(a+(2*i+1)*h/2,t);
J2=J2*h;
}while (fabs(J2-J1)>e);
return J2;
}
//////////////////////////////////////
void star(int n, int m)
{
cout.width(n);
int i;
for(i=0;i<m;i++)
cout<<'*';
cout<<endl;
}
/////////////////////////////////////
void star1(int n, int m)
{
cout.width(n); cout<<'*';
int i;
for(i=0;i<m;i++)
{
cout.width(lengthColumn+1);
cout<<'*';
}
cout<<endl;
}
//////////////////////////////////////
void table(double* x,double* y,int m, char a[2][15])
{
int i;
cout<<endl;
star(Indent+1,lengthTable);
star1(Indent+1,2);
cout.width(Indent+1);
cout<<'*';
for(i=0;i<2;i++)
{
cout.width(10);
cout<<a[i];
cout.width(11);
cout<<'*';
}
cout<<endl;
star1(Indent+1,2);
star(Indent+1,lengthTable);
for(i=0;i<m;i++)
{
cout.width(Indent+1);
cout<<'*';
cout.width(lengthColumn-5);
cout<<x[i];
cout.width(6);
cout<<'*';
cout.width(lengthColumn-5);
cout<<y[i];
cout.width(6);
cout<<'*';
cout<<endl;
star1(Indent+1,2);
star(Indent+1,lengthTable);
}
}
/////////////////////////////
void main()
{
double a,b,eps;
int m,i;
char name_task[80];
char name_x_y[2][15]; // x[i] y[i]
cout<<" enter the name of the table"<<endl;
cin.getline(name_task,80);//
for(i=0;i<2;i++)
{
cout<<" x[i] y[i] ";
cin>>name_x_y[i];// x[i] y[i]
}
cout<<endl;
cout<<name_task<<endl;
for(i=0;i<2;i++)
cout<<name_x_y[i]<<' ';
cout<<endl;
cout<<" a= "; cin>>a;
cout<<" b= "; cin>>b;
cout<<" eps= "; cin>>eps;
|
|
cout<<" m= "; cin>>m;
double* t, *y;
t=new double[m];
y=new double[m];
create(t,m);
cout<<"arguments: "<<endl;
show(t,m);
for(i=0;i<m;i++)
y[i]=Integral(a,b,eps,t[i]);
cout<<"value of integeral"<<endl;
show(y,m);
cout<<endl;
cout<<setw(15+strlen(name_task))<<name_task<<endl;
table(t,y,m,name_x_y);
delete []t;
delete []y;
}
////////////////////////////////////////
- .
, ++- . , . - ios, - , .
- ios
- ++ . ios fntflags,
adjustfield
basefield
boolalpfa
dec
fixed
floatfield
hex
internal
left
oct
right
scientific
showbase
showpoint
showpos
skipws
unitbuf
upprecase
.
skipws , , (.. , ), .
..
setf(), ios.
10
. ( ) , , (\0). , -. ++ - .
++.
string, ++. , string .