0% found this document useful (0 votes)
49 views15 pages

Code - Nhom 4

The document contains code for a program that manages a linked list of household data structures. It defines functions for initializing the linked list, creating and inserting nodes, outputting node data, deleting nodes, searching/filtering the list, and sorting nodes. The main menu function allows the user to call these functions to view, modify and analyze the linked list of household information.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views15 pages

Code - Nhom 4

The document contains code for a program that manages a linked list of household data structures. It defines functions for initializing the linked list, creating and inserting nodes, outputting node data, deleting nodes, searching/filtering the list, and sorting nodes. The main menu function allows the user to call these functions to view, modify and analyze the linked list of household information.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

// Bai tap lon mon cau truc du lieu va giai thuat

// Nhom 4

#include<iostream>

#include<string>

#include<iomanip>

using namespace std;

// ========================================= KHAI BAO HO DAN


===================================================

struct Hodan

int mh;

string tch;

int stv;

float mtn;

};

typedef struct Hodan HODAN;

// ========================================= KHAI BAO 1 NODE HO DAN


============================================

struct node

HODAN data;

struct node* next;

struct node* prev;

};

typedef struct node NODE;


// ========================================= KHAI BAO DANH SACH LIEN KET
=======================================

struct list

NODE* pHead;

NODE* pTail;

};

typedef struct list LIST;

// ========================================= KHOI TAO DANH SACH LIEN KET


========================================

void KhoiTao(LIST &l)

l.pHead = NULL; // con tro pHead quan ly dau danh sach

l.pTail = NULL; // con tro pTail quan ly cuoi danh sach

// ========================================= KHOI TAO 1 NODE


====================================================

NODE* createNODE(HODAN x)

NODE* p = new NODE();

p->data = x;

p->next = NULL;

p->prev = NULL;

return p;

// ========================================= HAM XUAT THONG TIN HO DAN


===========================================
void Output(HODAN x)

cout << right << setw(10) << x.mh << setw(30) << x.tch << setw(20) << x.stv << setw(20) << x.mtn <<
endl;

// ========================================= HAM THEM HO DAN VAO CUOI


============================================

void InsertLast(LIST &l, NODE *p)

if (l.pHead == NULL)

l.pHead = l.pTail = p;

else

l.pTail->next = p;

l.pTail->prev = p;

l.pTail = p;

//========================================= HAM THEM HO DAN VAO DANH SACH


=======================================

void Insert(LIST& l)

HODAN x;

cout << "\n\n\t\t NHAP THONG TIN CHO HO DAN ";

NODE* p = l.pHead;

cout << "\n";

cout << "\n[-]Nhap Ma: ";

cin >> x.mh;


while (p != NULL)

if (p->data.mh == x.mh)

cout << "\n\n\t\t MA HO DA TON TAI!!! ";

cout << "\n[-]Nhap Lai Ma Ho: ";

cin >> x.mh;

else

p = p->next;

while (getchar() != '\n');

cout << "\n[-]Nhap Ten Chu Ho: ";

getline(cin, x.tch);

cout << "\n[-]Nhap So Thanh Vien: ";

cin >> x.stv;

cout << "\n[-]Nhap Muc Thu Nhap: ";

cin >> x.mtn;

NODE* k = createNODE(x);

InsertLast(l, k);

// ============================================ XOA HO DAN O DAU DANH SACH


====================================

void DeleteFirst(LIST &l)

{
NODE* p;

if (l.pHead == NULL)

cout << "\n\n\t\t DANH SACH RONG";

else

// danh sach co 1 phan tu

if (l.pHead->next == NULL)

p = l.pHead;

l.pHead = l.pTail = NULL;

delete p;

else // danh sach co nhieu hon 1 phan tu

p = l.pHead;

l.pHead = p->next;

p->next = NULL;

l.pHead->prev = NULL;

delete p;

// ========================================= XOA HO DAN O CUOI DANH SACH


========================================

void DeleteLast(LIST& l)

if (l.pHead == NULL)
{

cout << "\n\n\t\t DANH SACH RONG ";

else

if (l.pHead->next == NULL)

delete l.pTail;

l.pTail = NULL;

else

NODE* p = l.pHead;

while (p->next->next != NULL)

p = p->next;

delete p->next;

p->next = NULL;

// ============================================ XOA HO DAN BAT KY DANH SACH


=====================================

void DeleteMA(LIST& l, int x)

if (l.pHead->data.mh == x)

DeleteFirst(l);
}

else if (l.pTail->data.mh == x)

DeleteLast(l);

else

NODE* p = l.pHead;

NODE* q = l.pHead;

while (p->data.mh != x)

q = p;

p = p->next;

if (p == NULL)

cout << "\n\n\t\t KHONG TON TAI NODE CAN XOA ";

else

q->next = p->next;

p->next = NULL;

delete p;

// ========================================= TIM 1 HO THEO TEN CHU HO


===========================================

void TimTen(LIST &l)


{

string ten;

while (getchar() != '\n');

cout << "\n[-]Nhap Ten Chu Can Tim: ";

getline(cin, ten);

cout << "\n\n\t\t ========== DANH SACH HO DAN TIM THEO TEN ========== " << endl;

cout << "\n";

cout << setw(10) << "MA" << setw(30) << "HO TEN" << setw(20) << "SO THANH VIEN" << setw(20) <<
"THU NHAP" << endl;

for(NODE *p = l.pHead; p != NULL; p = p->next)

string tentk = p->data.tch;

if (_strcmpi((char*)ten.c_str(), (char*)tentk.c_str()) == 0)

Output(p->data);

// ========================================= HIEN THI THANH VIEN NHAP VAO TU BAN PHIM


===========================

void Xuat_So_Ho_Co_Thanh_Vien_Nhap_Tu_Ban_Phim(LIST &l)

int a;

cout << "\n[-]Nhap So Thanh Vien Cua Ho Can Tim: ";

cin >> a;

cout << "\n\n\t\t ========== DAN SACH HO DAN CO SO DAN CAN TIM ========== " << endl;

cout << "\n";

cout << setw(10) << "MA" << setw(30) << "HO TEN" << setw(20) << "SO THANH VIEN" << setw(20) <<
"THU NHAP" << endl;

for (NODE* k = l.pHead; k != NULL; k = k->next)


{

if (k->data.stv == a)

Output(k->data);

// ========================================= DEM SO HO CO THU NHAP TREN 2TR


===================================

void Dem(LIST &l)

int dem = 0;

for (NODE* k = l.pHead; k != NULL; k = k->next)

if (k->data.mtn > 2000)

dem++;

cout << "\n\t So Ho Dan Co Thu Nhap Tren 2TR la: " << dem << endl;

// ========================================= HOAN Vi
==========================================================

void HoanVi(HODAN& x, HODAN& y)

HODAN temp = x;

x = y;

y = temp;

}
// ========================================= SAP XEP HO DAN GIAM DAN THEO STV
=================================

void SapXep(LIST &l)

cout << "\n\n\t\t ========== DANH SACH CAC HO CO SO THANH VIEN GIAM DAN ========== " <<
endl;

cout << "\n";

cout << setw(10) << "MA" << setw(30) << "HO TEN" << setw(20) << "SO THANH VIEN" << setw(20) <<
"THU NHAP" << endl;

for (NODE* k = l.pHead; k != NULL; k = k->next)

for (NODE* h = k->next; h != NULL; h = h->next)

if (k->data.stv < h->data.stv)

HoanVi(k->data, h->data);

Output(k->data);

// ================================ THEM HO DAN VAO ROI SAP XEP


===============================================

void Them_Sap_Xep(LIST &l)

HODAN x;

Insert(l);

SapXep(l);

}
// ================================ TIM KIEM HO DAN CO THU NHAP DUOI 10TR
=====================================

void Tim_Kiem_Ho_Thu_Nhap_10TR(LIST &l)

cout << "\n\n\t\t ========== DANH SACH CAC HO CO THU NHAP DUOI 10TR ========== " << endl;

cout << "\n";

cout << setw(10) << "MA" << setw(30) << "HO TEN" << setw(20) << "SO THANH VIEN" << setw(20) <<
"THU NHAP" << endl;

for (NODE* k = l.pHead; k != NULL; k = k->next)

if (k->data.mtn < 10000)

Output(k->data);

// ========================================= HAM XUAT THONG TIN DANH SACH HO DAN


==============================

void ShowList(LIST l)

NODE* p = l.pHead;

cout << "\n\n\t\t ========== DANH SACH CAC HO DAN ========== " << endl;

cout << "\n";

cout << setw(10) << "MA" << setw(30) << "HO TEN" << setw(20) << "SO THANH VIEN" << setw(20) <<
"THU NHAP" << endl;

while (p != NULL)

Output(p->data);

p = p->next;

}
}

// ========================================= HUY TOAN BO DANH SACH CAC HO DAN


=================================

void Huy(LIST l)

NODE* p = NULL;

while (l.pHead != NULL)

p = l.pHead;

l.pHead = l.pHead->next;

l.pHead->prev = NULL;

delete p;

return;

void MENU(LIST &l)

int luachon;

while (true)

cout << "\n\n\t\t==================================== MENU


===================================== ";

cout << "\n\t\t|| 1.Hien Thi Toan Bo Danh Sach || ";

cout << "\n\t\t|| 2.Tim 1 Ho Theo Ten Chu Ho Nhap Vao || ";

cout << "\n\t\t|| 3.Them 1 Ho Vao Cuoi Danh Sach || ";

cout << "\n\t\t|| 4.Xoa 1 Ho Khoi Danh Sach Tu Ma Ho || ";

cout << "\n\t\t|| 5.Nhap So Thanh Vien. Hien Thi Danh Sach Co So Thanh Vien Do || ";

cout << "\n\t\t|| 6.Dem So Ho Co Muc Thu Nhap Tren 2TR || ";

cout << "\n\t\t|| 7.Sap Xep Danh Sach Giam Dan Theo So Thanh Vien || ";
cout << "\n\t\t|| 8.Them 1 Ho Vao Danh Sach Van Du Dieu Kien Giam Dan Theo So Thanh Vien ||
";

cout << "\n\t\t|| 9.Tim Kiem Danh Sach Cac Ho Co Muc Thu Nhap Tren 10TR || ";

cout << "\n\t\t|| 10.Huy Toan Bo Danh Sach || ";

cout << "\n\t\t|| 0.Ket Thuc || ";

cout << "\n\t\t====================================== END


==================================== ";

cout << "\n[-]Nhap Lua Chon: ";

cin >> luachon;

system("cls");

if (luachon < 0 || luachon > 10)

cout << "\n\n\t\t HAY CHON CHUC NANG TREN MAN HINH ";

else if (luachon == 1)

ShowList(l);

else if(luachon == 2)

TimTen(l);

else if (luachon == 3)

Insert(l);

else if (luachon == 4)
{

int x;

cout << "\n[-]Nhap NODE Can Xoa: ";

cin >> x;

DeleteMA(l,x);

else if (luachon == 5)

Xuat_So_Ho_Co_Thanh_Vien_Nhap_Tu_Ban_Phim(l);

else if (luachon == 6)

Dem(l);

else if (luachon == 7)

SapXep(l);

else if (luachon == 8)

Them_Sap_Xep(l);

else if (luachon == 9)

Tim_Kiem_Ho_Thu_Nhap_10TR(l);

else if (luachon == 10)

Huy(l);
}

else

break;

int main()

LIST l;

KhoiTao(l);

MENU(l);

system("pause");

return 0;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy