主要是對之前一篇部落格即下圖中的**進行改進封裝成多個函式,使其更加簡潔明瞭
該篇鏈結在此
注:1.標頭檔案中,只能存在變數或者函式的宣告, 而不要放定義
2.要想函式返回多個值,可通過返回指標達到目的
專案如下圖,將原**拆分為四個函式,並定義乙個標頭檔案包含各個函式
標頭檔案**如下:
主函式**如下://標頭檔案
#include
//標準輸入/輸出流物件標頭檔案
using
namespace std;
//使用c++標準程式庫的識別符號宣告
int*
iuputarray
(int len)
;//宣告從螢幕接收陣列函式
int*
bubble_sort
(int length,
int* p)
;//宣告氣泡排序函式
void
outputas
(int length,
int* p)
;//宣告排序後輸出函式
從螢幕接收使用者輸入陣列函式**如下:#include
"head.h"
//呼叫標頭檔案
//主函式實現
intmain()
氣泡排序實現函式**如下:#include
"head.h"
//呼叫標頭檔案
//從螢幕接收使用者輸入陣列函式
int*
iuputarray
(int len)
}return a;
//為輸出整個陣列返回指標型別
}
列印輸出公升序後陣列函式**如下:#include
"head.h"
//呼叫標頭檔案
//氣泡排序實現函式
int temp =0;
//中間變數
int c[
999]
;//定義乙個陣列接收指標傳來原陣列的元素
int*
bubble_sort
(int length,
int* p)
for(
int i=
0;i1;i++
)//氣泡排序核心**}}
return c;
//返回排序後的陣列指標
}
測試案例:#include
"head.h"
//呼叫標頭檔案
//列印輸出公升序後陣列函式
void
outputas
(int length,
int* p)
cout <
//元素輸出結束後換行
}
小白學習中,歡迎交流指正!
it』s good to see you!
標頭檔案和原始檔
一.例1 test.h void show test.cpp include using namespace std void show includeproblem.cpp include test.h int main 可以看到 includeproblem.cpp檔案彙總 include te...
檔案 標頭檔案 原始檔(C )
標頭檔案和原始檔中的函式宣告與定義 函式原型 file fsopen const char filename,const char mode,int shflag file wfsopen const wchar t filename,const wchar t mode,int shflag 注 ...
C 標頭檔案和原始檔的關係
一 原始檔如何根據 include 來關聯標頭檔案 1,系統自帶的標頭檔案用尖括號括起來 include,這樣編譯器會在系統檔案目錄下查詢。2,使用者自定義的檔案用雙引號括起來 include h 編譯器首先會在使用者目錄下查詢,然後在到 c 安裝目錄 比如 vc中可以指定和修改庫檔案查詢路徑,un...