problemscpp
A collection of my answers to algorithm problems in c++.
函数
pat::b::b1051 命名空间参考

1051 复数乘法 更多...

函数

int main (istream &cin, ostream &cout)
 
 TEST (b1051, case1)
 

详细描述

1051 复数乘法

函数说明

◆ main()

int pat::b::b1051::main ( istream &  cin,
ostream &  cout 
)

在文件 pat.cpp1701 行定义.

1701 {
1702 long double r1;
1703 long double p1;
1704 long double r2;
1705 long double p2;
1706 cin >> r1 >> p1 >> r2 >> p2;
1707 const long double a1 = r1 * cos(p1);
1708 const long double a2 = r2 * cos(p2);
1709 const long double b1 = r1 * sin(p1);
1710 const long double b2 = r2 * sin(p2);
1711 long double a = a1 * a2 - b1 * b2;
1712 long double b = a1 * b2 + a2 * b1;
1713 if(a < 0 && a + 0.005 >= 0) {
1714 a += 0.005;
1715 }
1716 if(b < 0 && b + 0.005 >= 0) {
1717 b += 0.005;
1718 }
1719 cout << fixed << setprecision(2) << a << fixed << setprecision(2) << showpos << b << 'i';
1720 return 0;
1721 }

被这些函数引用 TEST().

◆ TEST()

pat::b::b1051::TEST ( b1051  ,
case1   
)

在文件 pat_test.cpp775 行定义.

775 {
776 istringstream in("2.3 3.5 5.2 0.4");
777 auto out = ostringstream();
778 main(in, out);
779 const auto ans = out.str();
780 ASSERT_EQ("-8.68-8.23i", out.str());
781 }
int main(int argc, char **argv)
Definition: main.cpp:5

引用了 main().