第三章-程序分析题-4

#include <iostream>
using namespace std;
class Location
{
public:
int x, y;
void init(int initx, int inity);
int Getx();
int Gety();
};
void Location::init(int initx, int inity)
{
x = initx;
y = inity;
}
int Location::Getx()
{
return x;
}
int Location::Gety()
{
return y;
}
void display(Location& rL)
{
cout << rL.Getx() << "" << rL.Gety() << endl;
}
int main()
{
Location A[5] = { {5,5},{3,3},{1,1},{2,2},{4,4} };
Location* rA = A;
A[3].init(7, 3);//数组如果没有设置[i]默认就是数组[0],init(n,m)是替换数组内的元素,例如A[3].init(7, 3)替换第三个值 因为数组下标是从0开始 第三个值实际上是第四个值
rA->init(7, 8);
for (int k = 0; k < 5; k++)display(*(rA++));
return 0;
}

第三章-程序分析题-4

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

给TA打赏
共{{data.count}}人
人已打赏
C++

第三章-程序分析题-3

2023-10-19 19:37:01

C++

P174-1 给出下列程序都输出结果

2023-10-21 15:37:04

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索