Em có cái đề tài này mong mọi người giúp ạ câu 5 ạ
Đề :
Đây là code ạ
#include<iostream>
#include<conio.h>
using namespace std;
struct DienThoai
{
char msp[10];
char tensp[30];
int ngay,thang,nam;
char mau[6];
int soluong;
int dongia;
int thanhtien;
char ch;
};
void nhap(DienThoai& dt)
{
cout << "Ma san pham:";
cin >> dt.msp;
cout << "Ten san pham:";
cin.ignore();
cin.getline(dt.tensp, 30);
cout << "Ngay/thang/nam:";
cin >> dt.ngay >>dt.ch>> dt.thang >>dt.ch>> dt.nam;
cout << "Mau:";
cin >> dt.mau;
cout << "So luong:";
cin >> dt.soluong;
cout << "Don gia:";
cin >> dt.dongia;
}
void xuat(DienThoai dt)
{
cout << endl;
cout << "Ma san pham:" << dt.msp << endl;
cout << "Ten san pham:" << dt.tensp << endl;
cout << "Ngay/thang/nam:" << dt.ngay << "/" << dt.thang << "/" << dt.nam << endl;
cout << "Mau:" << dt.mau << endl;
cout << "So luong:" << dt.soluong << endl;
cout << "Don gia:" << dt.dongia <<""<<"USD"<< endl;
cout << "Thanh tien:" << dt.soluong * dt.dongia << "" << "USD" << endl;
}
struct node
{
DienThoai info;
node* Next;
};
struct list
{
node* pHead;
node* pTail;
};
void init(list& l)
{
l.pHead = l.pTail = NULL;
}
node* creatnode(DienThoai dt)
{
node* p = new node;
if (p == NULL) return NULL;
strcpy_s(p->info.msp, dt.msp);
strcpy_s(p->info.tensp, dt.tensp);
p->info.ngay = dt.ngay;
p->info.thang = dt.thang;
p->info.nam = dt.nam;
strcpy_s(p->info.mau, dt.mau);
p->info.soluong = dt.soluong;
p->info.dongia = dt.dongia;
p->info.thanhtien = dt.thanhtien;
p->Next = NULL;
return p;
}
void addFirst(list& l, node* p)
{
if (l.pHead == NULL)
l.pHead = l.pTail = p;
else
{
p->Next = l.pHead;
l.pHead = p;
}
}
void Nhapnsp(list& l)
{
int n;
node* p;
DienThoai dt;
cout << "Nhap so luong san pham :";
cin >> n;
for (int i = 0; i < n; i++)
{
cout << "\nNhap thong tin danh sach san pham" << " " << i + 1;
cout << endl;
nhap(dt);
p = creatnode(dt);
addFirst(l, p);
}
}
void outlist(list l)
{
node* p = l.pHead;
cout << "\tDanh sach san pham:" << endl;
while (p != NULL)
{
xuat(p->info);
p = p->Next;
}
system("pause");
}
int Tim(list l, DienThoai dt)
{
int vt = 1;
node* q = l.pHead;
while (q != NULL && q->info.msp != dt.msp)
{
q = q->Next;
vt++;
}
if (q == NULL)
return vt;
xuat(q->info);
return -1;
system("pause");
}
void Interchangesort(list& l)
{
for (node* p = l.pHead; p != l.pTail; p = p->Next)
{
for (node* q = p->Next; q != NULL; q = q->Next)
{
if (p->info.mau > q->info.mau)
{
swap(p->info, q->info);
}
}
}
}
void menu()
{
system("cls");
cout << "1.Nhap san pham" << endl;
cout << "2.Xuat san pham" << endl;
cout << "3.Tim kiem bang ma san pham" << endl;
cout << "4.Sap xep cac san pham" << endl;
cout << "0.Thoat" << endl;
}
int main()
{
int chon, n = 0, kq;
DienThoai x;
node* p;
list l;
init(l);
while (1)
{
menu();
cin >> chon;
if (chon == 0)break;
switch (chon)
{
case 1:
Nhapnsp(l);
break;
case 2:
outlist(l);
break;
case 3:
cout << "Nhap ma san pham:";
cin >> x.msp;
kq = Tim(l, x);
if (kq == -1)
cout << "Khong tim thay san pham";
else
{
cout << "Tim thay san pham:\n";
outlist(l);
}
system("pause");
break;
case 4:
Interchangesort(l);
cout << "Danh sach san pham sau sap xep:" << endl;
outlist(l);
system("pause");
break;
case 0:
return 0;
default:
cout << "Vui long chon lai tu 0->4" << endl;
system("pause");
break;
}
}
}