Advertisement
Guest User

Untitled

a guest
Feb 18th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<time.h>
  4. struct baiHat{
  5. int maBaiHat;
  6. int maTheLoai;
  7. char tenBaiHat[50];
  8. int soLuotNghe;
  9. char thoiGian[50];
  10. };
  11. void nhap(struct baiHat sl[],int &n){
  12. time_t rawtime;
  13. struct tm * timeinfo;
  14. char hienTai [80];
  15. time (&rawtime);
  16. timeinfo = localtime (&rawtime);
  17. strftime (hienTai,80,"%d %m %Y.",timeinfo);
  18. //Lay thong tin ngay thang nam
  19. int k=n;
  20. int temp=0;
  21. char x[50];
  22. printf("----------Nhap danh sach bai hat-----------\n");
  23. for (int i=0;i<k;i++){
  24. printf("---Bai %d---\n",i+1);
  25. printf("Nhap ten bai hat: ");
  26. fflush(stdin);
  27. gets(x);
  28. if(i==0){
  29. sl[i].maBaiHat = ++temp;
  30. strcpy(sl[i].tenBaiHat,x);
  31. printf("Nhap ma the loai: ");
  32. scanf("%d",&sl[i].maTheLoai);
  33. printf("Nhap so luong nghe: ");
  34. scanf("%d",&sl[i].soLuotNghe);
  35. strcpy(sl[i].thoiGian,hienTai);
  36.  
  37. }
  38. else {
  39. for (int j=0;j<i;j++){
  40. if (stricmp(sl[j].tenBaiHat,x)==0){
  41. printf("Trung bai hat\n");
  42. n--;
  43. }
  44. else if (stricmp(sl[j].tenBaiHat,x)!=0){
  45. sl[i].maBaiHat = ++temp;
  46. strcpy(sl[i].tenBaiHat,x);
  47. printf("Nhap ma the loai: ");
  48. scanf("%d",&sl[i].maTheLoai);
  49. printf("Nhap so luong nghe: ");
  50. scanf("%d",&sl[i].soLuotNghe);
  51. strcpy(sl[i].thoiGian,hienTai);
  52. }
  53. }
  54. }
  55. }
  56. }
  57. void xuat(struct baiHat sl[],int n){
  58. printf("----------Xuat danh sach bai hat-----------\n");
  59. for (int i=0;i<n;i++){
  60. printf("---Bai %d---\n",i+1);
  61. printf("Ma bai hat: %d || Ma bai hat: %d || Ten Bai Hat: %s || So luot nghe: %d || Thoi gian: %s\n",sl[i].maBaiHat,sl[i].maTheLoai,sl[i].tenBaiHat,sl[i].soLuotNghe,sl[i].thoiGian);
  62. }
  63. }
  64. int main(){
  65. int n;
  66. printf("Nhap so luong bai hat: ");
  67. scanf("%d",&n);
  68. struct baiHat sl[n];
  69. nhap(sl,n);
  70. xuat(sl,n);
  71. return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement