Qt复习提纲 联系客服

发布时间 : 星期五 文章Qt复习提纲更新完毕开始阅读7742e721192e45361066f56c

void SetPositionY(int iPositionY) {

m_iPositionY = iPositionY; } private:

int m_iPositionX; // X坐标 int m_iPositionY; // Y坐标 };

int main(void) {

CPosition oPostion1;

const CPosition oPostion2(6, 8);

cout << oPostion1.GetPositionX() << endl; oPostion1.SetPositionX(16);

cout << oPostion1.GetPositionX() << endl; oPostion1.SetPositionY(18);

cout << oPostion1.GetPositionY() << endl; cout << oPostion2.GetPositionX() << endl; cout << oPostion2.GetPositionY() << endl; return 0; }

上面程序的输出结果为: 参考答案: 0 16 18 6 8

2.阅读下面程序,写出输出结果。 #include using namespace std; template class CTest {

public:

CTest(Type m_tArray[], int iSize):m_pArray(m_tArray) {

m_iSize = iSize; }

void Print() const {

for (int i = 0; i < m_iSize; i++)

{

cout << m_pArray[i] << \ } } private:

Type *m_pArray; int m_iSize; };

int main(void) {

int a[] = {1, 0, 8};

double b[] = {1.6, 1.8}; CTest oTest1(a, 3); oTest1.Print();

CTest oTest2(b, sizeof(b) / sizeof(double)); oTest2.Print(); cout << endl; return 0; }

上面程序的输出结果为:

参考答案:1 0 8 1.6 1.8

3.阅读下面程序,写出输出结果。 #include using namespace std; class CGoods {

public:

CGoods(int iWeight) {

m_iWeight = iWeight;

m_iTotalWeight = m_iTotalWeight + iWeight; }

CGoods(const CGoods &oGood) {

m_iWeight = oGood.m_iWeight;

m_iTotalWeight = m_iTotalWeight + m_iWeight; }

~CGoods() {

m_iTotalWeight = m_iTotalWeight - m_iWeight; }

void Print() const;

static int GetTotalWeight() {

return m_iTotalWeight; } private:

int m_iWeight;

static int m_iTotalWeight; };

int CGoods::m_iTotalWeight = 8; // 初始化静态数据成员 void CGoods::Print() const {

cout << this->m_iWeight << \}

int main(void) {

CGoods oGood1(6);

oGood1.Print(); CGoods oGood2(oGood1); oGood2.Print();

cout << CGoods::GetTotalWeight(); cout << endl; return 0; }

上面程序的输出结果为:

参考答案:6 14 6 20 20