第一题:
#include <iostream>
using namespace std;
class Complex
{
private:
int a;
int b;
public:
Complex()
{
a = b = 0;
}
Complex(int aa, int bb)
{
a = aa;
b = bb;
}
void setAB(int aa, int bb)
{
a = aa;
b = bb;
}
void display()
{
if (b == 0)
{
cout << a << endl;
}
else if (b > 0)
{
cout << a << " + " << b << "i" << endl;
}
else
{
cout << a << " - " << (-b) << "i" << endl;
}
}
};
第二题:
#include <iostream>
using namespace std;
int main()
{
freopen("indata.txt", "r", stdin);
int num, sum = 0, cnt = 0;
while (~scanf("%d", &num))
{
sum += num;
++cnt;
}
freopen("outdata.txt", "w", stdout);
printf("%lf\n", sum * 1.0 / cnt);
return 0;
}
第三题:
#include <iostream>
using namespace std;
int main()
{
freopen("indata.txt", "r", stdin);
int num, sum = 0;
while (~scanf("%d", &num))
{
sum += num;
}
freopen("outdata.txt", "w", stdout);
printf("%d\n", sum);
return 0;
}
温馨提示:答案为网友推荐,仅供参考