案例研究 查詢金屬數(shù)據(jù)庫(kù)_第1頁(yè)
案例研究 查詢金屬數(shù)據(jù)庫(kù)_第2頁(yè)
案例研究 查詢金屬數(shù)據(jù)庫(kù)_第3頁(yè)
案例研究 查詢金屬數(shù)據(jù)庫(kù)_第4頁(yè)
案例研究 查詢金屬數(shù)據(jù)庫(kù)_第5頁(yè)
已閱讀5頁(yè),還剩5頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、案例研究: 查詢金屬數(shù)據(jù)庫(kù)問(wèn)題 MetalsnMore是一個(gè)郵寄訂購(gòu)金屬的供應(yīng)商,要求以計(jì)算機(jī)文件的形式向公司提供該金屬的詳細(xì)目錄,這樣方便根據(jù)數(shù)據(jù)庫(kù)中的內(nèi)容回答相關(guān)問(wèn)題.重要的問(wèn)題應(yīng)當(dāng)包括以下內(nèi)容:n 什么樣的金屬可以承受135Gpa 的壓力 (1 gigapascalGpa=1千牛/平方毫米) ?n 釩的特征 (密度,熔點(diǎn),拉伸模量) 是什么?n 熔點(diǎn)至少在1400的什么金屬可以在訂購(gòu)日期起的15天內(nèi)交貨?只要我們掌握了提出這些問(wèn)題的正確方法,就能夠容易得到以上問(wèn)題及其他問(wèn)題的答案查詢一個(gè)數(shù)據(jù)庫(kù)應(yīng)該包括兩個(gè)階段:設(shè)置查詢參數(shù)和查詢滿足參數(shù)的記錄.在我們的程序當(dāng)中,先假設(shè)所有的機(jī)構(gòu)成員都包括

2、在被查詢范圍之內(nèi)程序用戶必須鍵入每個(gè)利益范圍的上下界讓我們說(shuō)明以下,這樣來(lái)設(shè)置回答問(wèn)題的查詢參數(shù),熔點(diǎn)至少在的什么金屬可以在訂購(gòu)日期起的天內(nèi)交貨?給出所有的etalsnM ore可以在天內(nèi)交貨的原料,要求金屬的密度不能超過(guò)g/cm3,所有的金屬都在以下熔化,金屬的承載量不能超過(guò)pa,我們可以用下面所列的菜單驅(qū)動(dòng)語(yǔ)言設(shè)置查詢參數(shù):Select by letter a search parameter to set, or enter q to accept parameters shown. Search Parameter Current Value a Low bound for name

3、aaaa b High bound for name zzzz c Low bound for density (g/cm3) 0.00 d High bound for density (g/cm3) 20.00 e Low bound for melting point (degrees C) 0 f High bound for melting point (degrees C) 4000 g Low bound for tensile modulus (Gpa) 0 h High bound for tensile modulus (Gpa) 350 i Low bound for d

4、ays to delivery 0 j High bound for days to delivery 90 Selection>e New low bound for melting point >1400 Select by letter a search parameter to set , or enter q to accept parameters shown . Search Parameter Current Value a Low bound for name aaaa b High bound for name zzzz c Low bound for dens

5、ity (g/cm3) 0.00 d High bound for density (g/cm3) 20.00 e Low bound for melting point (degrees C) 1400 f High bound for melting point (degrees C) 4000 g Low bound for tensile modulus (Gpa) 0 h High bound for tensile modulus (Gpa) 350 i Low bound for days to delivery 0 j High bound for days to delive

6、ry 90 Selection > j New high bound for days to delivery > 15 Select by letter a search parameter to set ,or etnte q to accept parameters shown. Search Parameter Current Value a Low bound for name aaaa b High bound for name zzzz c Low bound for density (g/cm3) 0.00 d High bound for density (g/c

7、m3) 20.00 e Low bound for melting point (degrees C) 1400 f High bound for melting point (degrees C) 4000 g Low bound for tensile modulus (Gpa) 0 h High bound for tensile modulus (Gpa) 350 i Low bound for days to delivery 0 j High bound for days to delivery 15 Selection > q數(shù)據(jù)要求問(wèn)題輸入Search_params_t

8、params ; /*查詢參數(shù)范圍Char inv_filename STR_SIZ /*詳細(xì)目錄文件名問(wèn)題輸出所有滿足查詢條件的金屬初始算法分析1. 打開(kāi)詳細(xì)目錄文件2. 輸入查詢參數(shù)3. 示所有滿足查詢參數(shù)的金屬步驟和步驟的算法細(xì)化,在建立函數(shù)get_params和display_match的過(guò)程中有所體現(xiàn)實(shí)現(xiàn)如圖.所示,列出了實(shí)現(xiàn)程序的數(shù)據(jù)庫(kù)概要,包括main函數(shù)的完整代碼段我們?cè)O(shè)計(jì)并實(shí)現(xiàn)的由main函數(shù)調(diào)用的函數(shù)以及其輔助函數(shù)都在此提綱后列出 顯示數(shù)據(jù)庫(kù)中所有滿足查詢參數(shù)條件的金屬 這些查詢參數(shù)是由程序用戶詳細(xì)說(shuō)明的 include <stdio.h># include &

9、lt;string.h># define MAX_DENSITY 20.0 /* 最大密度(g/cm3) */# define MAX_MELT_PT 4000 /* 最高熔點(diǎn)(攝氏度) *# define MAX_TENS_MOD 350 /*最大拉伸模量(pa)*# define MAX_DAYS 90/*最長(zhǎng)交貨期限*# define STR_SIZ 80/*字符串中字符個(gè)數(shù)*Typedef struct /*金屬結(jié)構(gòu)體類型* char name STR_SIZ; double density; /* g/cm3 * int melt_pt, /*攝氏度表示的熔點(diǎn)* tens_mo

10、d,/*拉伸模量(pa)* day_to_deliv;/*從定貨到交貨的日期* metal_t;tupedef struct /*查詢參數(shù)范圍類型 * char low_name STR_SIZ, high_name STE_SIZ; double low_density, high_density; int low_melt_pt, high_melt_pt low_tens_mod, high_tens_mod,low_days, high_days; search_params_t;/*插入所需其他函數(shù)的原型/*提示用戶鍵入查詢參數(shù)*Search_params_t get_params

11、(void);/*顯示在詳細(xì)記錄中所有滿足查詢參數(shù)條件的金屬記錄*void display_match (FILE *databasep , /* 輸入二進(jìn)制數(shù)據(jù)庫(kù)文件指針*/ search_params_t parans) ; /*輸入查詢參數(shù)范圍*/intmain (void) char inv_filenameSTR_SIZ; /*詳細(xì)目錄文件名*/ FILE *inventoryp; /*詳細(xì)目錄文件指針*/ Search_params_t params ; /*查詢參數(shù)范圍*/* 輸入詳細(xì)目錄文件名并打印文件*/Printf(“Entet name of inventory file

12、 >”);scanf (“&s”, inv_filename);inventoryp = fopen (inv_fliename, “rb”);/* 輸入查詢參數(shù) */params = get_params();/*顯示所有滿足查詢參數(shù)的金屬*/display_match (inventoryp, params);return (0); 圖.金屬數(shù)據(jù)庫(kù)查詢程序的提綱及主要函數(shù)子函數(shù)的設(shè)計(jì)函數(shù)get_params首先必須對(duì)查詢參數(shù)進(jìn)行出初始化,使其在最大限度內(nèi)進(jìn)行查詢,然后用戶再改變一些參數(shù)來(lái)縮小查詢的范圍函數(shù)get_params的局部變量和算法如下,它的實(shí)現(xiàn)要求在本節(jié)末尾的編程練

13、習(xí)中完成函數(shù)get_params的局部變量search_params_t params; /*必須被定義結(jié)構(gòu)的成員 */ chan choice; /*用戶對(duì)菜單的反應(yīng)*/ 函數(shù)get_params的算法1. 對(duì)params進(jìn)行初始化,允許最大限度地進(jìn)行查詢2. 顯示菜單,得到反應(yīng)并存入choice中3. 如果choice不為q,重復(fù)4. 選擇相應(yīng)的提示,得到新的參數(shù)值5. 顯示菜單,得到反應(yīng)并存入choice中6. 返回查詢參數(shù)函數(shù)display_match 必須在名稱的上界和下界之間檢查所有的文件記錄如果有記錄滿足查詢參數(shù)條件就將其顯示出來(lái),如果沒(méi)有找到匹配條件的,函數(shù)display_ma

14、tch也會(huì)顯示相應(yīng)的信息函數(shù)的局部變量和算法如下函數(shù)display_match的局部變量metal_t mext_metal /*當(dāng)前金屬 */ int no_matches /* 是否匹配的標(biāo)記*/函數(shù)display_match的算法1. 將no_matches初始化為真()2. 在名稱范圍內(nèi)先提出第一個(gè)記錄3. 如果目前的記錄名仍在范圍內(nèi),重復(fù)4. 如果查詢參數(shù)匹配5. 顯示該金屬并將no_matchaes值設(shè)置為假()6. 輸入下一個(gè)金屬記錄7. 如果沒(méi)有匹配的8. 顯示no metals available的信息實(shí)現(xiàn) 圖.給出了函數(shù)display_match. menu_choose和

15、match的代碼,還有函數(shù)show的占用程序/ * *顯示一個(gè)印有當(dāng)前查詢參數(shù)值的菜單返回用戶鍵入的文字*在a到j(luò)之間的字母中,每個(gè)對(duì)應(yīng)范圍內(nèi)的一個(gè)參數(shù)選擇;q代表停止*給出查詢參數(shù)*/ char menu_choose (searchparams_t params) /*輸入當(dāng)前查詢參數(shù)的范圍 */ char choice; printf (“Select by letter a search parameter to set ,”) prinrf (“or enter q tonaccept parameters shown.nn”); prinrf (“Search Parameter

16、“); prinrf (“Current Value, n”); printf (“ a Low bound for name %sn ”, params . low_name); pinrtf (“ b High bound for name %sn” , params .high_name); printf (“ c Low bound for density (g/cm3) %5.2fn”, params. low_density); printf (“ d High bound for density (g/cm3) %5.2fn”, params. high_ density); p

17、rintf (“ e Low bound for melting point (degrees C) %4dn”, params. low_melt_ pt); prinrf (“ f High bound for melting point (degrees C) %4dn”, params. high_ melt_ pt); printf (“g Low bound for tensile modulus (Gpa) %3dn”, params. low_tens_mod); prinrf (“ h High bound for tensile modulus (Gpa) %3dn”, p

18、arams. high_tens_mod); printf (“i Low bound for days to delibery %3dn”, params. low_days); printf (“j High bound for days to delibery %3dn”, params. high_days); printf (“Selection>”); for (scanf (“&c”, &choice); ! (choice >= a && choice <=j choice = q); scanf(“%c”,&choic

19、e) return (choice);/* * 判定金屬是否滿足查詢參數(shù) */int match (metalt metal , /*輸入要查詢的金屬記錄*/search_params_t params ) /*輸入要滿足的參數(shù)*/ return ( params .low_density <=metal .dendity && params .high_density >= metal .dendity && params .low_melt_pt <= metal .melt_pt && params .high_melt_

20、pt >= metal .melt_pt && params .low_tens_mod <=metal.tens_mod && params .high_tens_mod >=metal.tens_mod && params.low_days <= metal.days_to_deliv && params.high_days>= metal.days_to_deliv && /* * *占程序*顯示每個(gè)金屬記錄的組成 *在輸出金屬后留出一個(gè)空行*/ void show ( metal_t metal printf (“Function show entered with metal %sn”, ); /*顯示詳細(xì)目錄中滿足查詢參數(shù)條件的所有金屬記錄*/voiddisplay_match(FILE *databasep, /*二進(jìn)制數(shù)據(jù)庫(kù)文件的指針 */ search_params_t parama) /*輸入查詢參數(shù)范圍 */ metal_t naxt_metal; /* 數(shù)據(jù)庫(kù)中的當(dāng)

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論