Untitled

 avatar
rongvodich1998
css
2 years ago
4.4 kB
52
Indexable
Never
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Struct TAINGHE
{
    Char MaTaiNghe[10];
    Char TenTaiNghe[25];
    Char NuocSX[10];
    Int SoLuong;
    Float DonGia, ThanhTien;
    
};
Struct Node
{
    TAINGHE info;
    Struct Node*next;
};
Struct List
{
    Node *Head;
    Node *Tail;
};
//Nh?p danh sách tai nghe t? bàn phím và luu vào DSLK Ðon (ho?c DSLK kép)
Void NhapTaiNghe(TaiNghe &x)
{
    Fflush(stdin);
    Printf(“\n Nhap Ma Tai Nghe:”); gets(x. MaTaiNghe);
    Printf (“Nhap Ten Tai Nghe:”); fflush(stdin); gets(x. TenTaiNghe);
    Printf (“Nhap Nuoc san xuat:”); fflush(stdin); gets(x. NuocSX);
    Printf (“Nhap so luong:”); scanf(“%d”,&x.SoLuong);
    Printf (“Nhap don gia:”); scanf(“%f”,&x. DonGia);
    x.ThanhTien=x.SoLuong* x.DonGia;
}
//Yêu c?u 2: In danh sách tai nghe dã nh?p
Void InDanhSach (TAINGHE x)
{
    Printf(“\n %7s”,x. MaTaiNghe);
    Printf(“%15s”,x. TenTaiNghe);
    Printf(“%7s”,x. Nuocsx);
    Printf(“%5d”,x. Soluong);
    Printf(“%10.0f”,x.DonGia);
    Printf(“%10.0f”,x.ThanhTien);
}
//Tao nut va khoi tao danh sach
Void KhoiTao(List &Q)
{
    Q.Head=Null;
    Q.Tail=Null;
}
Node *getNode(Tainghe x)
{
    Node *p;
    P=new Node;
    If (p==Null);
{
    Printf (“\n Cap phat khong thanh cong”);
    Exit(1);
}
p->infor = x;
p->next = Null;
return p;
}
//Chen dau danh sach
Void ChenDau (List &Q, Node *p)
{
    If (Q.Head==Null)
    {
        Q.Head=p;
        Q.Tail=p;
        
    }
    Else
    {
        p->next=Q.Head;
        Q.Head=p;
        
    }
}	
//Xoa phan tu dau danh sach
Void XoaDau(List &Q)
{
    Node *p;
    If (Q.Head!=Null)
    {
        P=Q.Head;
        Q.Hea=Q.Head->next;
        Delete p;
        If (Q.Head==Null)
        Q.Tail=Null;
    }
}
//Nhap va in danh sach tai nghe
Void NhapDSTN (List &Q)
{
    Node *p;
    Int n.i;
    TaiNghe x;
    Printf (“Nhap so tai nghe:”); scanf (“%d”, &n);
    For (i=0; I<n; i++)
    {
        Nhap TaiNghe (x);
        P= getNode (x);
        chenDau (Q,p);
        
    }
}
Void InDSTN (List Q)
{ 
    Node *p;
    For (p=Q.Head; p!=Null; p=p->next)
    InDSTN(p->info);
}
//Yeu cau 3: Tim kiem tai nghe theo ten
Node *TimTaiNghe (List Q, char x[])
{
    Node *p;
    For (p=Q.Head; p!=Null; p=p->next)
    If (strcmp (p->info.TenTainghe,x)==0)
    Break;
    Return p;
}
//Yeu cau 4: Sap xep tang dan cua don gia
Void SX_TD_DonGia (List &Q)
{
    Node *p, *q;
    TaiNghe tg;
    For (p=Q.Head; p!=Null; p=p->next)
    For (q=p->next; q!=Null; q=q->next)
    {
        Tg=p->info;
        P->info = q->info;
        q->info=tg;
    }
}
//Yeu cau 5: Tinh tong tien
Void TongTien (List Q)
{
    Node *p;
    Float s=0;
    For(p=Q.Head; p!=Null; p=p->Next)
    S=s+p->info.ThanhTien;
    Printf (“\n Tong tien cua cac tai nghe da nhap: %10.0f”,s);
}
//Yeu cau 6: Hien thi tai nghe co don gia >250.000
Void InTaiNgheDonGia (List Q)
{
    Node *p;
    Printf (“\n ====================”);
    Printf (“\n DSTN co don gia lon hon 250.000 Dong: \n”);
    For (p=Q.Head; p!=Null; p=p->next)
    If (p->info.DonGia>250.000)
    InDanhSach(p->info);
}
//Yeu cau 7: hien thi ten (hoac thong tin day du) cua Tai nghe co don gia cao nhat
Void TenTaiNgheDonGiaMax (List Q)
{
    Node *p;
    Float max;
    Max = Q.Head->info.DonGia;
    For (p=Q.Head; p!=Null; p=p->next)
    If (p->info.DonGia>max)
    Max=p->info.DonGia;
    Printf (“\n Ten tai nghe co don gia cao nhat:”);
    For(p=Q.Head; p!=Null; p=p->next)
    If (p->info.DonGia==max)
    Printf(“- %25s”, p->info.TenTaiNghe);
}
Int main()
{
    List Q;
    Node *p, *q;
    Char MaTaiNghe[10], TenTaiNghe[25];
    KhoiTao(Q);
    NhapDSTN (Q);
    Printf (“\n DSTN da nhap \n”);
    InDSTN (Q);
    InTaiNgheDonGia (Q);
    TongTien(Q);
    TenTaiNgheDonGiaMax(Q);
    SX_TD_DonGia (Q);
    Printf (“\n ==================”);
    Printf (“\n DSTN SX gian dan don gia \n”);
    Printf (“\n Nhap ma Tai nghe can tim:”); gets (MaTaiNghe);
    If (p==Null)
    Printf (“\n Rat tiec,khong tim thay tia nghe \n”);
}
Else
{
    Printf (“\n Da tim thay tai nghe \n”);
    InTaiNghe(p->info);
}