哈工大C语言知识课程规划设计

上传人:新*** 文档编号:107356542 上传时间:2019-10-19 格式:DOC 页数:23 大小:383.50KB
返回 下载 相关 举报
哈工大C语言知识课程规划设计_第1页
第1页 / 共23页
哈工大C语言知识课程规划设计_第2页
第2页 / 共23页
哈工大C语言知识课程规划设计_第3页
第3页 / 共23页
哈工大C语言知识课程规划设计_第4页
第4页 / 共23页
哈工大C语言知识课程规划设计_第5页
第5页 / 共23页
点击查看更多>>
资源描述

《哈工大C语言知识课程规划设计》由会员分享,可在线阅读,更多相关《哈工大C语言知识课程规划设计(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,control|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; e

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 高等教育 > 专业基础教材

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号