本文整理汇总了C++中Complex::get_a方法的典型用法代码示例。如果您正苦于以下问题:C++ Complex::get_a方法的具体用法?C++ Complex::get_a怎么用?C++ Complex::get_a使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Complex
的用法示例。
在下文中一共展示了Complex::get_a方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: multiply
Complex Complex::multiply(Complex comp2)
{
// Following formula (a + ib ) * ( c + id ) = ( a * c - b * d ) + i( a * d + b * c )
// Create Complex object called "temp"
Complex temp;
// Set temp data member "a" to (this->get_a() * comp2.get_a()) - (this->get_b() * comp2.get_b())
temp.set_a((this->get_a() * comp2.get_a()) - (this->get_b() * comp2.get_b()));
// Set temp data member "b" to ((this->get_a() * comp2.get_b()) + (this->get_b() * comp2.get_a()))
temp.set_b((this->get_a() * comp2.get_b()) + (this->get_b() * comp2.get_a()));
// Return resulting Complex object "temp"
return temp;
}
示例2: isEqual
bool Complex::isEqual(Complex comp2)
{
if (this->get_a() == comp2.get_a() && this->get_b() == comp2.get_b())
return true;
else
return false;
}
示例3: divide
Complex Complex::divide(Complex comp2)
{
/* Following formula
a + ib ( a * c + b * d ) i( c * b - a * d )
------ = ----------------- + -------------------
c + id c^2 + d^2 c^2 + d^2
*/
// Create Complex object called "temp"
Complex temp;
// Set temp data member "a" to ((a*c) + (b*d)) / (c^2 + d^2)
temp.set_a((this->get_a()*comp2.get_a() + this->get_b()*comp2.get_b()) / (comp2.get_a()*comp2.get_a() + comp2.get_b()*comp2.get_b()));
// Set temp data member "b" to ((c*b) - (a*d)) / (c^2 + d^2)
temp.set_b((comp2.get_a()*this->get_b() - this->get_a()*comp2.get_b()) / (comp2.get_a()*comp2.get_a() + comp2.get_b()*comp2.get_b()));
return temp;
}
示例4: subtract
Complex Complex::subtract(Complex comp2)
{
// Following formula ( a + ib ) - ( c + id ) = ( a - c ) + i( b - d )
// Create Complex object called "temp"
Complex temp;
// Set temp data member "a" to difference of local "a" and parameter comp2's "a"
temp.set_a((this->get_a()) - (comp2.get_a()));
// Set temp data member "b" to difference local "b" and parameter comp2's "b"
temp.set_b((this->get_b()) - (comp2.get_b()));
// Return resulting Complex object "temp"
return temp;
}
示例5: add
// function to add 2 complex numbers
Complex Complex::add(Complex comp2)
{
// Following formula ( a + ib ) + ( c + id ) = ( a + c ) + i( b + d )
// Create Complex object called "temp"
Complex temp;
// Set temp data member "a" to sum of local "a" and parameter comp2's "a"
temp.set_a((this->get_a()) + (comp2.get_a()));
// Set temp data member "b" to sum of local "b" and parameter comp2's "b"
temp.set_b((this->get_b()) + (comp2.get_b()));
// Return resulting Complex object "temp"
return temp;
}