#include<iostream>
#include<iomanip>
#include<conio.h>
using namespace std;
class DIEUHOA
{
private:
char ma[30];
char tenhsx[30];
char tennnk[20];
float dg , cs;
public:
DIEUHOA (char mahang[]=" ", char tenhangsanxuat[]=" ",
char tennuocnhapkhau[]=" ", float dongia =0, float congsuat=0)
{
strcpy(ma,mahang);
strcpy(tenhsx,tenhangsanxuat);
strcpy(tennnk,tennuocnhapkhau);
dg=dongia;
cs=congsuat;
}
~DIEUHOA()
{}
friend istream& operator >>(istream &is, DIEUHOA &d)
{
fflush(stdin);
cout<<"nhap ma hang :";
is>>d.ma;
cout<<"nhap hang san xuat :";
is>>d.tenhsx;
cout<<"nhap don gia :";
is>>d.dg;
cout<<"nhap ten nuoc nhap khau :";
is>>d.tennnk;
cout<<"nhap cong suat :";
is>>d.cs;
return is;
}
friend ostream &operator << (ostream &os , DIEUHOA &d)
{
os<<setw(15)<<"ma hang "<<d.ma
<<setw(20)<<"ten nha san xuat "<<d.tenhsx
<<setw(20)<<"don gia "<<d.dg
<<setw(20)<<"ten nuoc nhap khau "<<d.tennnk
<<setw(20)<<"cong suat "<<d.cs<<endl;
return os;
}
float thue()
{
if(cs<=18000)
{
return 0.2*dg;
cout<<endl;
}
else
{
return 0.4*dg;
cout<<endl;
}
}
float thanhtien()
{
return dg*thue()*0.1;
}
char *getNhaSanXuat()
{
return tenhsx;
}
};
void Xoa(DIEUHOA *dieuhoa,int &n,int vt)
{
for(int i=vt;i<n-1;i++)
{
dieuhoa[i]=dieuhoa[i+1];
}
n--;
}
char *daoNguocChuoi(char *str)
{
for(int i=0;i<strlen(str)/2;i++)
{
swap(str[i], str[sizeof(str)-i-1]);
}
return str;
}
int main()
{
DIEUHOA a[100];
int d=0;
int n,i;
cout<<"[+]Nhap so dieu hoa : ";
cin>>n;
cout<<endl;
for(int i=0;i<n;i++)
{
cout<<"[+]Nhap dieu hoa thu : "<<i+1<<endl;
cin>>a[i];
}
int choice;
do
{
cout<<"\t1.Sap xep tang dan theo ten nuoc nhap khau :"<<endl;
cout<<"\t2.In ra danh sach dieu hoa co thanh tien lon hon 1000 USD"<<endl;
cout<<"\t3.Chen vao vi tri K neu chua co loai 'panasonic'"<<endl;
cout<<"\t4.Xoa khoi danh sach dieu hoa 'Thai Lan'"<<endl;
cout<<"\t0.THOAT."<<endl;
cout<<"BAN CHON:"<<endl;
cin>>choice;
switch (choice)
{
/////////////////////////////////////////////////////////////////////
case 1:
cout<<"\n=====================================Danh sach dieu hoa tang dan theo ten nuoc nhap khau======================================="<<endl;
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n-1;j++)
{
if(a[i]>a[j])
{
swap(a[i],a[j]);
}
}
}
for(int i=0;i<n;i++)
{
cout<<a[i];
}
break;
//////////////////////////////////////////////////////////////////
case 2:
cout<<"\n=====================================Danh sach dieu hoa co thanh tien hon 1000USD======================================="<<endl;
for(int i=0;i<n;i++)
{
if(a[i].thanhtien() > 1000)
{
cout<<a[i];
}
}
break;
/////////////////////////////////////////////////////////////////////
case 3:
d=0;
for(int i=0;i<n;i++)
{
if(strcmp(a[i].getNhaSanXuat(), "panasonic")!=0)
{
cout<<"Nhap vi tri K :";
int k;
cin>>k;
DIEUHOA aChen;
cout<<"Nhap dieu hoa "<<endl;
cin>>aChen;
for(int i=n;i>k;i--)
{
a[i]=a[i-1];
}
a[k]=aChen;
n++;
d++;
cout<<"\n=======================================Danh sach sau khi chen ==============================="<<endl;
for(int i=0;i<n;i++)
{
cout<<a[i];
}
break;
}
}
if(d==0)
{
cout<<"Da co panasonic"<<endl;
}
break;
//////////////////////////////////////////////////////////////
case 4:
for(int i=0;i<n;i++)
{
if(strcmp(a[i].getNhaSanXuat(), "thailan")==0)
{
Xoa(a,n,i);
i--;
}
}
cout<<"\n==========================Danh sach ruou sau khi xoa ============================="<<endl;
for(int i=0;i<n;i++)
{
cout<<a[i];
}
break;
default:
break;
}
}
while (choice!=0);
return 0;
}
