//Sinh viên : Nguyễn Thanh Phong - Lớp DH10TH – Khoa Công nghệ thông tin - ĐHBRVT
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <dos.h>
#include <stdlib.h>
#include <math.h>
FILE *f;
int i,n;
int chon;
struct kara
{
char ten[30],ma[10];
};
kara list[1000];
float notnhac(char c);
int doclist()
{
textcolor(WHITE);
clrscr();
f = fopen("kara.lst","r");
if (f==NULL) {printf("Khong co file danh sach bai hat."); chon=4; getch(); return 0;}
else
{
i=0;
while (feof(f)==0)
{
i++;
fscanf(f,"%s",&list[i].ma); fscanf(f," %[^\n]",&list[i].ten);
//printf("\n%7s%30s",list[i].ma,list[i].ten);
}
n=i;
fclose(f);
return 1;
              
                                            
                                
            
 
            
                 5 trang
5 trang | 
Chia sẻ: luyenbuizn | Lượt xem: 1493 | Lượt tải: 0 
              
            Nội dung tài liệu Tiểu luận Môn Lập trình C – Phần mềm nhạc hát Karaoke, để tải tài liệu về máy bạn click vào nút DOWNLOAD ở trên
Tiểu luận Môn Lập trình C – Phần mềm nhạc hát Karaoke – khoa Công nghệ thông tin –
ĐHBRVT tinvn.com.vn 
1 
//Sinh viên : Nguyễn Thanh Phong - Lớp DH10TH – Khoa Công nghệ thông tin - ĐHBRVT 
#include 
#include 
#include 
#include 
#include 
#include 
FILE *f; 
int i,n; 
int chon; 
struct kara 
{ 
 char ten[30],ma[10]; 
}; 
kara list[1000]; 
float notnhac(char c); 
int doclist() 
{ 
 textcolor(WHITE); 
 clrscr(); 
 f = fopen("kara.lst","r"); 
 if (f==NULL) {printf("Khong co file danh sach bai hat."); chon=4; getch(); return 0;} 
 else 
 { 
 i=0; 
 while (feof(f)==0) 
 { 
 i++; 
 fscanf(f,"%s",&list[i].ma); fscanf(f," %[^\n]",&list[i].ten); 
 //printf("\n%7s%30s",list[i].ma,list[i].ten); 
 } 
 n=i; 
 fclose(f); 
 return 1; 
 } 
} 
void danhsach() 
{ 
 if (doclist()==1) 
 { 
 textcolor(WHITE); 
 clrscr(); 
 printf("\n DANH SACH BAI HAT"); 
 printf("\n+=======+==============================+"); 
 printf("\n+ Ma so + Ten bai hat +"); 
 printf("\n+=======+==============================+"); 
 for (i=1;i<=n;i++) 
 { 
 printf("\n|%7s|%30s|",list[i].ma,list[i].ten); 
Tiểu luận Môn Lập trình C – Phần mềm nhạc hát Karaoke – khoa Công nghệ thông tin –
ĐHBRVT tinvn.com.vn 
2 
 printf("\n+-------+------------------------------+"); 
 } 
 getch(); 
 } 
} 
void tim() 
{ 
 if (doclist()==1) 
 { 
 textcolor(WHITE); 
 clrscr(); 
 char bai[100]; 
 printf("\nXin nhap ten bai hat can tim: "); fflush(stdin); gets(bai); 
 for (i=1;i<=n;i++) if (strcmp(strupr(list[i].ten),strupr(bai))==0) break; 
 if (i>n) printf("\nKhong co bai hat %s",bai); 
 else 
 { 
 printf("\n+=======+==============================+"); 
 printf("\n+ Ma so + Ten bai hat +"); 
 printf("\n+=======+==============================+"); 
 printf("\n|%7s|%30s|",list[i].ma,list[i].ten); 
 printf("\n+-------+------------------------------+"); 
 } 
 getch(); 
 } 
} 
void hat() 
{ 
 if (doclist()==1) 
 { 
 textcolor(WHITE); 
 clrscr(); 
 char ma[10]; 
 printf ("\nXin nhap ma bai hat: "); fflush(stdin); gets(ma); 
 for (i=1;i<=n;i++) if(strcmp(list[i].ma,ma)==0) break; 
 if (i>n) printf("\nKhong co bai hat mang ma so %s, ban hay xem lai.",ma); 
 else 
 { 
 f= fopen(ma,"r"); 
 if (f==NULL) printf("\nKhong tim thay file bai hat ma so %s.",ma); 
 else 
 { 
 printf("\nco file"); 
 int j,tong; 
 struct baihat 
 { 
 char loi[15]; 
 char nhac[5]; 
 }; 
Tiểu luận Môn Lập trình C – Phần mềm nhạc hát Karaoke – khoa Công nghệ thông tin –
ĐHBRVT tinvn.com.vn 
3 
 baihat bai[1000]; 
 j=0; 
 while (feof(f)==0&&strcmp(bai[j].loi,"|")!=0) 
 { 
 j++; 
 fscanf(f,"%s",&bai[j].loi); 
 } 
 tong=j-1; 
 //printf ("%d",tong); 
 //for (j=1;j<=tong;j++) printf("%s ",bai[j].loi); 
 j=0; 
 while (feof(f)==0) 
 { 
 j++; 
 fscanf(f,"%s",&bai[j].nhac); 
 } 
 fclose(f); 
 printf ("\n%d loi, %d nhac",tong,j); 
 if (tong!=j) printf("\nSo loi hat va so not nhac khong bang nhau, file nhac bi loi khong 
the hat duoc."); 
 else 
 { 
 printf ("\nok het, hat\n"); 
 textcolor(WHITE); 
 clrscr(); 
 printf("\n%s\n\n",strupr(list[i].ten)); 
 //for (j=1;j<=tong;j++) printf("%s-%s ",bai[j].loi,bai[j].nhac); 
 //printf("%d ",bai[16].loi[strlen(bai[16].loi)-1]); 
 for (j=1;j<=tong;j++) 
 { 
 printf("%s ",bai[j].loi); 
 if(bai[j].loi[strlen(bai[j].loi)-1]==','||bai[j].loi[strlen(bai[j].loi)-1]=='.') 
printf("\n"); 
 } 
 textcolor(YELLOW); 
 gotoxy(1,4); 
 for (j=1;j<=tong;j++) 
 { 
 cprintf("%s ",bai[j].loi); 
 if(bai[j].loi[strlen(bai[j].loi)-1]==','||bai[j].loi[strlen(bai[j].loi)-1]=='.') 
printf("\n"); 
 int quang = bai[j].nhac[1]-48; 
 //printf ("%d ", quang); 
 sound(notnhac(bai[j].nhac[0])*pow(2,quang-1)); 
 delay((100*bai[j].nhac[2])-4500); 
 nosound(); 
 } 
 } 
Tiểu luận Môn Lập trình C – Phần mềm nhạc hát Karaoke – khoa Công nghệ thông tin –
ĐHBRVT tinvn.com.vn 
4 
 } 
 } 
 } 
 getch(); 
}; 
int main(void) 
{ 
 clrscr(); 
 if (doclist()==1) 
 { 
 int tl,dong; 
 char *x[5]; 
 x[1]= "1. Xem danh sa'ch ba`i ha't"; 
 x[2]= "2. Ti`m ba`i ha't"; 
 x[3]= "3. Ha't"; 
 x[4]= "4. Thoa't"; 
 do{ 
 textcolor(WHITE); 
 clrscr(); 
 printf("\nMENU CHUC NANG\n"); 
 for(int i=1;i<=4;i++) printf("\n%s",x[i]); 
 dong=3; 
 tl=72; 
 chon=2; 
 do { 
 if (tl==72&&chon>=2) 
 { 
 chon-=1; 
 textcolor(WHITE); 
 gotoxy(1,chon+1+dong); cprintf("%s",x[chon+1]); 
 textcolor(YELLOW); 
 gotoxy(1,chon+dong); cprintf("%s",x[chon]); 
 } 
 if (tl==80&&chon<=3) 
 { 
 chon+=1; 
 textcolor(WHITE); 
 gotoxy(1,chon-1+dong); cprintf("%s",x[chon-1]); 
 textcolor(YELLOW); 
 gotoxy(1,chon+dong); cprintf("%s",x[chon]); 
 } 
 } while((tl=getch())!=13); 
 switch (chon) 
 { 
 case 1: {danhsach(); break;} 
 case 2: {tim(); break;} 
 case 3: {hat(); break;} 
 } 
Tiểu luận Môn Lập trình C – Phần mềm nhạc hát Karaoke – khoa Công nghệ thông tin –
ĐHBRVT tinvn.com.vn 
5 
 } while(chon!=4); 
 clrscr(); 
 } 
 getch(); 
 return 0; 
} 
float notnhac (char c) 
{ 
 float am=440; 
 switch (c) 
 { 
 case 'a':{am = 55.0000;break;} 
 case 'A':{am = 58.2705;break;} 
 case 'b':{am = 61.7354;break;} 
 case 'B':{am = 65.4064;break;} 
 case 'c':{am = 32.7032;break;} 
 case 'C':{am = 34.6478;break;} 
 case 'd':{am = 36.7081;break;} 
 case 'D':{am = 38.8909;break;} 
 case 'e':{am = 41.2034;break;} 
 case 'E','f':{am = 43.6535;break;} 
 case 'F':{am = 46.2493;break;} 
 case 'g':{am = 48.9994;break;} 
 case 'G':{am = 51.9131;break;} 
 } 
 return am; 
} 
            Các file đính kèm theo tài liệu này:
 Tinvn_Tieuluan_trochoi_nhachat_karaoke_p.pdf Tinvn_Tieuluan_trochoi_nhachat_karaoke_p.pdf