Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- #include<time.h>
- struct baiHat{
- int maBaiHat;
- int maTheLoai;
- char tenBaiHat[50];
- int soLuotNghe;
- char thoiGian[50];
- };
- void nhap(struct baiHat sl[],int &n){
- time_t rawtime;
- struct tm * timeinfo;
- char hienTai [80];
- time (&rawtime);
- timeinfo = localtime (&rawtime);
- strftime (hienTai,80,"%d %m %Y.",timeinfo);
- //Lay thong tin ngay thang nam
- int k=n;
- int temp=0;
- char x[50];
- printf("----------Nhap danh sach bai hat-----------\n");
- for (int i=0;i<k;i++){
- printf("---Bai %d---\n",i+1);
- printf("Nhap ten bai hat: ");
- fflush(stdin);
- gets(x);
- if(i==0){
- sl[i].maBaiHat = ++temp;
- strcpy(sl[i].tenBaiHat,x);
- printf("Nhap ma the loai: ");
- scanf("%d",&sl[i].maTheLoai);
- printf("Nhap so luong nghe: ");
- scanf("%d",&sl[i].soLuotNghe);
- strcpy(sl[i].thoiGian,hienTai);
- }
- else {
- for (int j=0;j<i;j++){
- if (stricmp(sl[j].tenBaiHat,x)==0){
- printf("Trung bai hat\n");
- n--;
- }
- else if (stricmp(sl[j].tenBaiHat,x)!=0){
- sl[i].maBaiHat = ++temp;
- strcpy(sl[i].tenBaiHat,x);
- printf("Nhap ma the loai: ");
- scanf("%d",&sl[i].maTheLoai);
- printf("Nhap so luong nghe: ");
- scanf("%d",&sl[i].soLuotNghe);
- strcpy(sl[i].thoiGian,hienTai);
- }
- }
- }
- }
- }
- void xuat(struct baiHat sl[],int n){
- printf("----------Xuat danh sach bai hat-----------\n");
- for (int i=0;i<n;i++){
- printf("---Bai %d---\n",i+1);
- 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);
- }
- }
- int main(){
- int n;
- printf("Nhap so luong bai hat: ");
- scanf("%d",&n);
- struct baiHat sl[n];
- nhap(sl,n);
- xuat(sl,n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement