Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct {
- char tenHang[25];
- int donGia;
- int soLuong;
- float thanhTien;
- }ThongKe;
- typedef struct NODE {
- ThongKe SoLieu;
- struct NODE* next;
- }NODE;
- typedef struct {
- NODE* first;
- NODE* last;
- }DS;
- NODE* taoSoLieu()
- {
- NODE* node = (NODE*)calloc(1 ,sizeof(NODE));
- fflush(stdin);
- printf("\t\tTen don hang: ");
- gets(node->SoLieu.tenHang);
- fflush(stdin);
- do
- {
- printf("\t\tDon gia: ");
- scanf("%d", &node->SoLieu.donGia);
- }while (node->SoLieu.donGia < 0);
- fflush(stdin);
- do
- {
- printf("\t\tSo luong: ");
- scanf("%d", &node->SoLieu.soLuong);
- }while (node->SoLieu.soLuong < 0);
- fflush(stdin);
- node->next = NULL;
- return node;
- }
- DS* taoDanhSach(int n)
- {
- int i;
- DS* ds = (DS*)calloc(1, sizeof(DS));
- ds->first = NULL;
- ds->last = NULL;
- NODE* node = NULL;
- for (i=0; i<n; i++)
- {
- printf("\t\tDon hang thu %d\n", i+1);
- node = taoSoLieu();
- if (ds->first == NULL)
- {
- ds->first = node;
- ds->last = node;
- }
- else
- {
- ds->last->next = node;
- ds->last = node;
- }
- }
- }
- void inDanhSach(DS* ds)
- {
- int i=1;
- NODE* tmp = ds->first;
- printf("\t\t\t SO LIEU BAN HANG\n");
- printf("\t\t_%5s_%25s_%10s_%10s_%15s_\n", "_____", "_________________________", "__________", "__________", "_______________");
- printf("\t\t|%5s|%25s|%10s|%10s|%15s|\n", "STT", "Ten Hang", "Don Gia", "So Luong", "Thanh Tien");
- printf("\t\t|%5s+%25s+%10s+%10s+%15s|\n", "-----", "-------------------------", "----------", "----------", "---------------");
- while (tmp != NULL)
- {
- printf("\t\t|%5d|%25s|%10d|%10d|%15.3f|\n", i++, tmp->SoLieu.tenHang, tmp->SoLieu.donGia, tmp->SoLieu.soLuong, (float)(tmp->SoLieu.donGia * tmp->SoLieu.soLuong));
- tmp = tmp->next;
- }
- printf("\t\t|%5s_%25s_%10s_%10s_%15s|\n", "_____", "_________________________", "__________", "__________", "_______________");
- }
- void giaiPhong(DS* ds)
- {
- NODE* tmp = NULL;
- NODE* del = NULL;
- del = tmp = ds->first;
- while (tmp != NULL)
- {
- tmp = tmp->next;
- free(del);
- del = tmp;
- }
- }
- void themHang(DS* ds, NODE* node)
- {
- ds->last->next = node;
- ds->last = node;
- }
- int main()
- {
- int n, chon;
- char select;
- DS* ds = NULL;
- label:
- printf("\t\t\t Bang chon\n");
- printf("\t\t ______________________________ \n");
- printf("\t\t|1. Nhap so lieu ban hang |\n");
- printf("\t\t|2. Bo sung so lieu ban hang |\n");
- printf("\t\t|3. Hien thi so lieu ban hang |\n");
- printf("\t\t|4. Ket thuc |\n");
- printf("\t\t|______________________________|\n");
- printf("\t\tMoi chon: ");
- scanf("%d", &chon);
- switch (chon)
- {
- case 1:
- {
- printf("\t\tNhap so luong hang: ");
- scanf("%d", &n);
- ds = taoDanhSach(n);
- goto label;
- }
- case 2:
- {
- NODE* node = NULL;
- do
- {
- node = taoSoLieu();
- printf("\n\t\tNhap nua khong (y/n): ");
- scanf("%s", &select);
- }
- while (select != 'n');
- printf("\n");
- goto label;
- }
- case 3:
- {
- inDanhSach(ds);
- goto label;
- }
- case 4:
- {
- giaiPhong(ds);
- exit(0);
- }
- default:
- {
- printf("\t\tNhap sai, nhap lai\n");
- goto label;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement