C OJ習題練習 三 函式過載

2021-10-25 00:14:00 字數 2293 閱讀 8203

problem description

編寫過載函式min(),分別計算int、double、float、long型別陣列中的最小值。

程式如下,請完善該程式的設計:

#include

using

namespace std;

intmin

(int

,int);

double

min(

double

,int);

float

min(

float

,int);

long

min(

long

,int);

intmain()

;int aa[4]

=;double b[8]

=;float c[4]

=;long d[3]

=;cout<<

"the least number in a[6] is "

<<

min(a,6)

"the least number in b[8] is "

<<

min(b,8)

"the least number in c[4] is "

<<

min(c,4)

"the least number in d[3] is "

<<

min(d,3)

"the least number in aa[4] is "

<<

min(aa,4)

}//你的**將被嵌在這裡

sample output

the least number in a[

6] is -

111the least number in b[

8] is -

500.345

the least number in c[

4] is -

8.61

the least number in d[

3] is -

63256

the least number in aa[

4] is 2

解題**

#include

using

namespace std;

intmin

(int

,int);

double

min(

double

,int);

float

min(

float

,int);

long

min(

long

,int);

intmain()

;int aa[4]

=;double b[8]

=;float c[4]

=;long d[3]

=;cout<<

"the least number in a[6] is "

<<

min(a,6)

"the least number in b[8] is "

<<

min(b,8)

"the least number in c[4] is "

<<

min(c,4)

"the least number in d[3] is "

<<

min(d,3)

"the least number in aa[4] is "

<<

min(aa,4)

}//你的**將被嵌在這裡

intmin

(int arr,

int n)

double

min(

double arr,

int n)

float

min(

float arr,

int n)

long

min(

long arr,

int n)

C OJ習題練習 十六 計算公司員工的工資

problem description 某公司有老闆boss 雇員employee 小時工hourlyworker和營銷人員commworker,他們的薪金計算方法如下 老闆實行年薪制,如一年15萬 雇員按月計酬,方法是基本工資 獎金 小時工按工作時間計算報酬,方法是工作小時每小時單價 營銷人員按月...

函式練習題

1.打字軟體的正確率 編寫函式,計算字串匹配的準確率,類似於打字軟體 orginstr為原始內容,userstr為使用者輸入內容 2.模擬輪盤 遊戲 轉盤分為三部分 一等獎 二等獎和三等獎 輪盤轉的時候是隨機的,如果範圍在 0,0.08 之間,代表一等獎 如果範圍在 0.08,0.3 之間,代表二等...

C OJ習題練習 二十 計算某高校教師的課酬

problem description 某高校教師的課酬計算方法是 教授100元 小時,副教授80元 小時,講師60元 小時,助教40元 小時。編寫計算教師課酬的程式,從鍵盤輸入教師的姓名 職稱 授課時數,然後輸出該教師應得的課酬。請完善下面的程式 include include using nam...