#include <iostream>
#include <stdlib.h>
#include <time.h>

using namespace std;

const int MAXCHAMBRE = 64, MAXNUITS = 15 ;


struct Chambre
{
    int num;
    int simples, doubles;
    int prix [3];
};

struct Reservation
{
    int nbNuits;
    int num_chambre;
    int tarif; // 0, 1 ou 2 pour basse moyenne ou haute saison
};

struct Hotel
{
    struct Chambre T_Room[MAXCHAMBRE];
    struct Reservation T_Resa[MAXNUITS];
    int nb_Room, nb_Resa;

};
struct Chambre remplir_chambre (int n)
{
    Chambre room;
    int i;
    room.num = n ;
    do
    {
        cout<<"Donnez le nombre de lits simples"<<endl;
        cin>> room.simples;
        cout<<"Donnez le nombre de lits doubles"<<endl;
        cin>> room.doubles;
    }
    while (room.simples + room.doubles ==0 || (room.simples + room.doubles)>5);

    cout<<"Donnez les 3 prix"<<endl;
    do
    {
        cin>>room.prix[0] ;
    }
    while (room.prix[0] <=0);
    for (i=1; i<3; i++)
    {
        do
        {
            cin>>room.prix[i] ;
        }
        while (room.prix[i] <= room.prix[i-1] );
    }
    return room;
}
void affiche_chambre (Chambre room)
{
    int i;

    cout<<"Chambre : "<<room.num<<endl;
    cout<<"Nombre de lits simples : "<<room.simples<<endl;
    cout<<"Nombre de lits doubles : "<<room.doubles<<endl;
    for (i=0; i<3; i++)
        cout<<"Prix : "<<room.prix[i]<<endl;
}

void remplir_reservation (struct Reservation &resa, int num, int tarif)
{
    resa.num_chambre=num;
    resa.tarif = tarif;
    do
    {
        cout<<"Nombre de nuits "<<endl;
        cin>>resa.nbNuits;
    }
    while (resa.nbNuits <=0);
}

void affiche_reservation (Reservation resa)
{
    cout<<"Nb nuits : "<<resa.nbNuits<<endl;
    cout<<"Numero Chambre "<<resa.num_chambre<<endl;
    cout<<"Tarif choisi"<<resa.tarif<<endl;
}
struct Hotel remplir_hotel ()
{
    struct Hotel h;
    h.nb_Resa = 0;
    h.nb_Room = 0;
    int i;
    do
    {
        cout<<"Combien de chambres dans l'hotel ?"<<endl;
        cin>>h.nb_Room;
    }
    while (h.nb_Room <1 || h.nb_Room>MAXCHAMBRE);
    for (i=0; i<h.nb_Room; i++)
    {
        h.T_Room[i]= remplir_chambre(i+1);
    }
    return h;
}



void ajoute_une_reservation(struct Hotel &h)
{
    if (h.nb_Resa<MAXNUITS)
    {
        remplir_reservation(h.T_Resa[h.nb_Resa],rand()%h.nb_Room+1, rand()%3);
        h.nb_Resa++;
        cout<<h.nb_Resa<<endl;
    }
}

void affiche_hotel (struct Hotel h)
{
    int i;
    cout<<"LES CHAMBRES "<<h.nb_Room<<endl;
    for (i=0; i<h.nb_Room; i++)
    {
        affiche_chambre(h.T_Room[i]);
    }
    cout<<"LES RESERVATIONS"<<h.nb_Resa<<endl;
    for (i=0; i<h.nb_Resa; i++)
    {
        affiche_reservation(h.T_Resa[i]);
    }
}

void chiffre_affaire(struct Hotel h, int &gain, int & nb_client)
{
    gain = 0;
    nb_client = 0;
    int i;
    for (i=0; i<h.nb_Resa; i++)
    {
        gain += h.T_Room[h.T_Resa[i].num_chambre-1].prix[h.T_Resa[i].tarif]*h.T_Resa[i].nbNuits;
        nb_client += h.T_Room[h.T_Resa[i].num_chambre-1].simples + 2*h.T_Room[h.T_Resa[i].num_chambre-1].doubles;
    }
}
int main (void)
{
    srand(time(NULL));
    Hotel hot;
    int gain, nb;
    char rep;
    hot = remplir_hotel();
    do
    {
        ajoute_une_reservation(hot);
        cout<<"une autre ?"<<endl;
        cin>>rep;
    }
    while (rep=='o');

    affiche_hotel(hot);
    chiffre_affaire(hot,gain, nb);
    cout<<"Gain total : "<<gain<<endl;
    cout<<"Nombre de clients "<<nb<<endl;

    return 0;
}
