编程作业题之二-临时抱佛脚

来源:互联网 发布:淘宝店铺打印快递单 编辑:程序博客网 时间:2024/06/04 19:58
题:使用函数重载的方法定义两个重名函数,分别求出整数的两点间的距离和浮点型数的两点间距离(数值自定)


//难度和题一差不多

#include<iostream>using namespace std;int Distance(int x1, int y1,int x2,int y2) {return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));}float Distance(float x1, float y1, float x2, float y2) {return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));}int main() {int a = 1, b = 1, c = 2, d = 2;float a1 = 1, b1 = 1, c1 = 2, d1 = 2;cout << Distance(a, b, c, d) << endl;cout << Distance(a1, b1, c1, d1) << endl;return 0;}


原创粉丝点击