『代码』··By/蜜汁炒酸奶

负数计算-C++

/*
功能:负数计算类 V1.0
作者:wind
日期:2013-10-11
*/

#include <iostream>
#include <string>
using namespace std;
class Complex
{
public:
	Complex(double aX,double aY);
	~Complex();
	void setX(double aX);
	void setY(double aY);
	void Count(Complex other);
private:
	double m_aX;
	double m_aY;
};
Complex :: Complex(double aX =0,double aY=0):
m_aX(aX),m_aY(aY){};
Complex ::~Complex()
{

}
void Complex::setX(double aX)
{
	m_aX = aX;
}
void Complex::setY(double aY)
{
	m_aY = aY;
}
void Complex::Count(Complex other)
{
	string choice;
	cout<<"Please input sign(+/-):";
	cin >> choice;

	double addresultX = m_aX + other.m_aX;
	double addresultY = m_aY + other.m_aY;
	double subtractresultX = m_aX - other.m_aX;
	double subtractresultY = m_aY - other.m_aY;
	cout <<"The result is:";
	if (choice =="+")
	{
         cout <<"("<<addresultX<<","<<addresultY<<")"<<endl;
	}
	else if(choice == "-")
	{
         cout <<"("<<subtractresultX<<","<<subtractresultY<<")"<<endl;
	}


}
int main(void)
{
	Complex P1,P2;
	double p1x,p1y,p2x,p2y;

	cout<<"Please input first complex number(实部,虚部):";
	cin>>p1x>>p1y;
	P1.setX(p1x);
	P1.setY(p1y);

	cout<<"Please input second complex number(实部,虚部):";
	cin>>p2x>>p2y;
	P2.setX(p2x);
	P2.setY(p2y);

	P1.Count(P2);
	system("pause");
	return 0;

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

预览
Loading comments...
2 条评论
  • W

    额,太复杂了- -,一看到代码就头疼怎么解- -。

example
预览