




已閱讀5頁,還剩20頁未讀, 繼續(xù)免費(fèi)閱讀
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
課程設(shè)計(jì)說明書設(shè)計(jì)題目: 創(chuàng)建和修改表的定義 _專 業(yè): 計(jì)算機(jī)科學(xué)與技術(shù) 班 級: _設(shè) 計(jì) 人: _山東科技大學(xué)2012年 06月 20 日課程設(shè)計(jì)任務(wù)書學(xué)院 信息科學(xué)與工程學(xué)院 專業(yè) 計(jì)算機(jī)科學(xué)與技術(shù) 班級 姓名一、 課程設(shè)計(jì)題目:(1) 創(chuàng)建和修改表的定義 二、 課程設(shè)計(jì)主要參考資料:(1) 數(shù)據(jù)庫系統(tǒng)概論 (2) c語言程序設(shè)計(jì) (3) 數(shù)據(jù)結(jié)構(gòu) 三、 課程設(shè)計(jì)應(yīng)解決的主要問題:1.選擇一種高級語言實(shí)現(xiàn)一個簡單的dbms主要功能: 實(shí)現(xiàn):create table (, ) 實(shí)現(xiàn):alter table add dropmodify 要求:(1)設(shè)計(jì)實(shí)現(xiàn)表的物理存儲結(jié)構(gòu);(2)語句以命令行和圖形化界面兩種形式實(shí)現(xiàn);(3)提交課程設(shè)計(jì)報告。四、 課程設(shè)計(jì)相關(guān)附件(如:圖紙、軟件等):(1) (2) (3) 五、 任務(wù)發(fā)出日期: 課程設(shè)計(jì)完成日期: 指導(dǎo)教師簽字: 系主任簽字: 指導(dǎo)教師對課程設(shè)計(jì)的評語指導(dǎo)教師簽字: 2012年 月 日山東科技大學(xué)學(xué)生課程設(shè)計(jì)一、 設(shè)計(jì)要求:(1)設(shè)計(jì)實(shí)現(xiàn)表的物理存儲結(jié)構(gòu);(2)語句以命令行和圖形化界面兩種形式實(shí)現(xiàn);(3)提交課程設(shè)計(jì)報告。二、 需求分析:1.選擇一種高級語言實(shí)現(xiàn)一個簡單的dbms 設(shè)計(jì)實(shí)現(xiàn)表的物理存儲結(jié)構(gòu);語句以命令行和圖形化界面兩種形式實(shí)現(xiàn);三、 設(shè)計(jì)思想:(1) 由命令行輸入sql語句, 通過對語句進(jìn)行語法分析,分離關(guān)鍵字,語句以分號作為結(jié)束符號; (2) 以 *.txt 文件存放建立的表,一張表對應(yīng)一個 *.txt 文件;(3) 用戶可直接輸入create table 語句和alter語句, 程序自動解析和查錯, output語句輸出表的相關(guān)信息。四、 主要源程序:/源程序在codeblocks 10.05下運(yùn)行通過#include#include#include#include#include#include#include#includeusing namespace std;#define max 1000#define n 100/表中每個域的結(jié)構(gòu):struct field char namen; char typen; int len; char conditionn; field() len = 0; name0 = type0 = condition0 = 0; ;/讀入的語句字符串char sqlmax,sqltmpmax;/將輸入的大寫字母轉(zhuǎn)化為小寫字母void tolower(char *s) int len = strlen(s); for(int i = 0; i = a & si = z) si += 32; /讀入sql語句,并進(jìn)行格式化分離單詞, 以分號結(jié)束, esc退出整個程序int read() char c; int i; for(i = 0; c = getch(); i+) if(c = ;) break; if(c = 27) exit(0); if(c = 8) i -= 2; if(i -1) i = -1; system(cls); printf(:nplease input the sql sentence:nn); for(int j = 0; j tmp; if( 0 != strcmp(tmp,create) error = true; printf(nthe word create maybe error!n); else ss tmp; if(0 != strcmp(tmp,table) error = true; printf(nthe word table maybe error!n); else ss table_name; int len = strlen(table_name); strcat(table_name, .txt); if(access(table_name, 0) = 0) printf(the table already exist! over it?y/nn); char c; c = getchar(); if(c = n) return false; else remove(table_name); while(true) field field; ss tmp; if(tmp0 = ,) add(field, table_name); continue; if(strcmp(tmp, ;) = 0) break; strcpy(, tmp); if(!(ss tmp) break; if(tmp0 = ,) add(field, table_name); continue; bool flg = false; for(int i = 0; i tmp; if(tmp0 = ,) add(field, table_name); continue; bool flg = true; int len = strlen(tmp); int sum = 0; for(int i = 0; i 58 | tmpi tmp; if(tmp0 = ,) add(field, table_name); continue; if(0 = strcmp(tmp,primary) char stn; ss st; if( 0 = strcmp(st,key) strcat(tmp, key); strcpy(field.condition, tmp); else error = true; printf(the word key maybe error!n); break; else if(strcmp(tmp,unique)=0) strcpy(field.condition, tmp); add(field, table_name); return (!error);/修改表函數(shù)bool alter() char tmpn; char table_namen; bool error = false; char type610= char,int,float,double,time,date; stringstream ss(sql); ss tmp; if( 0 != strcmp(tmp,alter) error = true; printf(nthe word alter maybe error!n); else ss tmp; if(0 != strcmp(tmp,table) error = true; printf(nthe word table maybe error!n); else ss table_name; strcat(table_name, .txt); if(access(table_name, 0) = -1) printf(the table do not exist!n); return false; ss tmp; if(strcmp(tmp, add) = 0) ss tmp; field field; strcpy(, tmp); ss tmp; bool flg = false; for(int i = 0; i tmp; bool flg = true; int len = strlen(tmp); int sum = 0; for(int i = 0; i 58 | tmpi tmp; if(0 = strcmp(tmp,primary) char stn; ss st; if( 0 = strcmp(st,key) strcat(tmp, key); strcpy(field.condition, tmp); else error = true; printf(the word key maybe error!n); return false; else if(strcmp(tmp,unique)=0) strcpy(field.condition, tmp); file *fp = fopen(table_name, a); fwrite(&field, sizeof(field), 1, fp); fclose(fp); else if(strcmp(tmp, drop) = 0) ss tmp; if(0 = strcmp(tmp,primary) char stn; ss st; if( 0 != strcmp(st,key) error = true; printf(the word key maybe error!n); return false; else strcat(tmp, key); field fieldn; int len = 0; file *fp = fopen(table_name, r); while(fread(&fieldlen, sizeof(field), 1, fp) != 0) +len; fclose(fp); remove(table_name); printf(%dn, len); for(int i = 0; i len; +i) if(strcmp(fieldi.condition, tmp) = 0) fieldi.condition0 = 0; fp = fopen(table_name, w); fwrite(&field0, sizeof(field), 1, fp); fclose(fp); for(int i = 1; i tmp; ss tmp; char stn; int sum = 0; ss st; bool flg = false; for(int i = 0; i t; bool flg = true; int len = strlen(t); for(int i = 0; i 58 | ti 48) flg = false; break; else sum = sum * 10 + ti - 0; if(!flg) error = true; printf(nthe length of the type maybe error!n); return false; field fieldn; int len = 0; file *fp = fopen(table_name, r); while(fread(&fieldlen, sizeof(field), 1, fp) != 0) +len; fclose(fp); remove(table_name); for(int i = 0; i len; +i) if(strcmp(, tmp) = 0) strcpy(fieldi.type, st); fieldi.len = sum; break; fp = fopen(table_name, w); fwrite(&field0, sizeof(field), 1, fp); fclose(fp); for(int i = 1; i len; +i) fp = fopen(table_name, a); fwrite(&fieldi, sizeof(field), 1, fp); fclose(fp); return (!error);/輸出表的相關(guān)信息void output(char *s) if(access(s, 0) = -1) printf(the table do not exist!n); return ; printf(*n); printf( name type length conditionn); printf(*n); file *fp = fopen(s, r); field field; while(fread(&field, sizeof(field), 1, fp) != 0) printf(%10s, ); if(field.type0 != 0) printf( %10s, field.type); else printf( ); if(field.len != 0) printf( %10d, field.len); else printf( ); if(field.condition0 != 0) printf( %10s, field.condition); else printf( ); puts(); fclose(fp); printf(*n);/程序主函數(shù),循環(huán)讀入, 直到讀到escint main() while(true) printf(:nplease input the sql sentence:nn); read(); stringstream ss(sql); char sn; ss s; if(strcmp(s, create) = 0) if(create() printf(create successful!n); else printf(create failed!n); else if(strcmp(alter, s) = 0) if(alter() printf(alter successful!n); else printf(alter failedn); else if(strcmp(output, s) = 0) ss s; strcat(s, .txt); output(s); ret
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 安全注射單選試題及答案
- 基于區(qū)塊鏈技術(shù)的2025年互聯(lián)網(wǎng)+政務(wù)服務(wù)安全與可信度提升與實(shí)踐報告001
- 2025年直播電商主播影響力測評與定制化營銷策略研究報告
- 南京網(wǎng)絡(luò)課件師培訓(xùn)
- 顧問式營銷培訓(xùn)課件
- 制圖基本技術(shù)課件
- 腫瘤重點(diǎn)??平ㄔO(shè)成果匯報
- 脂肪瘤護(hù)理診斷
- 中國入境旅游課件下載
- 中國兒童文學(xué)史課件
- MicroLED顯示技術(shù)產(chǎn)業(yè)化項(xiàng)目可行性研究報告(范文模板)
- 2025浙江中考:生物必背知識點(diǎn)
- 2025年國家開放大學(xué)《會計(jì)案例分析》形成性考核123答案+終結(jié)性考核答案
- 股權(quán)質(zhì)押融資與境外投資合作協(xié)議
- 汽油清凈性評價 汽油機(jī)進(jìn)氣閥沉積物模擬試驗(yàn)法 編制說明
- 沂蒙精神考試試題及答案
- 2024-2025學(xué)年人教版一年級下冊美術(shù)期末考試卷及參考答案
- 2024北京豐臺區(qū)五年級(下)期末語文試題及答案
- 2025年貴州燃?xì)饧瘓F(tuán)貴安新區(qū)燃?xì)庥邢薰菊衅腹P試參考題庫附帶答案詳解
- 旅行社計(jì)調(diào)國家職業(yè)技能標(biāo)準(zhǔn)
- 2025克拉瑪依市輔警考試試卷真題
評論
0/150
提交評論