哈工大C语言知识课程规划设计.doc
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_05.gif)
《哈工大C语言知识课程规划设计.doc》由会员分享,可在线阅读,更多相关《哈工大C语言知识课程规划设计.doc(23页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。
1、#+Harbin Institute of Technology课程设计说明书(论文)课程名称: C语言课程设计 设计题目: 音乐程序与波特图 院 系:航天学院控制科学与工程系班 级: 设 计 者: 学 号: 指导教师: 设计时间: 哈尔滨工业大学教务处哈尔滨工业大学课程设计任务书 姓 名: 院 (系): 专 业: 班 号: 任务起至日期: 年月日至 年 月 日 课程设计题目: 已知技术参数和设计要求: 工作量: 工作计划安排: 同组设计者及分工: 指导教师签字_ 年 月 日 教研室主任意见: 教研室主任签字_ 年 月 日*注:此任务书由课程设计指导教师填写。#+题目一1.1 题目详细描述:播
2、放音乐程序,实现了自选音乐曲目和直接使用键盘弹奏,而且可以在曲目播放结束后循环选择乐曲。开始1.2 程序设计思路及流程图:绘制文本背景并功能说明打印用户选择曲目,或者选择自己利 用键盘弹奏。选择歌曲弹奏放歌是否继续 是 结束1.3 程序清单及注释:#include #include #include #include #include #include #define N1 16#define N2 8#define N4 4#define N8 2#define N16 1#define END 0void playmusic(int n,int *c);void typemusic();e
3、num NOTESC10=131,D10=147,E10=165,F10=175,G10=196,A10=220,B10=247,C0=262,D0=296,E0=330,F0=349,G0=392,A0=440,B0=494,C1=523,D1=587,E1=659,F1=698,G1=784,A1=880,B1=988,C2=1047,D2=1175,E2=1319,F2=1397,G2=1568,A2=1760,B2=1976,S=10;typedef enum NOTES SONG;SONG song1=C0,N4+N2,E0,N4,G0,N2,G0,N2,A0,N1,G0,N1,E0
4、,N4+N2, C0,N4,G0,N1/3,G0,N1/3,G0,N1/3,E0,N1,C0,N1,G10,N1/3,G10,N1/3, G10,N1/3,G10,N1/3,G10,N1/3,G10,N1/3,C0,N1,END,END;SONG song2=A0,N2,B0,N2,C1,N1+N2,B0,N2,C1,N1,E1,N1,B0,N1+N1,S,N1,E0,N1, A0,N1+N2,G0,N2,A0,N1,C1,N1,G0,N1+N1,S,N1,E0,N2,E0,N2,F0, N1+N2,E0,N2,F0,N1,C0,N1,E0,N1+N1,S,N1,C1,N2,C1,N2,B0,
5、N1+N2,370, N2,F0,N1,B0,N1,B0,N1+N2,S,N1,A0,N2,B0,N2,C1,N1+N2,B0,N2,C1,N1, E1,N1,B0,N1+N2,END,END;int main() int m,n,c=1; char b=y; while(b=y) printf(Hello,what do you want to do by this program?n); printf(1.Listen to music.-Press 1n); printf(2.Play music by yourself.-Press 2n); scanf(%d,&m); while(m
6、!=1&m!=2&m!=3) /*选择方式*/ printf(You typed wrong!Do not push me around.:(n); scanf(%d,&m); if(m=1) printf(I have two musics,choose one!(Press 1/2)n); scanf(%d,&n); while(n!=1&n!=2) printf(You typed wrong!Do not push me around.:(n); scanf(%d,&n); playmusic(n,&c); else if(m=2) typemusic(); getchar(); pr
7、intf(Do you want to continue?(y/n)n); scanf(%c,&b); return 0;void playmusic(int n,int *c) int note=0,fre,dur,control; char d; clock_t goal; if(n=1) while(song1note!=END) fre=*c*song1note; dur=song1note+1; if(kbhit() break; if(fre) /*若频率值fre非0*/ outportb(0x43,0xb6); /*初始化2号定时器 */ fre=(unsigned)(11931
8、80L/fre); /*计算计数初值 */ outportb(0x42,(char)fre); /*先写计数初值的低8位*/ outportb(0x42,(char)(fre8); /*再写计数初值的高8位*/ control=inportb(0x61); /*读0x61的状态*/ outportb(0x61,control|0x03); /*将第0位,第1位置1,使喇叭发声*/ goal=(clock_t)dur+clock( ); while(goalclock( ); if(dur) outportb(0x61,control); note+=2; else while(song2not
9、e!=END) fre=*c*song2note; dur=song2note+1; if(kbhit() break; if(fre) /*若频率值fre非0*/ outportb(0x43,0xb6); /*初始化2号定时器 */ fre=(unsigned)(1193180L/fre); /*计算计数初值 */ outportb(0x42,(char)fre); /*先写计数初值的低8位*/ outportb(0x42,(char)(fre8); /*再写计数初值的高8位*/ control=inportb(0x61); /*读0x61的状态*/ outportb(0x61,contro
10、l|0x03); /*将第0位,第1位置1,使喇叭发声*/ goal=(clock_t)dur+clock( ); while(goalclock( ); if(dur) outportb(0x61,control); note+=2; getchar(); printf(Do you want to raise/lower the frequency? Press r/lnIf you do not want press nn); scanf(%c,&d); if(d=r) *c*=2; else if(d=l) *c*=0.5; else if(d=n) *c=*c;void typemu
11、sic() char ch; clock_t goal; int fre=0,control,dur=2; printf(Play your own music!n(You can play on the keyboard by pressing Z-M,A-J,Q-U,1-7)n); printf(If you are bored press /n); do ch=getch(); if(ch=/); else switch(ch) case z:fre=C10;break; case x:fre=D10;break; case c:fre=E10;break; case v:fre=F10
12、;break; case b:fre=G10;break; case n:fre=A10;break; case m:fre=B10;break; case a:fre=C0;break; case s:fre=D0;break; case d:fre=E0;break; case f:fre=F0;break; case g:fre=G0;break; case h:fre=A0;break; case j:fre=B0;break; case q:fre=C1;break; case w:fre=D1;break; case e:fre=E1;break; case r:fre=F1;br
13、eak; case t:fre=G1;break; case y:fre=A1;break; case u:fre=B1;break; case 1:fre=C2;break; case 2:fre=D2;break; case 3:fre=E2;break; case 4:fre=F2;break; case 5:fre=G2;break; case 6:fre=A2;break; case 7:fre=B2;break; default:printf(You typed wrong!Do not push me around.:(n); if(fre) /*若频率值fre非0*/ outp
14、ortb(0x43,0xb6); /*初始化2号定时器 */ fre=(unsigned)(1193180L/fre); /*计算计数初值 */ outportb(0x42,(char)fre); /*先写计数初值的低8位*/ outportb(0x42,(char)(fre8); /*再写计数初值的高8位*/ control=inportb(0x61); /*读0x61的状态*/ outportb(0x61,control|0x03); /*将第0位,第1位置1,使喇叭发声*/ goal=(clock_t)dur+clock( ); /* clock()是计时函数,而与其相关的数据类型是cl
15、ock_t,返回当前程序占用的CPU时间,用clock()返回的值除于CLOCK_PER_SEC常量可以得到当前程序的运行时间,单位是秒 */ while(goalclock( ); if(dur) outportb(0x61,control); while (ch!=/);1.4 程序运行结果及自评:1.5 程序调试中遇到过的问题及解决办法在编辑弹奏的程序时,没有弄明白延时函数,无法让按键发声,后来明白了延时函数的原理,把时长设成4,就可以了,还有就是按/时直接退出,后来把if放到前面,就解决了。题目二2.1 题目详细描述: 开始2.2 程序设计思路及流程图:选择所绘制曲线图形下绘制背景及坐
16、标 输出图形下标注每隔一定时间画两点间的坐标计算各点坐标值判断是否退出循环2.3 程序清单及注释:#include #include #include #include float data1(float k,float m);float data2(float k,float m);void drawpic1();void drawpic2();void drawpic3();void h1(float z,float x1,int m);void h2(float z,float x1,int m);int main() int a; char c=y; while(c=y) /*重复选择
17、*/ printf(G(jw)=1/(1-w2*T2+2jwTn); printf(Choose the Bode Diagram:n); printf(1.Magnitude(dB)n); printf(2.Phase(deg)n); printf(3.Bothn); scanf(%d,&a); /*选择画图*/ while(a!=1&a!=2&a!=3) /*试错*/ printf(Do not push me around.:(); scanf(%d,&a); if(a=1) drawpic1(); /*画第一个*/ else if(a=2) drawpic2(); /*画第二个*/ e
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 哈工大 语言 知识 课程 规划 计划 设计
![提示](https://www.deliwenku.com/images/bang_tan.gif)
限制150内