我怎么能写一个长度函数来返回间隔的长度
How could I write a length function in which gives back the length of the interval?
#include <iostream>
#include <math.h>
using namespace std;
class Interval {
double x,y;
public:
Interval(double,double);
Interval();
void print();
double absz();
void save(char*);
};
Interval::Interval(double x, double y) {
this->x = x;
this->y = y;
}
Interval::Interval() {
cin >> x >> y;
}
void Interval::print() {
cout << "(" << x << "," << y << ")the length of the interval:";
}
double Interval::absz() {
return abs(y-x);
}
int main(int argc, char** argv) {
Interval *i = new Interval();
i->print();
cout << i->absz();
delete i;
system("pause");
return 0;
}
我正在用C++编写一个程序,它可以计算闭合间隔的长度。我的问题是:我怎样才能写一个函数来返回间隔的长度?我感谢每一个帮助。
我想你已经写过了。即,Interval::absz
计算间隔的长度。
相关文章:
- 从函数返回const char*数组
- 检查函数返回类型是否与STL容器类型值相同
- 从 c 或 cpp 系列子函数返回到主函数
- 从函数返回任意简单类型的数据
- 警告:在函数返回类型 [-Wignore 限定符] 时忽略类型限定符
- 从 C++ 中的函数返回数组地址问题
- VirtDisk.h QueryChangesVirtualDisk() 函数返回 RangeCount 为 0
- 为什么glGetSubroutineIndex为不同的函数返回相同的值?
- 在 c++ 中将函数返回类型指定为模板参数
- 从封装在对象中的函数 C++ 返回时为空的列表
- 为什么向量内部的指针在从函数返回时会发生变化?
- 函数返回的 rvalue 引用(表达式)是 xvalue - 但没有标识?
- 程序中的布尔函数返回输入的范围无论如何都是无效的
- 寿命延长从函数返回引用
- 程序不向函数返回值
- 字符串函数返回奇怪的值
- 类的大问题,以及从空函数c++返回
- 为什么在尝试测量函数返回所需的时间时,我的运行时编号是错误的?
- C++二叉搜索树模板从函数返回节点
- NVCC 错误:string_view.h:constexpr 函数返回是非常量