Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
3.4 kB
2
Indexable
Never
#include<iostream>
#include<string>
#include<stdio.h>
using namespace std;
int mkh = 1 , mmh = 1 , mdh = 1;
class inFor1
{
	public:
		string maKhachHang, tenKhachHang , diaChi;
};
inFor1 ds1[1000];
class inFor2
{
	public:
		string maMatHang, tenMatHang , donViTinh;
		int giaMua , giaBan;
};
inFor2 ds2[1000];
class KhachHang{
	public:
		string maKhachHang;
		string tenKhachHang;
		string gioiTinh;
		string ngaySinh;
		string diaChi;
};
class MatHang{
	public :
		string maMatHang;
		string tenMatHang;
		string donViTinh;
		int giaMua, giaBan;
};
class HoaDon{
	public:
		string maHoaDon;
		string maKhachHang;
		string maMatHang;
		int soLuong;
		int loiNhuan;
		int viTriKhachHang;
		int viTriMatHang;
};
istream& operator >> (istream &is, KhachHang &a)
{
	if(mkh == 1) scanf("\n");
	if(mkh <= 9)
	{
		a.maKhachHang = "KH00" + to_string(mkh);
	}
	
	else if(10<= mkh && mkh <= 99)
	{
		a.maKhachHang = "KH0" + to_string(mkh);
	}
	else 
	{
		a.maKhachHang = "KH" + to_string(mkh);
	}
	getline(is, a.tenKhachHang);
	is>>a.gioiTinh>>a.ngaySinh;
	scanf("\n");
	getline(is, a.diaChi);
	ds1[mkh].maKhachHang = a.maKhachHang;
	ds1[mkh].tenKhachHang = a.tenKhachHang;
	ds1[mkh].diaChi = a.diaChi;
	mkh++;
	return is;
}

istream& operator >> (istream &is , MatHang &a)
{
	scanf("\n");
	if(mmh <= 9)
	{
		a.maMatHang = "MH00" + to_string(mmh);
	}
	else if(10 <= mmh && mmh <= 99)
	{
		a.maMatHang = "MH0" + to_string(mmh);
	}
	else
	{
		a.maMatHang = "MH"+to_string(mmh);
	}
	getline(is, a.tenMatHang);
	is>>a.donViTinh>>a.giaMua>>a.giaBan;
	ds2[mmh].donViTinh = a.donViTinh;
	ds2[mmh].maMatHang = a.maMatHang;
	ds2[mmh].tenMatHang =a.tenMatHang;
	ds2[mmh].giaMua = a.giaMua;
	ds2[mmh].giaBan = a.giaBan;
	mmh++;
	return is;
}

istream& operator >> (istream & is , HoaDon &a)
{
	scanf("\n");
	if(mdh <= 9)
	{
		a.maHoaDon = "HD00" + to_string(mdh);
	}
	else if(10 <= mdh && mdh <= 99)
	{
		a.maHoaDon = "HD0" + to_string(mdh);
	}
	else
	{
		a.maHoaDon = "HD" + to_string(mdh);
	}
	is>>a.maKhachHang>>a.maMatHang>>a.soLuong;
	for(int i = 0 ; i < mkh ; i++)
	{
		if(a.maKhachHang == ds1[i].maKhachHang)
		{
			a.viTriKhachHang = i;
			break;
		}
	}
	for(int i = 0 ; i < mmh ;i++)
	{
		if(a.maMatHang == ds2[i].maMatHang)
		{
			a.viTriMatHang = i;
			a.loiNhuan = a.soLuong * (ds2[i].giaBan - ds2[i].giaMua);
			break;
		}
	}
	mdh++;
	return is;
}

void sapxep(HoaDon dshd[], int K)
{
	for(int i = 0; i < K - 1;i++)
	{
		for(int j = i+1 ; j < K ; j++)
		{
			if(dshd[i].loiNhuan < dshd[j].loiNhuan)
			{
				HoaDon a = dshd[i];
				dshd[i] = dshd [j];
				dshd [j] = a;
			}
			else if(dshd[i].loiNhuan == dshd[j].loiNhuan)
			{
				if(dshd[i].maHoaDon > dshd[j].maHoaDon)
				{
					HoaDon a = dshd[i];
				dshd[i] = dshd [j];
				dshd [j] = a;
				}
			}
		}
	}
}

ostream& operator << (ostream & os , HoaDon &a)
{
	os<<a.maHoaDon<<" ";
	os<<ds1[a.viTriKhachHang].tenKhachHang<<" ";
	os<<ds1[a.viTriKhachHang].diaChi<<" ";
	os<<ds2[a.viTriMatHang].tenMatHang<<" ";
	os<<a.soLuong<<" ";
	os<<ds2[a.viTriMatHang].giaBan*a.soLuong<<" ";
	os<<a.loiNhuan<<endl;
	return os;
}

int main(){
    KhachHang dskh[25];
    MatHang dsmh[45];
    HoaDon dshd[105];
    int N,M,K,i;
    cin >> N;
    for(i=0;i<N;i++) cin >> dskh[i];
    cin >> M;
    for(i=0;i<M;i++) cin >> dsmh[i];
    cin >> K;
    for(i=0;i<K;i++) cin >> dshd[i];

    sapxep(dshd, K);

    for(i=0;i<K;i++) cout << dshd[i];
    return 0;
}