正弦函數(shù)的圖形表示_第1頁(yè)
正弦函數(shù)的圖形表示_第2頁(yè)
正弦函數(shù)的圖形表示_第3頁(yè)
正弦函數(shù)的圖形表示_第4頁(yè)
正弦函數(shù)的圖形表示_第5頁(yè)
已閱讀5頁(yè),還剩23頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

1、沈 陽(yáng) 航 空 工 業(yè) 學(xué) 院 課程設(shè)計(jì)學(xué) 號(hào) _2_班 級(jí) _ 姓 名 _李百川_指導(dǎo)教師 _劉成_2007年 月 日XXV / 28文檔可自由編輯打印課程設(shè)計(jì)任務(wù)書院系:電子工程系 專業(yè):電子信息工程 班級(jí):6402104學(xué)號(hào):2題目:正弦函數(shù)的圖形表示一、課程設(shè)計(jì)時(shí)間2007年9月10日至2007年9月14日,共計(jì)1周,20學(xué)時(shí)。二、課程設(shè)計(jì)內(nèi)容用C語(yǔ)言編寫軟件完成以下任務(wù):在圖形模式下,繪制正弦函數(shù)sin(x)在x1x2之間的圖形。注意:此程序必須用TC2.0編寫。三、課程設(shè)計(jì)要求1. 程序質(zhì)量:² 貫徹結(jié)構(gòu)化的程序設(shè)計(jì)思想。² 用戶界面友好,功能明確,操作方便。&

2、#178; 用戶界面中的菜單至少應(yīng)包括“輸入x的區(qū)間”、“開始繪制”、“退出”3項(xiàng)。² 代碼應(yīng)適當(dāng)縮進(jìn),并給出必要的注釋,以增強(qiáng)程序的可讀性。2. 課程設(shè)計(jì)說明書:課程結(jié)束后,上交課程設(shè)計(jì)說明書和源程序。課程設(shè)計(jì)說明書的格式和內(nèi)容參見提供的模板。四、指導(dǎo)教師和學(xué)生簽字指導(dǎo)教師:_劉成_ 學(xué)生簽名:_李百川_五、成績(jī):六、教師評(píng)語(yǔ): 目錄一、需求分析二、程序流程圖三、核心技術(shù)的實(shí)現(xiàn)說明及相應(yīng)程序段四、個(gè)人總結(jié)五、參考文獻(xiàn)六、源程序一、需求分析經(jīng)過對(duì)程序設(shè)計(jì)題目的分析可知,整個(gè)程序的設(shè)計(jì)實(shí)現(xiàn)大致分為三大模塊,其中他們的功能分別是:繪制圖象(Strat Up)、函數(shù)參數(shù)的設(shè)定(Settin

3、gs)、退出(Quit)。在這些函數(shù)當(dāng)中,繪制圖象(Strat Up)又包括菜單欄的繪制,函數(shù)圖形及坐標(biāo)軸的繪制和函數(shù)的縮放與移動(dòng);函數(shù)參數(shù)的設(shè)定(Settings)包括函數(shù)Y=ASin(Bx)+C的參數(shù)A、B、C及X的區(qū)間MinXMaxX.二、程序流程圖 整體框架圖 Y=ASin(Bx)+C開 始輸入目錄選項(xiàng)Start Now(繪圖) Settings (參數(shù)設(shè)定)Quit(退出)0.Set A (參數(shù)A的設(shè)定)1.Set B (參數(shù)B的設(shè)定)2.Set C (參數(shù)C的設(shè)定)3.Set MinX (X的最小值)4.Set MaxX (X的最大值)5.Back (返回)輸入函數(shù)Y=ASin(B

4、x)+C的各項(xiàng)參數(shù)A、B、C及X的區(qū)間范圍MinXMaxX的值void StartUp() Initialize(); Start(); Draw();Pause();void Initialize()int GD=VGA; int GM=VGAHI; int ErrorC; clrscr(); initgraph(&GD,&GM,""); ErrorC=graphresult(); if (ErrorC!=0) printf("Graphics System ERROR"); exit(1); cleardevice();void St

5、art() setcolor(RED); settextstyle(TRIPLEX_FONT,0,9); outtextxy(120,180,"Welcome"); setcolor(YELLOW); settextstyle(0,0,1); outtextxy(6,470,"Press Any Key."); getch(); cleardevice(); setfillstyle(SOLID_FILL,7); setlinestyle(0,0,1); bar(0,0,639,479); setfillstyle(SOLID_FILL,BLUE); b

6、ar(1,1,638,12); Title("Function Graphics V0.1"); DrawRect(3,465,636,476); DrawMenuBar(); Inform("Ready!"); /*/int ScreenX(double x)/*數(shù)學(xué)座標(biāo)轉(zhuǎn)換為屏幕坐標(biāo)*/ return (316+ZOOM*x+RX*ZOOM);int ScreenY(double y) return (211-ZOOM*y+RY*ZOOM);繪制函數(shù)圖象及功能模塊圖void DrawAxis(int maxx,int maxy,int minx,in

7、t miny) int i; setcolor(GREEN); line(ScreenX(minx),ScreenY(0),ScreenX(maxx),ScreenY(0); line(ScreenX(0),ScreenY(miny),ScreenX(0),ScreenY(maxy); for(i=minx;i<=maxx;i+) if(i%10=0) line(ScreenX(i),ScreenY(-1),ScreenX(i),ScreenY(1); for(i=miny;i<=maxy;i+) if(i%10=0) line(ScreenX(-1),ScreenY(i),Scr

8、eenX(1),ScreenY(i); void Draw() double x,y,y2; int MaxY,MinY; DrawRect(3,37,636,460); setviewport(4,38,635,459,1); setfillstyle(1,7); bar(0,0,640,480); MaxY=211/ZOOM; MinY=-211/ZOOM; DrawAxis(MaxX,MaxY,MinX,MinY); setcolor(RED); setlinestyle(0,0,1); for(x=MinX;x<=MaxX;x+=1.0/Q) y=Function(x); y2=

9、Function(x+1.0/Q); line(ScreenX(x),ScreenY(y),ScreenX(x+1.0/Q),ScreenY(y2); int ScreenX(double x) return (316+ZOOM*x+RX*ZOOM);int ScreenY(double y) return (211-ZOOM*y+RY*ZOOM);double Function(double x) return (A*sin(B*x)+C);void ZoomIn() if(ZOOM*1.5<=80) ZOOM*=1.5; Draw(); Inform("ZoomIn&quo

10、t;);void ZoomOut() if(ZOOM/1.5>=1.5) ZOOM/=1.5; Draw(); Inform("ZoomOut");void MoveUp() if(RY-1>=-15) RY-=1; Draw(); Inform("MoveUp");void MoveDown() if(RY+1<=15) RY+=1; Draw(); Inform("MoveDown");void MoveLeft() if(RX-1>=-15) RX-=1; Draw(); Inform("Mov

11、eLeft");void MoveRight() if(RX+1<=15) RX+=1; Draw(); Inform("MoveRight");(1)菜單界面(2)函數(shù)參數(shù)設(shè)置(3)函數(shù)區(qū)間設(shè)置(4)歡迎屏幕(5)函數(shù)圖象(6)函數(shù)的縮放(7)函數(shù)的上下移動(dòng)(8)函數(shù)的左右移動(dòng)三、核心技術(shù)的實(shí)現(xiàn)說明及相應(yīng)程序段void StartUp()/* 圖形環(huán)境啟動(dòng)*/ Initialize(); Start(); Draw(); Pause();/*/void Initialize()/* 圖形設(shè)備初始化*/ int GD=VGA; int GM=VGAHI; i

12、nt ErrorC; clrscr(); initgraph(&GD,&GM,""); ErrorC=graphresult(); if (ErrorC!=0) printf("Graphics System ERROR"); exit(1); cleardevice();/*/void Start()/* 歡迎屏幕及視圖初始化*/ setcolor(RED); settextstyle(TRIPLEX_FONT,0,9); outtextxy(120,180,"Welcome"); setcolor(YELLOW);

13、 settextstyle(0,0,1); outtextxy(6,470,"Press Any Key."); getch(); cleardevice(); setfillstyle(SOLID_FILL,7); setlinestyle(0,0,1); bar(0,0,639,479); setfillstyle(SOLID_FILL,BLUE); bar(1,1,638,12); Title("Function Graphics V0.1"); DrawRect(3,465,636,476); DrawMenuBar(); Inform(&quo

14、t;Ready!"); /*/int ScreenX(double x)/*數(shù)學(xué)座標(biāo)轉(zhuǎn)換為屏幕坐標(biāo)*/*對(duì)于屏幕坐標(biāo)而言,它的X軸坐標(biāo)與數(shù)學(xué)坐標(biāo)的正方向相同,而Y軸的坐標(biāo)相反*/ return (316+ZOOM*x+RX*ZOOM);int ScreenY(double y) return (211-ZOOM*y+RY*ZOOM);void MoveUp() if(RY-1>=-15) RY-=1; Draw(); Inform("MoveUp");void MoveDown() if(RY+1<=15) RY+=1; Draw(); Inform(

15、"MoveDown");void MoveLeft() if(RX-1>=-15) RX-=1; Draw(); Inform("MoveLeft");void MoveRight() if(RX+1<=15) RX+=1; Draw(); Inform("MoveRight");/*/* 圖形縮放*/void ZoomIn() if(ZOOM*1.5<=80) ZOOM*=1.5; Draw(); Inform("ZoomIn");void ZoomOut() if(ZOOM/1.5>=1

16、.5) ZOOM/=1.5; Draw(); Inform("ZoomOut");/* 目錄的選擇功能實(shí)現(xiàn)*/switch(getch()case 0: ;break;case 1: ;break;case 2: ;判斷所輸入的數(shù)據(jù)是否符合要求:void SetA() do printf("nPlease Input A(-1010):"); scanf("%f",&A); if (A*A>100) printf("Input Wrong(-1010)! Try Again.n"); while(A*

17、A>100);void SetB() do printf("nPlease Input B(-1010):"); scanf("%f",&B); if (B*B>100) printf("Input Wrong(-1010)! Try Again.n"); while(B*B>100);void SetC() do printf("nPlease Input C(-1010):"); scanf("%f",&C); if (C*C>100) printf(

18、"Input Wrong(-1010)! Try Again.n"); while(C*C>100);/*/* 區(qū)間設(shè)置*/void SetMaxX() do printf("nPlease Input Max X(-100100):"); scanf("%f",&MaxX); if (MaxX*MaxX>10000|MaxX<=MinX) printf("Input Wrong.(-100100),And MaxX>MinX! Try Again.n"); while(MaxX*M

19、axX>10000|MaxX<=MinX);void SetMinX() do printf("nPlease Input Min X(-100100):"); scanf("%f",&MinX); if (MinX*MinX>10000|MaxX<=MinX) printf("Input Wrong.(-100100),And MinX<MaxX! Try Again.n"); while(MinX*MinX>10000|MaxX<=MinX);四、個(gè)人總結(jié)通過這次C語(yǔ)言的課設(shè)實(shí)踐活

20、動(dòng),使我充分的體會(huì)到自己的不足。這讓我在實(shí)踐中對(duì)C語(yǔ)言又有了一個(gè)全新的認(rèn)識(shí)。這讓我在了解到自己的不足的同時(shí),使自己對(duì)C語(yǔ)言的掌握又加深了一步。尤其是在這次實(shí)踐活動(dòng)中,我的課題:繪制函數(shù)SinX的過程中了解了更多的知識(shí),對(duì)于C語(yǔ)言的繪圖有了一定的掌握。使得自己可以運(yùn)用程序畫出簡(jiǎn)單的函數(shù)圖象。在對(duì)C語(yǔ)言繪制圖形的過程中,讓自己了解到不少東西,如數(shù)學(xué)坐標(biāo)轉(zhuǎn)換成屏幕坐標(biāo),菜單欄及歡迎屏幕的制作,圖形的縮放及移動(dòng),圖形的顏色和立體感上也有了一定的了解,并可以進(jìn)行一些簡(jiǎn)單的操作等五、參考文獻(xiàn)1 譚浩強(qiáng)C程序設(shè)計(jì)北京:清華大學(xué)出版社,2005六、源程序/* 編譯預(yù)處理*/#include <graph

21、ics.h>#include <stdio.h>#include <stdlib.h>#include <math.h>#include <dos.h>#include <string.h>#define ESC 0x1b#define MENU struct menu/*#*/* 菜單結(jié)構(gòu)體*/struct menu char Name16; int Value; void (*Function)();/*#*/* 全局變量*/int RX=0,RY=0;double ZOOM=10;int Q=10;float A=1,B=

22、1,C=0;float MaxX=32,MinX=-32;/* 菜單*/MENU Menus3;MENU Menus26;/*#*/* 函數(shù)聲明*/void m();void Initialize();void Start();void Draw();void DrawMenuBar();void ZoomIn();void ZoomOut();void Pause();void Title(char * str);void Inform(char * str);void DrawMenu(MENU * m,int,int,int,int);void DrawRect(int,int,int,

23、int);void DrawAxis(int,int,int,int);void MoveUp();void MoveDown();void MoveLeft();void SetMinX();void SetMaxX();void SetA();void SetB();void SetC();void Setting();int MenuInput(MENU * M,int);void ShowMenu(MENU * M,int);void Quit();void MoveRight();void Configure();void StartUp();int ScreenX(double);

24、int ScreenY(double);double Function(double);/*#*/* 程序開始*/*/main()/* 主函數(shù)*/ /*菜單資源初始化*/ strcpy(Menus0.Name,"Start Now") ;Menus0.Value=0 ;Menus0.Function=&StartUp; strcpy(Menus1.Name,"Settings") ;Menus1.Value=1 ;Menus1.Function=&Setting; strcpy(Menus2.Name,"Quit")

25、;Menus2.Value=2 ;Menus2.Function=NULL; strcpy(Menus20.Name,"Set A") ;Menus20.Value=0 ;Menus20.Function=&SetA; strcpy(Menus21.Name,"Set B") ;Menus21.Value=1 ;Menus21.Function=&SetB; strcpy(Menus22.Name,"Set C") ;Menus22.Value=2 ;Menus22.Function=&SetC; strcpy

26、(Menus23.Name,"Set MinX") ;Menus23.Value=3 ;Menus23.Function=&SetMinX; strcpy(Menus24.Name,"Set MaxX") ;Menus24.Value=4 ;Menus24.Function=&SetMaxX; strcpy(Menus25.Name,"Back") ;Menus25.Value=5 ;Menus25.Function=NULL;Configure();/* 進(jìn)入程序*/*/void StartUp()/* 圖形環(huán)境啟動(dòng)

27、*/ Initialize(); Start(); Draw(); Pause();/*/void Initialize()/* 圖形設(shè)備初始化*/ int GD=VGA; int GM=VGAHI; int ErrorC; clrscr(); initgraph(&GD,&GM,""); ErrorC=graphresult(); if (ErrorC!=0) printf("Graphics System ERROR"); exit(1); cleardevice();/*/void Configure()/* 字符環(huán)境主菜單*/ d

28、o clrscr(); printf("#n"); printf("# #n"); printf("# Welcome #n"); printf("# #n"); printf("#n"); ShowMenu(Menus,3); while(MenuInput(Menus,3)!=1); Quit();/*/int MenuInput(MENU *ms,int n)/*菜單輸入*/ int i,a=0; char c; do c=getch(); for(i=0;i<n;i+) if(c=

29、('0'+msi.Value) if (msi.Function=NULL) a=1;break;break; else msi.Function(); break;break; while(i=n); return a;/*/void ShowMenu(MENU *ms,int n)/* 顯示菜單*/ int i; for(i=0;i<n;i+) printf(" %d-%s n",msi.Value,msi.Name); printf("Select:");/*/void Start()/* 歡迎屏幕及視圖初始化*/ setco

30、lor(RED); settextstyle(TRIPLEX_FONT,0,9); outtextxy(120,180,"Welcome"); setcolor(YELLOW); settextstyle(0,0,1); outtextxy(6,470,"Press Any Key."); getch(); cleardevice(); setfillstyle(SOLID_FILL,7); setlinestyle(0,0,1); bar(0,0,639,479); setfillstyle(SOLID_FILL,BLUE); bar(1,1,638,

31、12); Title("Function Graphics V0.1"); DrawRect(3,465,636,476); DrawMenuBar(); Inform("Ready!"); /*/int ScreenX(double x)/*數(shù)學(xué)座標(biāo)轉(zhuǎn)換為屏幕坐標(biāo)*/ return (316+ZOOM*x+RX*ZOOM);int ScreenY(double y) return (211-ZOOM*y+RY*ZOOM);/*/void Setting()/* 字符界面參數(shù)設(shè)置菜單*/ do clrscr(); printf("#n"

32、;); printf("# #n"); printf("# Settings #n"); printf("# y=Asin(B*x)+C #n"); printf("# #n"); printf("#n"); ShowMenu(Menus2,6); while(MenuInput(Menus2,6)!=1);/*/void Draw()/* 繪制函數(shù)圖像*/ double x,y,y2; int MaxY,MinY; DrawRect(3,37,636,460); setviewport(4,3

33、8,635,459,1); setfillstyle(1,7); bar(0,0,640,480); /*MaxX=316/ZOOM;*/ MaxY=211/ZOOM; /*MinX=-316/ZOOM;*/ MinY=-211/ZOOM; DrawAxis(MaxX,MaxY,MinX,MinY); setcolor(RED); setlinestyle(0,0,1); for(x=MinX;x<=MaxX;x+=1.0/Q) y=Function(x); y2=Function(x+1.0/Q); line(ScreenX(x),ScreenY(y),ScreenX(x+1.0/Q)

34、,ScreenY(y2); /*/void DrawMenuBar()/* 繪制菜單條*/ setlinestyle(0,0,1); setcolor(DARKGRAY); line(1,13,638,13); line(1,27,638,27); setcolor(WHITE); line(1,14,638,14); line(1,28,638,28); setcolor(BLACK); settextstyle(DEFAULT_FONT,0,1);/*/* 繪制坐標(biāo)軸*/void DrawAxis(int maxx,int maxy,int minx,int miny) int i; se

35、tcolor(GREEN); line(ScreenX(minx),ScreenY(0),ScreenX(maxx),ScreenY(0); line(ScreenX(0),ScreenY(miny),ScreenX(0),ScreenY(maxy); for(i=minx;i<=maxx;i+) if(i%10=0) line(ScreenX(i),ScreenY(-1),ScreenX(i),ScreenY(1); for(i=miny;i<=maxy;i+) if(i%10=0) line(ScreenX(-1),ScreenY(i),ScreenX(1),ScreenY(i

36、); /*/void Inform(char * str)/* 狀態(tài)欄輸出*/ setviewport(4,466,635,475,1); setfillstyle(1,7); bar(0,0,640,100); setcolor(BLUE); settextstyle(DEFAULT_FONT,0,1); outtextxy(2,1,str); setviewport(0,0,639,479,1);/*/void Pause()/* 程序暫停等待用戶輸入*/ int ExitFlag=0; do switch(getch() case 72: MoveUp(); break; case 80

37、: MoveDown(); break; case 75: MoveLeft(); break; case 77: MoveRight(); break; case 0x3d:ZoomIn(); break; case 0x2d:ZoomOut(); break; case ESC: ExitFlag=1; default: break; while(ExitFlag=0); closegraph();/*/* 繪制立體感邊框*/void DrawRect(int x1,int y1,int x2,int y2) setcolor(DARKGRAY); setlinestyle(0,0,1);

38、 line(x1,y1,x1,y2); line(x1,y1,x2,y1); setcolor(WHITE); line(x2,y1,x2,y2); line(x1,y2,x2,y2);/*/void Title(char * str)/* 標(biāo)題欄輸出*/ setcolor(WHITE); settextstyle(DEFAULT_FONT,0,1); outtextxy(16,3,str);/*/* 圖形移動(dòng)*/void MoveUp() if(RY-1>=-15) RY-=1; Draw(); Inform("MoveUp");void MoveDown() if(RY+1<=15) RY+=1; Draw(); Inform("MoveDown");void MoveLeft() if(RX-1>=-15) RX-=1; Draw(); Inform("MoveLeft");void MoveRight() if(RX+1<=15) RX+=1; Draw(); Inform("MoveRight");/*/* 圖形縮放*/void ZoomIn() if(ZO

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝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ù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 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)論