202130310113
实验目的:
- 理解类和对象的概念,掌握声明类和定义对象的方法
- 掌握构造函数和析构函数的实现方法
- 初步掌握使用类和对象编制C++程序
实验内容:
- 创建一个类,完成以下功能:
- 连续输入一组二维坐标值;
- 二维坐标值的数目可以由用户自定义(默认为2个,最多为100组);
- 显示用户输入的坐标值;
- 显示用户输入坐标值的均值;
实验内容1:
- 观察例程中的构造函数和析构函数的运行顺序;
#pragma once
#include<iostream>
using namespace std;
class Coordinate
{
public:
Coordinate()
{
times = 2;
cout << "Coordinate construction called!" << endl;
}
Coordinate(int times1)
{
times = times1;
cout << "Coordinate construction2 called!" << endl;
}
~Coordinate()
{
cout << "Coordinate destruction called!" << endl;
}
void InputCoord()
{
for (int i = 0; i < times; i++)
{
cout