30/09/2018, 16:43
Giúp em tìm lỗi bài này trong cấu trúc dữ liệu C++ với
Sao em chạy nó cứ báo lỗi thư viện thế ạ :’(
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<conio.h>
using namespace std;
// KHAI BAO CAU TRUC DU LIEU CUA CHUONG TRINH
//================= khai báo CTDL====================
struct oto
{
int matx;
char bks[20];
int socmt;
char tenkh[20];
char diachi[20];
float tiendv,tientx,tt;
};
struct Node
{
oto info;
struct Node *next;
struct Node *previous;
};
struct List
{
Node *Head;
Node *Tail;
};
List Q;
//===================dinh nghia ham khoi tao ds moi==================
void khoitao(List &Q)
{
Q.Head = NULL;
Q.Tail = NULL;
}
//================ dinh nghia ham tao nut chua thong tin =====================
Node *taonut(oto &x)
{
Node *p;
p=(Node *)malloc(sizeof(Node));//hoac p=new Node;
if(p==NULL)
{
cout<<"
Cap phat khong thanh cong";
exit (1);
}
p->info =x;
p->next =NULL;
p-> previous = NULL;
return p;
}
//====================================================================================================
// DINH NGHIA CAC HAM THANH PHAN CAN THIET
//================dinh nghia ham nhap=====================
void nhap(oto &x)
{
float tg;
cout<<"
THONG TIN CUA NGUOI THUE XE";
cout<<"
Nhap ho ten cua khach hang : "; fflush(stdin);gets(x.tenkh) ;
cout<<"
Nhap so chung minh thu cua khach hang: ";cin>>x.socmt;
cout<<"
Nhap dia chi cua khach hang: ";fflush(stdin);gets(x.diachi) ;
cout<<"
CONG VIEC CUA NGUOI CHO THUE XE";
cout<<"
Nhap ma thue xe cua khach hang : ";cin>>x.matx;
cout<<"
Nhap bien so xe cho thue: ";fflush(stdin);gets(x.bks);
cout<<"
Nhap tien dich vu(co nguoi lai): ";cin>>tg;x.tiendv=tg;
cout<<"
Nhap tien thue xe: ";cin>>tg; x.tientx=tg;
x.tt+=x.tiendv*1,5+x.tientx;
}
//=================dinh nghia ham de in danh sach====================
void in(List Q)
{
Node *p;
p=Q.Head;
cout<<endl<<"============================DANH SACH THUE XE OTO===============================";
cout<<endl<<"
"<<setw(5)<<"Ma TX"<<setw(15)<<"Ten Khach Hang"<<setw(15)<<"So CMTND"<<setw(15)<<"Dia Chi"<<setw(15)<<"Bien So Xe"<<setw(15)<<"Tong Tien";
while(p!=NULL)
{
cout<<"
"<<setw(5)<<p->info.matx
<<setw(15)<<p->info.tenkh
<<setw(15)<<p->info.socmt
<<setw(15)<<p->info.diachi
<<setw(15)<<p->info.bks
<<setw(15)<<p->info.tt;
p=p->next;
}
}
//===============chen them vao dau danh sach======================
void chendau(List &Q, Node *x)
{
if(Q.Head==NULL)
{
Q.Head=x;
Q.Tail=Q.Head;
}
else
{
Q.Head->truoc=x;
x->next=Q.Head;
//Q.Head->truoc=x;
Q.Head=x;
}
}
//=========chen them vao cuoi danh sach=======================
void chencuoi(List &Q, Node *y)
{
if(Q.Head==NULL)
{
Q.Head=y;
Q.Tail=Q.Head;
}
else
{
Q.Tail->next=y;
y-> previous = Q.Tail;
Q.Tail=y;
}
}
//========chen them vao sau mot phan tu da biet========
void chensau(List &Q,Node *q, Node *x)
{
if(q!=NULL)
{ x->next=q->next;
(q->next)->previous = x;
q->next=x;
if(q==Q.Tail)
Q.Tail=x;
}
}
//===============xoa dau danh sach======================
void xoadau(List &Q)
{
Node *p;
if(Q.Head!=NULL)
{
p=Q.Head;
Q.Head=Q.Head->next;
delete p;
if(Q.Head==NULL)
Q.Tail=NULL;
}
}
//==============xoa cuoi========
void xoacuoi(List &Q)
{
Node *p;
if(Q.Head!=NULL)
{
p=Q.Tail;
free(p);
if(Q.Head==NULL)
Q.Tail==NULL;
}
}
//================xoa theo ten khach hang==========================
int xoatenkh(List &Q)
{
Node *p=Q.Head,*q=NULL;
char tenkh[20];
cout<<endl<<"
Nhap ten KH can xoa thong tin :";fflush(stdin);gets(tenkh);
while(p!=NULL)
{
if(strcmp(p->info.tenkh,tenkh)==0)
break;
p=q;
p=p->next;
}
if(p==0)
return 0;
if(q!=NULL)
{
if(p==Q.Tail)
Q.Tail=q;
q->next=p->next;
free(p);
}
else
{
Q.Head=p->next;
if(Q.Head==NULL)
Q.Tail=NULL;
}
return 0;
}
//===============sap xep theo ten nguoi thue======================
void sapxepten(List Q)
{
int a,b;
Node *p,*q;
oto tg;
p= Q.Head;
while(p!=NULL)
{
q=p->next;
while(q!=NULL)
{
a=p->info.tenkh[0];
b=q->info.tenkh[0];
if(a>b)
{
tg = p->info;
p->info = q->info;
q->info = tg;
}
q=q->next;
}
p=p->next;
}
}
//===============sua ten khach hang==========================
void suatenkh(List Q)
{
char tenkhs[20];
char tenkhm[20];
Node *p;
p=Q.Head;
cout<<endl<<"Nhap ten khach hang can sua :";fflush(stdin);gets(tenkhs);
while((p!=NULL) && (strcmp(p->info.tenkh,tenkhs)!=0))
{
p=p->next;
}
if(p!=NULL)
{
cout<<endl<<"Nhap ten KH moi :";fflush(stdin);gets(tenkhm);
strcpy(p->info.tenkh,tenkhm);
cout<<endl<<"=================Thong tin moi cua khach hang==============";
cout<<endl<<"
"<<setw(5)<<"Ma TX"<<setw(15)<<"Ten khach hang"<<setw(15)<<"So CMTND"<<setw(15)<<"Dia chi"<<setw(15)<<"Bien so xe"<<setw(15)<<"Tong tien";
cout<<endl<<setw(5)<<p->info.matx<<setw(15)<<p->info.tenkh<<setw(15)<<p->info.socmt<<setw(10)<<p->info.diachi<<setw(15)<<p->info.bks<<setw(15)<<p->info.tt;
}
else
{
cout<<endl<<"Khong co ten khach hang hop le";
}
}
//===============sua ten bien so xe==========================
void suabks(List Q)
{
int n,k;
Node *p;
p=Q.Head;
cout<<endl<<"Nhap bien so xe can sua :";cin>>n;
while(((p!=NULL) && (p->info.bks,n)==0))
{
p=p->next;
}
if(p!=NULL)
{
cout<<endl<<"Nhap bien so xe moi :";cin>>k;
(p->info.bks,k);
cout<<endl<<"=================Thong tin moi cua khach hang==============";
cout<<endl<<"
"<<setw(5)<<"Ma TX"<<setw(15)<<"Ten khach hang"<<setw(15)<<"So CMTND"<<setw(15)<<"Dia chi"<<setw(15)<<"Bien so xe"<<setw(15)<<"Tong tien";
cout<<endl<<setw(5)<<p->info.matx<<setw(15)<<p->info.tenkh<<setw(15)<<p->info.socmt<<setw(10)<<p->info.diachi<<setw(15)<<p->info.bks<<setw(15)<<p->info.tt;
}
else
{
cout<<endl<<"Khong bien so xe nao hop le";
}
}
//================ ham tim ten =====================
int timkiemten(List Q)
{
Node *p;
p=Q.Head;
char tenkhm[20];
while(p!=NULL)
{
if(strcmp(p->info.tenkh,tenkhm)==0)
{
cout<<"
Nhap ten khach hang can tim: ";fflush(stdin);gets(tenkhm);
cout<<endl<<setw(5)<<"Ma TX"<<setw(15)<<"Ten Khach Hang"<<setw(15)<<"So CMTND"<<setw(15)<<"Dia Chi"
<<setw(10)<<"Bien So Xe"<<setw(10)<<"Tong Tien";
cout<<"
"<<setw(5)<<p->info.matx
<<setw(15)<<p->info.tenkh
<<setw(15)<<p->info.socmt
<<setw(15)<<p->info.diachi
<<setw(10)<<p->info.bks
<<setw(10)<<p->info.tt;
p=p->next;
}
else
{
cout<<"
KHONG TIM THAY KHACH HANG NAO";
}
}
}
int main()
{
int i,n;
int k;
Node *new_e;
khoitao(Q);
oto x;
do
{
cout<<"
||=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*||";
cout<<"
** MO HINH QUAN LY CHO THUE OTO **";
cout<<"
|| 1. Nhap moi khach hang ||";
cout<<"
** 2. Hien danh sach khach hang **";
cout<<"
|| 3. Them khach hang vao cuoi danh sach ||";
cout<<"
** 4. Them khach hang vao mot vi tri xac dinh **";
cout<<"
|| 5. Them khach hang vao dau danh sach ||";
cout<<"
|| 6. Xoa dau danh sach ||";
cout<<"
** 7. Xoa ten khach hang **";
cout<<"
** 8. Xoa cuoi danh sach **";
cout<<"
** 9. Sap xep theo ten khach hang **";
cout<<"
|| 10. Sua ten khach hang ||";
cout<<"
** 11. Sua bien so xe **";
cout<<"
|| 12. Exit **";
cout<<"
||*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=||";
cout<<"
MOI BAN CHON CONG VIEC : ";
cin>>k;
switch(k)
{
case 1:
{
cout<<"
Nhap so khach hang thue xe:"; cin>>n;
for(i=0;i<n;i++)
{
nhap(x);
new_e=taonut(x);
chendau(Q,new_e);
}
break;
}
case 2:
{
in(Q);
break;
}
case 3:
{
nhap(x);
new_e = taonut(x);
chencuoi(Q,new_e);
break;
}
case 4:
{
nhap(x);
new_e = taonut(x);
int ma;
cout<<"
Nhap ma thue xe de xac dinh vi tri chen: ";cin>>ma;
Node *q;
// q = timma(Q,k);
chensau(Q,q,new_e);
break;
}
case 5:
{
nhap(x);
new_e = taonut(x);
chendau(Q,new_e);
break;
}
case 6:
{
xoadau(Q);
break;
}
case 7:
{
xoatenkh(Q);
break;
}
case 8:
{
xoacuoi(Q);
break;
}
case9:
{
sapxepten(Q);
break;
}
case10:
{
suatenkh(Q);
break;
}
case 11:
{
suabks(Q);
break;
}
case 12:
{
timkiemten(Q);
break;
}
case13:
{
exit(1); break;
}
}
}
while(k!=0);
getch();
return 0;
}
Bài liên quan
Chắc là báo lỗi thiếu thư viện
#include<conio.h>
đúng không? Thư viện này cũ rồi, code này cũng cũ lắm rồiNó báo lỗi thư viện # < iomanip> ạ, em dùng dev-c++
Viết lại chính xác là
xem có lỗi không?
Giờ thì nó báo lỗi tùm lùm luôn. Em xem lại vậy
Đã xem và phát hiện như sau:
Cảm ơn bạn @david15894 , mình đã sửa hehe