Thread: explaination for this C code

  1. #1
    Registered User
    Join Date
    May 2021
    Posts
    1

    Question explaination for this C code

    hi everyone, i have a presenttion tomorrow where i will explain a code that i didn't write, please if someone could explain it for me, it would a life saving for me, thanks in advance.

    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;
    }
    Attached Files Attached Files

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,343
    This doesn't look obfuscated: the variable names are perhaps a little concise, but that could be okay. The function names look like they have relevant meaning, as does the text to be printed. There are even comments!

    So, you should give this a try yourself. You can post your attempt over here for members to review, although in that case I suggest translating the names, text, and comments to English.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. in need of a little explaination..
    By unknown2007 in forum C Programming
    Replies: 3
    Last Post: 11-01-2011, 09:54 PM
  2. explaination of code
    By gtr_s15 in forum C++ Programming
    Replies: 7
    Last Post: 02-02-2006, 02:25 AM
  3. Explaination of EOF
    By Stinky in forum C Programming
    Replies: 1
    Last Post: 11-05-2003, 01:18 PM
  4. relation explaination
    By asli_masti in forum C Programming
    Replies: 1
    Last Post: 08-28-2003, 06:55 AM
  5. Explaination
    By rogerlpe in forum C++ Programming
    Replies: 4
    Last Post: 03-11-2002, 07:28 AM

Tags for this Thread