⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 prog9_01.cpp

📁 c++最经典的入门书籍
💻 CPP
字号:
// Program 9.1 Overloading a function
#include <iostream>
using std::cout;
using std::endl;

// Prototypes for two different functions 
double larger(double a, double b);             
long larger(long a, long b);                


int main() {
  double a_double = 1.5, b_double = 2.5;
  float a_float = 3.5f, b_float = 4.5f;
  long a_long = 15L, b_long = 25L;
  cout << endl;
  cout << "The larger of double values " 
       << a_double << " and " << b_double <<" is " 
       << larger(a_double, b_double) << endl;
  cout << "The larger of float values "
       << a_float << " and " << b_float <<" is " 
       << larger(a_float, b_float) << endl;
  cout << "The larger of long values "
       << a_long << " and " << b_long <<" is " 
       << larger(a_long, b_long) << endl;
return 0;
}

// Function to return the larger of two floating point values
double larger(double a, double b) {
  cout << "double larger() called" << endl;
  return a>b ? a : b;
}

// Function to return the larger of two integer values
long larger(long a, long b) {
  cout << "long larger() called" << endl;
  return a>b ? a : b;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -