SlideShare a Scribd company logo
1 of 42
Download to read offline
專題報告
貨品存取操作系統之探討
指導老師:楊建成 老師
學生:許元美 D9920899
林于珊 D9935737
孫莉筑 D9935808
蔡孟娟 D9980618
學年: 101 學年 第 2 學期
日期: 2013 年 06 月 19 日
專題報告-貨品存取操作系統之探討 2013/06/19
1
目錄
一、緒論----------------------------------------------02
二、資料庫結構與內容----------------------------04
三、程式碼呈現及介紹----------------------------11
四、作品呈現----------------------------------------28
五、結論與感想-----------------------------------------36
專題報告-貨品存取操作系統之探討 2013/06/19
2
一、 緒論
(一) 背景
這是一個以 C 語言來撰寫的庫存管理系統,這個系統
有新增、查詢、修改、刪除四項功能,這四項功能為每個
庫存管理系統最基本且必要的。
現代許多店家都會用到庫存系統,因此我們撰寫了一
個簡單的系統,如果可用電腦查資料,不但省時又方便。
(二) 動機
一開始我們只是想做一個可以有系統的歸納系統,可
以利用電腦輕鬆找到東西的存放位置。在綜合與老師討論
後的意見和上網查詢的資料後,最符合的就是「賣場的庫
存系統」了。
本來我們要用以既定的軟體(MySQL)下去做,但用不
太到撰寫程式碼的部分,又由於我們希望能以寫程式的方
式呈現,而且 MySQL 這軟體我們也不熟悉還需要重新學
習,所以最後還是決定以寫程式的方式來完成此專題討論。
由於庫存系統,過於龐大,所以我們只針對庫存系統裡的
採購、營業、委外、製令這四個小系統,內部共同有的新
增、查詢、修改、刪除四項基本的功能,來撰寫此程式。
專題報告-貨品存取操作系統之探討 2013/06/19
3
(三) 目的
在現今資訊爆炸且廣布運用的情況下,很多東西都是
使用電腦來管理,藉由我們所探討的主題可以使產品的資
料進行有效率的排列和管理,並且對於庫存的數量能夠隨
時掌握,以達到減少人力成本和查貨所需的時間,讓庫存
資料使用起來能夠更便利。
專題報告-貨品存取操作系統之探討 2013/06/19
4
二、 資料庫結構與內容
(一) 一維陣列
想要存放一連串相關資料,使用陣列會是個很好的選
擇。「陣列」 (array)是由一群相同型態的變數所組成的一
種資料結構,他們以一個共同的名稱來表示。
陣列中個別的元素是以「索引值」 (或稱為註標,
index),來標示存放的位置。陣列依存放元素(element)的
複雜度,分為一維、二維與二維以上的多維陣列。
一維陣列(1-dimensional array)可以存放多個相同型態
的資料,陣列和變數一樣也需要經過宣告後才能使用。陣
列宣告後,編譯器分配給該陣列的記憶體是一個連續的區
塊,此時即可在這個區塊內存放資料。
資料形態 陣列名稱[個數]; /*宣告一維陣列格式*/
宣告好陣列之後,如果想要使用陣列裡的元素,可以
利用陣列裡的索引值完成。
專題報告-貨品存取操作系統之探討 2013/06/19
5
整個陣列就好比是整個旅館裡的房間,而索引值就好
像是房間的編號一樣,只要根據房間的編號(索引值),就
能找到住宿的客人(儲存於陣列裡的元素)。
(二) 結構
陣列只能用來存放一群相同型態的資料,「結構」就
沒有這個限制。相較於陣列利用「結構」可以把不同的資
料形態組合在一起,形成一個新的資料形態,這就是結構
的基本概念。另外,「列舉」可用一組有意義的名稱取代
一組整數常數,以方便程式設計。
利用 C 語言所提供的「結構」(structure),可將一群
形態不同卻又相互關聯的資料組合在一起,形成一種新的
資料形態。以下介紹結構的基本概念,以及他的使用方式,
首先我們來看看結構變數的定義與宣告方式。
專題報告-貨品存取操作系統之探討 2013/06/19
6
如果想要同時儲存學生的姓名與數學成績,因為這兩
種資料的形態並不相同,過去我們必須使用兩個不同形態
的變數來儲存他們,現在則是可以利用 C 語言提供的結
構,將這些有關連性,型態卻不同的資料存放在同一個新
式的資料結構裡。
在使用結構之前,必須先定義結構的內容,然後再利
用定義的結構來宣告變數。
struct 結構名稱 /*定義結構*/
{
資料形態 成員名稱 1;
資料形態 成員名稱 2;
……
資料形態 成員名稱 n;
};
專題報告-貨品存取操作系統之探討 2013/06/19
7
(三) 指標
透過變數名稱來存取變數的內容。除了透過變數的名
稱之外,C 語言還提供了另一種存取變數的特殊方式,可
以不必使用變數的名稱,便能存取到變數的值,這種技術
變是利用「指標」(pointer)來達成的。
指標可看程式一種特殊的變數,用來存放變數在記憶
體中的位址。當我們宣告一個變數時,編譯器便會配置一
塊足夠儲存這個變數的記憶體空間給他。每個記憶體空間
均有他獨一無二的編號。這些編號稱為記憶體的「位址」
(address),程式便是利用記憶體的位址來存取變數的內容。
位址有如車牌號碼一樣,程式可以依照位址來存取變數,
就如同只要有了車牌號碼(位址) ,便可以掌握到車籍資
料(變數內容)一樣。
資料形態 *指標變數; /*宣告指標變數*/
/* 在變數的前面加上指標符號「*」即可將變數宣告成指標變數 */
專題報告-貨品存取操作系統之探討 2013/06/19
8
(四) 字串比較
strcmp 函數的作用是用於比較兩個字符串,它的原型是:
int strcmp(char const*s1,char const*s2);
strcmp 用法:
比較字符串 S1 和 S2,從兩個字符串的第一個字符開
始比叫大小,比較大小時是根據字符在 ASCⅡ中排序。
如果,兩個字符串的第一個字符相同的話,再比較第
二個字符的大小,如此纇推。
在比較的過程中遇到所比較的兩個字符不相同的話,
strcmp 就停止對後面字符的比較,而返回一個整數。S1
比 S2 大,就返回大於零的整數;S1 比 S2 小,就返回小
於零的整數。當 S1 和 S2 是一模一樣的兩個字符串的時
候,就返回零。
專題報告-貨品存取操作系統之探討 2013/06/19
9
(五) 陣列、指標與結構間的關係
(1)指標函數
指標使我們可以直接呼叫執行所指的函數。
(2)在結構定義中可以使用基本的變數、陣列、指標,甚
至是其他結構成員等。在結構定義中使用不同的結構
成員因而形成不同方式的陣列。
 結構陣列
 結構指標
專題報告-貨品存取操作系統之探討 2013/06/19
10
(六) While 迴圈
如果想處理重複性的工作時,「迴圈」會是一個方便
的選擇,它可以執行相同的程式片段,還可以讓程式結構
化。
當迴圈重複執行的次數很確定時,就會使用for迴圈。
但是對於有些問題,無法事先知道迴圈該執行幾次才夠時,
就可以考慮使用 while 迴圈或 do while 迴圈。
While 迴圈提供了類似 for 迴圈的功能,但 for 迴圈必
須知道迴圈執行的次數,while 迴圈則不用。下面就是 while
迴圈的格式
設定初值;
while( 判斷條件 ) □ /* □:不可加分號 */
{
迴圈主體;
設定增減量;
} □ /* □:不可加分號 */
當 while 迴圈主體只有一個敘述時,可以不使用大括
號。在 while 迴圈敘述中,判斷條件通常是一個帶有邏輯
運算子的運算式,當判斷值為真(ture),迴圈就會執行一
次,再重複測試判斷條件、執行迴圈主體,直到判斷條件
值為假(false)時,才會跳離 while 迴圈。
專題報告-貨品存取操作系統之探討 2013/06/19
11
三、 程式碼呈現及介紹
*程式碼呈現
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define Q 20
struct cargo //cargo 貨物
{
char Product[30]; //商品名稱
char Code[14]; //條碼
char Vendors[30]; //廠商
float Price; //價格
int Stock; //庫存
};
void add(struct cargodetail[]);
void modify(struct cargo detail[]);
void deleted(struct cargo detail[]);
void search(struct cargodetail[]);
int tail;
int main(void)
{
struct cargo detail[Q]; //detail 明細
int i;
FILE *fp1;
if((fp1 = fopen("databasein.txt","r"))==NULL)
tail=-1;
else{
fscanf(fp1,"%d",&tail);
for(i=0;i<=tail;i++)
fscanf(fp1,"%s %s %f %s %d",detail[i].Product,
detail[i].Code, &detail[i].Price,
detail[i].Vendors,&detail[i].Stock);
}
//功能
專題報告-貨品存取操作系統之探討 2013/06/19
12
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
int funop=1;
while(funop!=5){
while((funop>=1)&&(funop<5)){
printf("請選擇下列選項:n");
printf("1.新增n");
printf("2.修改n");
printf("3.刪除n");
printf("4.查詢n");
printf("5.離開n");
scanf("%d",&funop);
fflush(stdin);
switch(funop)
{
case 1:
add(detail); //副程式
break;
case 2:
modify(detail); //副程式
break;
case 3:
deleted(detail); //副程式
break;
case 4:
search(detail); //副程式
break;
}
}
}
fp1 = fopen("databasein.txt","w");
fprintf(fp1,"%dn",tail);
for(i=0;i<=tail;i++)
fprintf(fp1,"%sn%sn%.2fn%sn%dnn",detail[i].Product,
detail[i].Code,detail[i].Price,
detail[i].Vendors,detail[i].Stock);
fclose(fp1);
system("pause");
專題報告-貨品存取操作系統之探討 2013/06/19
13
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
return 0;
}
/*===============以下為副程式===============*/
/*新增*/
void add(struct cargodetail[])
{
tail=tail+1;
int i=0,a,n;
int New=0;
struct cargo sample;
printf("以下資料請以小寫輸入n");
printf("----------------------n");
printf(" 請輸入商品名稱: n");
scanf("%s",sample.Product);
printf(" 請輸入商品條碼: n");
scanf("%s",sample.Code);
printf(" 請輸入商品價格: n");
scanf("%f",&sample.Price);
printf(" 請輸入商品廠商: n");
scanf("%s",sample.Vendors);
printf(" 請輸入商品存貨: n");
scanf("%d",&sample.Stock);
fflush(stdin); //清空緩衝區的資料
if (tail==0)
detail[0]=sample;
else{
while(i<=tail){
n=strcmp(sample.Product,detail[i].Product);
if(n<0) {
New=i;
break;
}
i++;
}
專題報告-貨品存取操作系統之探討 2013/06/19
14
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
if(New<tail){
for(a=tail;a>=New;a--)
detail[a]=detail[a-1];
detail[New]=sample;
}else{
detail[tail]=sample;
}
}
return ;
}
/*修改*/
void modify(struct cargo detail[])
{
char Pro[30];
int i=0,n;
printf("請輸入商品名稱:n");
scanf("%s",Pro);
fflush(stdin); //清空緩衝區的資料
while(i<=tail){
n=strcmp(Pro,detail[i].Product);
if(n==0){
printf("商品名稱 %sn",detail[i].Product);
printf("商品條碼 %sn",detail[i].Code);
printf("商品價格 %.2fn",detail[i].Price);
printf("商品廠商 %sn",detail[i].Vendors);
printf("商品存貨 %dnn",detail[i].Stock);
break;
}
i++;
}
if(i>tail)
printf("找不到此商品nn");
else{
int funop=1;
while(funop!=4){
while((funop>=1)&&(funop<4)){
printf("請選擇修改選項n");
專題報告-貨品存取操作系統之探討 2013/06/19
15
149
150
151
152
153
154
155
156
157
158
159
160
160
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
printf("1.價格n");
printf("2.廠商n");
printf("3.存貨n");
printf("4.離開n");
scanf("%d",&funop);
fflush(stdin);
if(funop==1){
printf("輸入修改價格:");
scanf("%f",&detail[i].Price);
}else if(funop==2){
printf("輸入修改廠商:");
scanf("%s",&detail[i].Vendors);
}else if(funop==3){
printf("輸入修改存貨:");
scanf("%d",&detail[i].Stock);
}
}
printf("修改後資料n");
printf("-------------------n");
printf("商品名稱 %sn",detail[i].Product);
printf("商品條碼 %sn",detail[i].Code);
printf("商品價格 %.2fn",detail[i].Price);
printf("商品廠商 %sn",detail[i].Vendors);
printf("商品存貨 %dnn",detail[i].Stock);
}
}
return ;
}
/*刪除*/
void deleted(struct cargo detail[])
{
char Pro[30];
int i=0,New,a,n;
printf("請輸入商品名稱:n");
scanf("%s",Pro);
while(i<=tail){
專題報告-貨品存取操作系統之探討 2013/06/19
16
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
n=strcmp(Pro,detail[i].Product);
if(n==0){
New=i;
break;
}
i++;
}
if(i>tail)
printf("找不到此商品nn");
else{
for(a=New;a<=tail;a++)
detail[a]=detail[a+1];
tail=tail-1;
}
return ;
}
/*查詢*/
void search(struct cargodetail[])
{
char Pro[30];
int i=0,n;
printf("請輸入商品名稱:n");
scanf("%s",Pro);
while(i<=tail){
n=strcmp(Pro,detail[i].Product);
if(n==0){
printf("您要查詢之商品:n");
printf("----------------------n");
printf("商品名稱 %sn",detail[i].Product);
printf("商品條碼 %sn",detail[i].Code);
printf("商品價格 %.2fn",detail[i].Price);
printf("商品廠商 %sn",detail[i].Vendors);
printf("商品存貨 %dnn",detail[i].Stock);
break;
}
i++;
}
專題報告-貨品存取操作系統之探討 2013/06/19
17
225
226
227
228
if(i>tail)
printf("找不到此商品nn");
return ;
}
專題報告-貨品存取操作系統之探討 2013/06/19
18
*以下將分段介紹整個程式的架構。
(一) 全域變數
5
6
7
8
9
10
11
12
13
14
15
16
17
18
struct cargo //cargo 貨物
{
char Product[30]; //商品名稱
char Code[14]; //條碼
char Vendors[30]; //廠商
float Price; //價格
int Stock; //庫存
};
void add(struct cargodetail[]);
void modify(struct cargo detail[]);
void deleted(struct cargo detail[]);
void search(struct cargodetail[]);
int tail;
這些是宣告在全域變數裡的值,在下面的主程式、副程式只
要有用到這些變數,都可以直接從全域變數呼叫作使用,不需要
再重新宣告。
5~12 行,struct 是結構的形式,在主程式、副程式都會用到
這個結構,因此宣告在全域變數較方便使用,不必每次都重新宣
告;14~17 行,功能副程式的宣告,因為我們副程式寫在主程式
後面,所以必須做此宣告才能呼叫副程式,並且使用副程式;18
行,tail 是計算檔案裡有多少項商品的計數器,以方便我們知道
目前商品的數量。
專題報告-貨品存取操作系統之探討 2013/06/19
19
(二) 判斷是否有 databasein.txt
21
22
23
24
25
26
27
28
29
30
31
32
struct cargo detail[Q]; //detail 明細
int i;
FILE *fp1;
if((fp1 = fopen("databasein.txt","r"))==NULL)
tail=-1;
else{
fscanf(fp1,"%d",&tail);
for(i=0;i<=tail;i++)
fscanf(fp1,"%s %s %f %s %d",detail[i].Product,
detail[i].Code, &detail[i].Price,
detail[i].Vendors,&detail[i].Stock);
}
為主程式的開始。我們先由 if 判斷是否有 databasein.txt 這個
可讀的檔案,若沒有此檔案,則 tail=-1,進入功能選項;若有此
檔案,則指標*fp1=databasein,程式會讀入檔案的第一行數字
(=tail),再讀入裡面的資料,進入功能選項。
(三) 功能選項
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//功能
int funop=1;
while(funop!=5){
while((funop>=1)&&(funop<5)){
printf("請選擇下列選項:n");
printf("1.新增n");
printf("2.修改n");
printf("3.刪除n");
printf("4.查詢n");
printf("5.離開n");
scanf("%d",&funop);
fflush(stdin);
switch(funop)
{
專題報告-貨品存取操作系統之探討 2013/06/19
20
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
case 1:
add(detail); //副程式
break;
case 2:
modify(detail); //副程式
break;
case 3:
deleted(detail); //副程式
break;
case 4:
search(detail); //副程式
break;
}
}
}
這個程式有 4 項功能,新增、修改、刪除、查詢。
我們使用了 while 迴圈,確保程式不會在執行中途跳出,導致
程式錯誤,並且程式使用者不需重新執行這個檔案,也能無限次
使用功能,一直到程式使用者輸入「5」時,while 迴圈才會因為
初始設定,而跳出程式,並作存取的動作。
當程式使用者輸入功能選項後,我們使用了switch來作判斷,
確認程式使用者輸入的數字,而進入該數字配對到的副程式中。
專題報告-貨品存取操作系統之探討 2013/06/19
21
(四) 副程式
1. 功能選項→【1.新增】
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*新增*/
void add(struct cargodetail[])
{
tail=tail+1;
int i=0,a,n;
int New=0;
struct cargo sample;
printf("以下資料請以小寫輸入n");
printf("----------------------n");
printf(" 請輸入商品名稱: n");
scanf("%s",sample.Product);
printf(" 請輸入商品條碼: n");
scanf("%s",sample.Code);
printf(" 請輸入商品價格: n");
scanf("%f",&sample.Price);
printf(" 請輸入商品廠商: n");
scanf("%s",sample.Vendors);
printf(" 請輸入商品存貨: n");
scanf("%d",&sample.Stock);
fflush(stdin); //清空緩衝區的資料
if (tail==0)
detail[0]=sample;
else{
while(i<=tail){
n=strcmp(sample.Product,detail[i].Product);
if(n<0) {
New=i;
break;
}
i++;
}
if(New<tail){
專題報告-貨品存取操作系統之探討 2013/06/19
22
112
113
114
115
116
117
118
119
120
for(a=tail;a>=New;a--)
detail[a]=detail[a-1];
detail[New]=sample;
}else{
detail[tail]=sample;
}
}
return ;
}
新增副程式,一開始會先呼叫全域變數裡的結構
(struct cargo),並依 struct cargo 裡的項目依序輸入資料,
存放到 sample 結構裡,每新增一筆資料 tail 會加 1,若一
開始 tail = 0 代表原本的檔案裡未儲存任何資料,本筆資
料為第一筆;若 tail ≥1 則會進入 while 迴圈判斷,並使
用 strcmp 函數來比較商品名稱的字串,若輸入的字串的
ASCII 碼比檔案裡字串的 ASCII 碼大,則繼續跟下一筆資
料比…以此類推,直到輸入的字串的 ASCII 碼比檔案裡
字串的 ASCII 碼小,則輸入的資料放在檔案裡該筆資料
上方;若比較到最後一筆仍然沒有結果,則該筆資料放在
檔案的最後一筆,新增結束後,所有檔案會存入 detail[]
陣列中。
專題報告-貨品存取操作系統之探討 2013/06/19
23
2. 功能選項→【2.修改】
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*修改*/
void modify(struct cargo detail[])
{
char Pro[30];
int i=0,n;
printf("請輸入商品名稱:n");
scanf("%s",Pro);
fflush(stdin); //清空緩衝區的資料
while(i<=tail){
n=strcmp(Pro,detail[i].Product);
if(n==0){
printf("商品名稱 %sn",detail[i].Product);
printf("商品條碼 %sn",detail[i].Code);
printf("商品價格 %.2fn",detail[i].Price);
printf("商品廠商 %sn",detail[i].Vendors);
printf("商品存貨 %dnn",detail[i].Stock);
break;
}
i++;
}
if(i>tail)
printf("找不到此商品nn");
else{
int funop=1;
while(funop!=4){
while((funop>=1)&&(funop<4)){
printf("請選擇修改選項n");
printf("1.價格n");
printf("2.廠商n");
printf("3.存貨n");
printf("4.離開n");
scanf("%d",&funop);
fflush(stdin);
if(funop==1){
printf("輸入修改價格:");
專題報告-貨品存取操作系統之探討 2013/06/19
24
158
159
160
160
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
scanf("%f",&detail[i].Price);
}else if(funop==2){
printf("輸入修改廠商:");
scanf("%s",&detail[i].Vendors);
}else if(funop==3){
printf("輸入修改存貨:");
scanf("%d",&detail[i].Stock);
}
}
printf("修改後資料n");
printf("-------------------n");
printf("商品名稱 %sn",detail[i].Product);
printf("商品條碼 %sn",detail[i].Code);
printf("商品價格 %.2fn",detail[i].Price);
printf("商品廠商 %sn",detail[i].Vendors);
printf("商品存貨 %dnn",detail[i].Stock);
}
}
return ;
}
修改的副程式,一開始要先輸入想要修改的商品名稱,
進入 while 迴圈,以 strcmp 函數來比較商品名稱的字串,
若字串相符合,會顯示該商品資料,在進入修改選項的
while 迴圈中,以 if 判斷程式使用者輸入的數字,對應到
需修改的部分。;若字串不相符合,則會顯示找不到此商
品。
程式是以取代的方式來修改資料,Ex:修改價格,程
式會請你輸入新價格,新價格會直接取代原先的價格,並
存回 detail[]中。
專題報告-貨品存取操作系統之探討 2013/06/19
25
3. 功能選項→【3.刪除】
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*刪除*/
void deleted(struct cargo detail[])
{
char Pro[30];
int i=0,New,a,n;
printf("請輸入商品名稱:n");
scanf("%s",Pro);
while(i<=tail){
n=strcmp(Pro,detail[i].Product);
if(n==0){
New=i;
break;
}
i++;
}
if(i>tail)
printf("找不到此商品nn");
else{
for(a=New;a<=tail;a++)
detail[a]=detail[a+1];
tail=tail-1;
}
return ;
}
刪除副程式,一開始先輸入想要修改的商品名稱,進
入 while 迴圈,以 strcmp 函數來比較商品名稱的字串,若
字串相符合,則會由該筆資料(detail[a])的下一筆
(detail[a+1])直接往上覆蓋該筆資料,後面也會依序往上覆
蓋,直到 tail 所指的最後一筆資料(detail[detail])才停止,
再讓 tail 減 1,使資料的數量正確;若字串不相符合,則
會顯示找不到此商品。
專題報告-貨品存取操作系統之探討 2013/06/19
26
4. 功能選項→4.查詢
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/*查詢*/
void search(struct cargodetail[])
{
char Pro[30];
int i=0,n;
printf("請輸入商品名稱:n");
scanf("%s",Pro);
while(i<=tail){
n=strcmp(Pro,detail[i].Product);
if(n==0){
printf("您要查詢之商品:n");
printf("----------------------n");
printf("商品名稱 %sn",detail[i].Product);
printf("商品條碼 %sn",detail[i].Code);
printf("商品價格 %.2fn",detail[i].Price);
printf("商品廠商 %sn",detail[i].Vendors);
printf("商品存貨 %dnn",detail[i].Stock);
break;
}
i++;
}
if(i>tail)
printf("找不到此商品nn");
return ;
}
查詢副程式,一開始先輸入想要修改的商品名稱,進
入 while 迴圈,以 strcmp 函數來比較商品名稱的字串,若
字串相符合,則會顯示該筆資料;若字串不相符合,則會
顯示找不到此商品。
專題報告-貨品存取操作系統之探討 2013/06/19
27
(五) 儲存
64
65
66
67
68
69
70
fp1 = fopen("databasein.txt","w");
fprintf(fp1,"%dn",tail);
for(i=0;i<=tail;i++)
fprintf(fp1,"%sn%sn%.2fn%sn%dnn",detail[i].Product,
detail[i].Code,detail[i].Price,
detail[i].Vendors,detail[i].Stock);
fclose(fp1);
開啟一個可寫入的 fp1=databasein.txt,把 tail 的數字和新增、
修改、刪除所發生的事件寫入 databasein.txt,並關閉 fp1。
專題報告-貨品存取操作系統之探討 2013/06/19
28
四、 作品呈現
這一段我們介紹完整的程式、程式的介面及功能的操作
這是程式一開始的執行介面-功能選項的部分。
第一次執行,所以在電腦裡並沒有 databasein.txt。
專題報告-貨品存取操作系統之探討 2013/06/19
29
(一)新增
新增一筆資料。
做了離開的動作,電腦裡出現了 databasein.txt 這個檔案。
專題報告-貨品存取操作系統之探討 2013/06/19
30
databasein.txt 裡的資料型態。
剛剛輸入了一筆新的資料,也有存放進去。
多新增幾筆資料到 databasein.txt。目前有 tail+1=4 筆資
料,因為程式有排序的功能,原本先輸入的 panda 變成第三
筆資料,最多能放 20 筆資料。
專題報告-貨品存取操作系統之探討 2013/06/19
31
(二)修改-可修改價格、廠商跟存貨
修改商品價格 99.3→100。
程式會先請使用者輸入欲修改之商品名稱,比對完後,會
先顯示輸入商品的資料,再進行修改選項詢問,在修改完後,
程式會再詢問修改選項,直到程式使用者按離開,不然會一直
循環,離開後會輸入商品修改後的資料。
專題報告-貨品存取操作系統之探討 2013/06/19
32
修改商品廠商 jcy→jcy2。
修改商品存貨 1→2。
專題報告-貨品存取操作系統之探討 2013/06/19
33
離開儲存後,databasein.txt 裡修改情況。
專題報告-貨品存取操作系統之探討 2013/06/19
34
(三)刪除
程式會先請使用者輸入欲刪除之商品名稱,比對完後,會
直接刪除此筆資料。
離開儲存後,databasein.txt 裡情況。Panda 這筆資料被刪
掉了,tail 也顯示少了一筆資料。
專題報告-貨品存取操作系統之探討 2013/06/19
35
(四)查詢
程式會先請使用者輸入欲查詢之商品名稱,比對完後,會
直接顯現此筆資料在執行介面上。
panda 在上一步驟已經刪除掉了,程式查詢不到,所以會
顯示找不到此商品。
專題報告-貨品存取操作系統之探討 2013/06/19
36
五、 結論與感想
(一) 結論
我們這次的專題-貨品存取操作系統,主要是提供一般商店
使用,方便於記錄商品的進貨廠商和商品的數量及價格等,我們
以 C 語言的執行介面來呈現結果。介面提供了商品資料新增、商
品資料修改、商品刪除、商品資料搜尋四項功能。雖然我們的程
式並不大,而且功能也不多,但我們期望能夠透過這個系統,讓
使用者在使用時能輕鬆上手,而且感覺到方便,以達到減少人力
成本和查貨所需的時間,隨時掌握讓庫存資料。
(二) 感想
 蔡孟娟
透過這個專題,讓我們寫程式的功力更提升了,雖然
我們使用的函數都是最基本最簡單的,但卻也是最淺顯易
懂的。有一些函數是沒學過的,我們從網路上查得,再與
老師進行討論,最後理解並使用,讓程式更完整。這個程
式雖然只有新增、查詢、修改、刪除四個功用,但是最實
用也是對基本的功能,大家分工找資料,在一起出去討論,
透過不斷的修改、討論和老師的建議,我們終於做出這個
專題。
專題報告-貨品存取操作系統之探討 2013/06/19
37
 許元美
我們做的這個小物流系統,功能並不多,程式並不長,
可是我們學到了很多,在打程式的方面也進步了很多。在
撰寫程式的途中,我們會有疑惑到底這個程式的功能性,
到底強不強,但在完成之後,我們發現,這個程式其實只
要改一下程式碼,或者在程式碼裡的請輸入後面加其他想
輸入之項目,這個程式的作用就不只是小物流系統了,他
可以變成其他東西的記憶位置,仔細的想想這個程式比我
們想像的程式還要完整,雖然他還可以在更完整,我們還
可以再加些東西,但我們做的是小物流,既然是【小】,
那就不用把他作到大囉!
剛開始討論專題要做資料庫時,我們查了一些資料,
沒多久我們就決定要作物流系統,本來要用 MySQL,最
後的討論,我們還是決定用 C 語言來呈現,由於時間的
關係,我們只做了物流系統裡的四個基本的功能。
在撰寫這個程式時,我們學到了一些我們從沒正式寫
過的函數,例如:struct、strcmp。這兩個函數我們在大
一計概時沒有碰過,尤其是 strcmp 字串比較,字串比較
其實有很多種不同型式的函數,每一種字串比較的函數都
專題報告-貨品存取操作系統之探討 2013/06/19
38
有一些些的不同,所以當時在寫這個地方的時候,查了一
堆的資料。還有在副程式的時候,因為我們的副程式寫在
主程式後面,所以主程式前面應該要宣告,但是我們不知
道要怎麼宣告,宣告甚麼,還好我們在老師的幫忙下解決
了,不然我們的程式可能在這卡關很久。
其實這個程式並不難,只是有一些新學的東西,要重
新堆起新的邏輯,但我們有老師的幫忙,使我們腦袋的東
西加速吸收,也使我們更加輕鬆的完成這個程式。而且也
因為寫這個程式,使我們把以前一些不懂得和錯誤的觀念
搞清楚,也使我們的實力有上一層的感覺。
這個程式不只可以用來記東西的數量、廠商、跟價格
喔!只要稍稍的改一下程式碼,他就可以變成重要東西放
置位子的程式了。
專題報告-貨品存取操作系統之探討 2013/06/19
39
 林于珊
自從知道系上有一門必修專題課後,就開始摸索自己
對哪一方面的知識比較有興趣,是統計方面、軟體方面還
是程式方面呢?經過大一大二各種的課程訓練後,發現自
己是對程式比較有興趣,因此開始尋找與我志同道合的人,
終於我找到了三位與我一樣對程式感到興趣且都想找楊
建成老師指導的同學。
專題這門課是設在大三下,但是我們從大三上就開始
找老師討論了。一開始我們原本想要做一個以賣場庫存系
統為主體的資料庫系統,為了更了解賣場的需求,我們有
人去訪問賣場的管理人員他們對對於庫存系統有什麼需
求,還有人去賣場打工想了解他們實際上可能會用到什麼
樣的功能。經過一個寒假後,為了完成完整的資料庫系統,
經過討論我們決定利用 MySQL 去完成我們的專題,但是
MySQL 並不是大家熟悉的軟體,要完全熟悉它並運用它
可能要花一段時間,所以最後在與老師幾番討論後,決定
以最原始的方式-「程式」來呈現我們的專題。
一開始在專題這門課,由於我們對撰寫庫存系統程式
一知半解根本不知該如何著手去做,因此老師還特地利用
專題報告-貨品存取操作系統之探討 2013/06/19
40
他的空堂時間教導我們如何去處理一個團隊程式處理步
驟及注意事項,並教導我們許多在以前沒有接觸過的程式
概念,如 struct。
從 Dev C++ 程式裡開新原始碼檔開始,看著它由一面
空白頁變成滿滿兩百多行的程式碼,想到臉上不禁多了抹
微笑,再想到撰寫程式時所遇到的困難一一被被我們擊敗
更是開心啦。在大略完成我們的程式並編譯後,發現了第
一個大問題-排序的問題在經過搜尋許多相關資料以及
老師的講解、幫忙後終於成功排解了,雖然在除完其他
bug 後發現它似乎還是存在著些許問題,但並不影響執行
結果。這個程式只包含新增、查詢、修改、刪除四項基本
的功能看起來並不起眼,但是它卻是庫存系統中的核心。
庫存系統沒有它,就像是空心蘿蔔一樣虛有其表,沒有什
麼用處。
完成了這專題,除了學習到了一些新知識以外,最大
的收穫就是瞭解團隊合作的精神;一群人為了同一個目標
邁進,即使過程辛苦,擁有的歡笑還是勝過一切。
專題報告-貨品存取操作系統之探討 2013/06/19
41
 孫莉筑
透過這一次的專題讓我們學習到了很多東西,不僅僅
是在寫程式方面的進步,更讓我們學習到團隊合作的重要
性,這些都是平常在課堂上所學不到的,從一開始我們對
「資料庫系統」這個專題名稱毫無頭緒,到做出這一個有
新增、修改、刪除、查詢的程式,在整個過程中我們由老
師的建議和討論逐漸縮小目標,使整個目標更明確之後,
先做出整個程式大概的樣子,再藉由一次又一次反覆的修
改才完成,也因為我們有實際動手操作之後,才知道我們
需要加強的是哪一方面的知識,從這裡下手去找資料、尋
求協助,雖然做出這個專題的過程很辛苦,但是收穫也非
常多,這一次的專題研究是我們難得且可貴的經驗。

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

貨品存取與操作系統之探討