point类包含xy写出其构造函数,并在构造函数中输出(x,y)的坐标
时间: 2023-05-20 11:07:06 浏览: 58
好的,以下是point类的构造函数代码:
```cpp
class point {
public:
int x, y;
point(int x, int y) : x(x), y(y) {
std::cout << "(" << x << ", " << y << ")" << std::endl;
}
};
```
在构造函数中,我们使用了初始化列表来初始化x和y成员变量,并在输出语句中输出了它们的值。
相关问题
point类包含xy写出其构造函数,y的默认值为1,并在构造函数中输出(x,y)的坐标
好的,以下是point类的构造函数代码:
```
class point {
public:
int x, y;
point(int x, int y = 1) : x(x), y(y) {
cout << "(" << x << ", " << y << ")" << endl;
}
};
```
这个构造函数接受两个参数,x和y,其中y的默认值为1。在构造函数中,我们输出了点的坐标(x, y)。
point类包含xy写出其构造函数
以下是 Point 类的构造函数的示例代码:
```cpp
class Point {
public:
int x, y;
Point(int x, int y) : x(x), y(y) {}
};
```
这个构造函数接受两个整数参数 x 和 y,然后将它们分别存储到 Point 对象的 x 和 y 成员变量中。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)