请使程序完整, 并使程序的输出为: 2, 1 4, 3 请填空。 #include <iostream> using namespace std; class A { int a; public: A(int i = 0) { a = i; } int Geta() { return a; } }; class B { A a; int b; public: B(int i = 0, int j = 0): ______ { b = i; } void display() { cout << a.Geta() << ',' << b << endl; } }; int main() { B b[2] = { B(1, 2), B(3, 4) }; for (int i = 0; i < 2; i++) ___; } 空1空2 标 记上一题下一题
时间: 2024-04-05 11:33:23 浏览: 88
2014高级语言程序设计考卷A及参考答案-共9页.pdf
空1:a(i);空2:b[i].display(); 完整程序如下:
#include <iostream>
using namespace std;
class A {
int a;
public:
A(int i = 0) {
a = i;
}
int Geta() {
return a;
}
};
class B {
A a;
int b;
public:
B(int i = 0, int j = 0): a(i) {
b = j;
}
void display() {
cout << a.Geta() << ',' << b << endl;
}
};
int main() {
B b[2] = {
B(1, 2),
B(3, 4)
};
for (int i = 0; i < 2; i++)
b[i].display();
}
阅读全文