Demo entry 6686343

calculate

   

Submitted by anonymous on Dec 23, 2017 at 08:51
Language: C++. Code size: 1.6 kB.

#include<iostream>
#include<cstdio>
#include<cmath> 

using namespace std;
double a1, b1, a2, b2, c2, d2, e2,f2,a3, b3, t2, t3,M,m,m1,m2,L;
const double c01 = 389, c02 = 389, ci = 1800, c0 = 4180,T1=-18,delta=0.1;
double func1(double x)//É¢ÈÈÇúÏß  Ò»´ÎÄâºÏ 
{
	return a1*x + b1;
}

double func2(double x)//½µÎÂÇúÏß Îå´ÎÄâºÏ 
{
	return a2*pow(x, 5) + b2*pow(x, 4) + c2*pow(x, 3) + d2*x*x + e2*x+f2;
}

double func3(double x)//ÎüÈÈÇúÏß Ò»´ÎÄâºÏ
{
	return a3*x + b3;
}

double getS(double(*f)(double), double min, double max)//»ý·ÖÇóÃæ»ý
{
	double result = 0;
	for (double i = min; i <= max; i +=delta)
	{
		result += f(i)*delta;
	}
	return result;
}
int main()
{
	int n;
	cout << "ÊäÈë²âÊÔµÄÊý¾Ý×éÊý\n";
	cin >> n;
	while (n--)
	{
		cout << "·Ö±ðÊäÈëÈýÌõÇúÏߵIJÎÊý£ºa1,b1,a2,b2,c2,d2,e2,f2,a3,b3\nt2,t3\n±ùµÄÖÊÁ¿M£¬Ë®µÄÖÊÁ¿m£¬ÄÚͲµÄÖÊÁ¿m1£¬½Á°èÆ÷µÄÖÊÁ¿m2\n";
		cin >> a1 >> b1 >> a2 >>  b2 >> c2 >> d2 >> e2 >> f2 >> a3 >> b3 >> t2 >> t3 >> M >> m >> m1 >> m2;
		double dif = 1000, t = t2, T2, T3;
		for (double i = t2; i < t3; i+=delta) 
		{
			if (dif > fabs(fabs(getS(func1, t2, i) - getS(func2, t2, i)) - fabs(getS(func2, i, t3) - getS(func3, i, t3))))
			{
				dif = fabs(fabs(getS(func1, t2, i) - getS(func2, t2, i)) - fabs(getS(func2, i, t3) - getS(func3, i, t3)));
				t = i;
			}
		}//Çó³öÐÞÕýµã¶ÔÓ¦µÄʱ¼ät
		T2 = func1(t);//¼ÆËãT2¶ÔÓ¦µÄÐÞÕýζÈ
		T3 = func3(t);//¼ÆËãT3¶ÔÓ¦µÄÐÞÕýζÈ
		L = (c0*m + c01*m1 + c02*m2)*(T2 - T3) / M - c0*T3 + c01*T1;//¸ù¾Ý¹«Ê½¼ÆËãL
		printf("\nL£º%.3lfJ/Kg\n\n", L);
	}
	return 0;
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).