Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char **p, **ptr;
// déclaration des prototypes des fonctions
char * saisir();
float traitement(char IndiceP, int NPE);
void afficher(char **NomAt, char**NomRA, char***NomE, char**IndicePE,
float **IndPE, float*TIndAt, float TotalID,
int NAtF, int*NEAt, int**NPE);
// définition des fonctions
char* saisir(){
char* Tab=NULL,intro[20];
scanf("%s",intro);
Tab=malloc(strlen(intro)+1);
if(Tab!=NULL)
strcpy(Tab,intro);
else
{printf("memoire insuffisante");
exit(-1);
}
return Tab;
} // fin saisir
float traiterPiece(char IndiceP,int NPE){
float indPE;
int taux;
if(IndiceP=='A'|| IndiceP=='a')
taux=20;
else if(IndiceP=='B' || IndiceP=='b')
taux=10;
else //if(indice=='C')
taux=5;
indPE=NPE*taux;
return indPE;
} // fin traiterPiece
void afficher(char **NomAt, char**NomRA, char***NomE, char**IndicePE,
float **IndPE, float*TIndAt, float TotalID,
int NAtF, int*NEAt, int**NPE){
printf("\tFICHE DE GESTION DES INDEMNITES DES EMPLOYES DE MOTOPROD (par journee)\n");
printf("------------------------------------------------------------------------------------------\n");
for(p=NomAt; p<NomAt+NAtF; p++) // boucle sur les ateliers
{
printf(" Nom Atelier de fabrication %d: %s,", p-NomAt+1, *p);
printf(" Nom Responsable Atelier %d: %s\n", p-NomAt+1, NomRA[p-NomAt]);
printf("\t\tNom\t\tNPE\t\tIndAticePE\t\tIndAtPE\n");
for(ptr=NomE[p-NomAt]; ptr<NomE[p-NomAt]+NEAt[p-NomAt]; ptr++) // boucle sur les employées
{
printf("\t\t%s", *ptr);
printf("\t\t%d", *(NPE[p-NomAt]+(ptr-NomE[p-NomAt])) );
printf("\t\t %c", *(IndicePE[p-NomAt]+(ptr-NomE[p-NomAt])) );
printf("\t\t%.2f\n", *(IndPE[p-NomAt]+(ptr-NomE[p-NomAt])) );
}
printf("\t---------------------------------------------------------------------------------\n");
printf("\t\t\t\t\t\tTotal Indemnite %.2f DH\n", TIndAt[p-NomAt]);
printf("------------------------------------------------------------------------------------\n");
}
printf(" Totaux des idemnites des employes du groupe MotoProd pendant la journee: %.2f DH\n\n", TotalID);
free( NomAt);
free( NomRA );
free( NomE );
free( NPE );
free( IndicePE );
free( IndPE );
free( NEAt );
free( TIndAt );
}// fin afficher
// fonction main()
int main() {
char **NomAt, **NomRA, ***NomE, **IndicePE ;
float **IndPE, *TIndAt, TotalID=0;
int NAtF, *NEAt, **NPE;
printf("Donner le nombre des ateliers: ");
scanf("%d", &NAtF);
NomAt=malloc(NAtF*sizeof( char* ));
NomRA=malloc(NAtF*sizeof( char* ));
NEAt=malloc(NAtF*sizeof(int));
TIndAt=malloc(NAtF*sizeof(float));
NomE=malloc(NAtF*sizeof( char** ));
NPE=malloc(NAtF*sizeof( int* ));
IndicePE=malloc(NAtF*sizeof( char* ));
IndPE=malloc(NAtF*sizeof( float* ));
// Entrées et traitement des données
for(p=NomAt; p<NomAt+NAtF; p++) // boucle sur les ateliers
{
printf("Entrer le nom de l'atelier %d: ", p-NomAt+1);
NomAt[p-NomAt]=saisir();
printf("Entrer le nom de responsable atelier %d: ", p-NomAt+1);
NomRA[p-NomAt]=saisir();
printf("Donner le nombre des employes de fabrication de l'atelier %d: ", p-NomAt+1);
scanf("%d", NEAt+(p-NomAt) );
NomE[p-NomAt]=malloc(NEAt[p-NomAt]*sizeof( char* ));
NPE[p-NomAt]=malloc(NEAt[p-NomAt]*sizeof( int ));
IndicePE[p-NomAt]=malloc(NEAt[p-NomAt]*sizeof( char ));
IndPE[p-NomAt]=malloc(NEAt[p-NomAt]*sizeof( float ));
TIndAt[p-NomAt]=0;
for(ptr=NomE[p-NomAt]; ptr<NomE[p-NomAt]+NEAt[p-NomAt]; ptr++) // boucle sur les employees
{
printf("Pour l'employe %d de l'atelier %d donner ces informations:\n", ptr-NomE[p-NomAt]+1, p-NomAt+1);
printf("\tNom: ");
*ptr=saisir();
printf("\tNombre de pieces fabriquees: ");
scanf("%d", NPE[p-NomAt]+(ptr-NomE[p-NomAt]) );
printf("\tIndAtice accorde: ");
getchar();
scanf("%c", IndicePE[p-NomAt]+(ptr-NomE[p-NomAt]) );
// traitement Pieces
*(IndPE[p-NomAt]+(ptr-NomE[p-NomAt]))=traiterPiece(*(IndicePE[p-NomAt]+(ptr-NomE[p-NomAt])),
*(NPE[p-NomAt]+(ptr-NomE[p-NomAt])));
TIndAt[p-NomAt]+=*(IndPE[p-NomAt]+(ptr-NomE[p-NomAt]));
TotalID+=*(IndPE[p-NomAt]+(ptr-NomE[p-NomAt]));
} // fin for employes
printf("\n");
}// fin for ateliers
// Affichage
afficher(NomAt, NomRA, NomE, IndicePE,
IndPE, TIndAt,TotalID,
NAtF, NEAt, NPE);
getch();
return 0;
}