Advertisement
captainIBM

Untitled

Apr 3rd, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 48.42 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. int main(int argc, char **argv)
  6. {
  7.     double answer;
  8.     printf("|*************************** Welcome to the exercise_4 ! ***************************|\n");
  9.     printf("|                                                                                   |\n");
  10.     printf("|                                                                                   |\n");
  11.     printf("|In this program we will be able to evaluate all the students we want !             |\n");
  12.     printf("|                                                                                   |\n");
  13.     printf("|                                                                                   |\n");
  14.     printf("|Would you like to enter in the program ? Press [1/0] ( 1 -> Enter || 0 -> Quit)    |\n");
  15.     printf("|                                                                                   |\n");
  16.     printf("|                                                                                   |\n");
  17.     printf("|***********************************************************************************|\n");
  18.     printf("\n\nChoice : ");
  19.     scanf("%lf", &answer);
  20.     system("cls");
  21.     while((int)answer<0 || (int)answer>1){
  22.                 printf("Error, please enter a correct value : ");
  23.                 scanf("%lf",&answer);
  24.                 system("cls");
  25.             }
  26.     while(answer==1){
  27.         double menuloop = 1;
  28.         int *answerArray=NULL;
  29.         int *studentArray=NULL;
  30.         int *statsArray=NULL;
  31.         int rangeStats;
  32.         int dataRange;
  33.         int initStats = 0;
  34.         int mark;
  35.         int maxIndex;
  36.         int max = 0;
  37.         int min = 0;
  38.         int maxStudent= 0;
  39.         int minStudent= 0;
  40.         int class;
  41.         double average = 0;
  42.         double nbAnswer;
  43.         int init = 0;
  44.         int initAnswer = 0;
  45.         double valueAnswer;
  46.         double nbStudent;
  47.         int valueStudent;
  48.         double studentTag;
  49.         double studentAnswer;
  50.         double underMenu2;
  51.         double underMenu3;
  52.         double answerUnderMenu2;
  53.         double questionChange;
  54.         double answerChange;
  55.         double modifySelect;
  56.         double changeValue;
  57.         double modifyService;
  58.         double underMenu4;
  59.         int existStudent = 0;
  60.         int verifStudent = 0;
  61.         int studentNumber;
  62.         srand(time(NULL));
  63.         while(menuloop==1){
  64.             double menuanswer;
  65.             int i;
  66.             int j=0;
  67.             int a = 1;
  68.             printf("\n\n|**************************************** Menu ****************************************|\n");
  69.             printf("|                                                                                      |\n");
  70.             printf("|                                                                                      |\n");
  71.             printf("|Select the option you want :                                                          |\n");
  72.             printf("|                                                                                      |\n");
  73.             printf("|1 Select the correction of the questions, and display it                              |\n");
  74.             printf("|2 Enter the number of students you want, their answers and their service number       |\n");
  75.             printf("|3 Modify the array                                                                    |\n");
  76.             printf("|4 Display result of a student                                                         |\n");
  77.             printf("|5 Display statistics                                                                  |\n");
  78.             printf("|6 Menu of the array generation                                                        |\n");
  79.             printf("|7 Reset the array                                                                     |\n");
  80.             printf("|8 Exit the menu                                                                       |\n");
  81.             printf("|                                                                                      |\n");
  82.             printf("|**************************************************************************************|\n");
  83.             printf("\n\nChoice :");
  84.             scanf("%lf",&menuanswer);
  85.             system("cls");
  86.             while((int)menuanswer<=0 ||(int)menuanswer>8){
  87.                 printf("Error, please enter a correct value : ");
  88.                 scanf("%lf",&menuanswer);
  89.                 system("cls");
  90.             }
  91.             switch((int)menuanswer){
  92.                 case 1:{
  93.                     double underMenuAnswer;
  94.                     double menuloop2=1;
  95.                     while(menuloop2 == 1){
  96.                     printf("\n\nWhat do you want to do ?\n");
  97.                     printf("1\\Enter the correction\n\n");
  98.                     printf("2\\Display the correction\n\n");
  99.                     printf("3\\Exit\n\n");
  100.                     printf("\n\nChoice :");
  101.                     scanf("%lf",&underMenuAnswer);
  102.                     system("cls");
  103.                     while((int)underMenuAnswer<=0 ||(int)underMenuAnswer>3){
  104.                         printf("Error, please enter a correct value : ");
  105.                         scanf("%lf",&underMenuAnswer);
  106.                         system("cls");
  107.                     }
  108.                     switch((int)underMenuAnswer){
  109.                         case 1:{                    // CORRECTION MENU
  110.                                 if(initAnswer == 1){
  111.                                 printf("\n\nPlease, reset or modify the array before trying to select an other correction ! ");
  112.                                 break;
  113.                                 }
  114.                                 printf("\n\nHow many questions are there ? (Select a value between 10 and 100)\n");
  115.                                 printf("Choice : ");
  116.                                 scanf("%lf",&nbAnswer);
  117.                                 system("cls");
  118.                                 while((int)nbAnswer<10 || (int)nbAnswer>100){
  119.                                     printf("\n\nThere is no interest in doing an evaluation of 0 or more than 100 questions. Please enter a value between 10 and 100\n");
  120.                                     printf("Value : ");
  121.                                     scanf("%lf",&nbAnswer);
  122.                                     system("cls");
  123.                                 }
  124.                                 answerArray=malloc(sizeof(int)*nbAnswer);
  125.                                 for(i=0;i<(int)nbAnswer;i++){               // ENTRY OF THE CORRECTION
  126.                                     printf("Question number %d : ",i+1);
  127.                                     scanf("%lf",&valueAnswer);
  128.                                     system("cls");
  129.                                     while((int)valueAnswer<=0 ||(int)valueAnswer>5){
  130.                                         printf("\n\nYou can not enter a negative number, a 0 or a higher number than 5 as a correction. An answer is between 1 and 5 !");
  131.                                         printf("Value : ");
  132.                                         scanf("%lf",&valueAnswer);
  133.                                         system("cls");
  134.                                     }
  135.                                     answerArray[i]=(int)valueAnswer;
  136.                                 }
  137.                                 initAnswer = 1;
  138.                                 break;
  139.                         }
  140.                         case 2:{
  141.                             if(initAnswer == 0){
  142.                                 printf("Enter a correction before trying to display it !");
  143.                                 break;
  144.                             }
  145.                             printf("The good answers are : \n");
  146.                             for(i=0;i<(int)nbAnswer;i++){
  147.                                 printf("Question %d : %d | ",i+1,answerArray[i]);
  148.                                 if(i%6==5){
  149.                                     printf("\n");
  150.                                 }
  151.                             }
  152.  
  153.                         }
  154.                         case 3:{
  155.                             menuloop2=0;
  156.                             break;
  157.                         }
  158.  
  159.                     }
  160.                 }
  161.  
  162.                     break;
  163.                 }
  164.                 case 2:{                        // MANANGING STUDENT
  165.                     if(initAnswer == 0){
  166.                         printf("Error, please enter a correction before trying to manage the students results");
  167.                         break;
  168.                     }
  169.                     printf("\n\nEnter the number of students you want : ");
  170.                     scanf("%lf",&nbStudent);
  171.                     system("cls");
  172.                     while((int)nbStudent<0 || (int)nbStudent == 0 ){
  173.                         printf("\n\nYou can not enter a 0 or a negative number as a number of student. Please enter a correct value : ");
  174.                         scanf("%lf",&nbStudent);
  175.                         system("cls");
  176.                     }
  177.                     valueStudent = ((int)nbAnswer+1)*(int)nbStudent;
  178.                     studentArray = malloc(sizeof(int)*valueStudent);
  179.                     for(i=0;i<valueStudent;i++){                    // ENTRY OF A STUDENT
  180.                             if(i%((int)nbAnswer+1) == 0){
  181.                                 j++;
  182.                                 printf("Please, enter the service number of the student %d : ",j);
  183.                                 scanf("%lf",&studentTag);
  184.                                 system("cls");
  185.                                 while(studentTag/10000 < 1 || studentTag/100000 >=1 || (int)studentTag<=0){
  186.                                     printf("Error, the service number of a student has to be entered with 5 numbers ! ");
  187.                                     printf("Student number : ");
  188.                                     scanf("%lf",&studentTag);
  189.                                     system("cls");
  190.                                 }
  191.                                 studentArray[i] = (int)studentTag;
  192.                             }
  193.                             if(i%((int)nbAnswer+1) != 0){
  194.                                 printf("Response %d of the student number %g : ",a,studentTag);
  195.                                 scanf("%lf",&studentAnswer);
  196.                                 system("cls");
  197.                                 while((int)studentAnswer<1 || (int)studentAnswer>5){
  198.                                     printf("Error, please enter a correct value. Answer needs to be between 1 and 5 : ");
  199.                                     scanf("%lf",&studentAnswer);
  200.                                     system("cls");
  201.                                 }
  202.                                 studentArray[i] = (int)studentAnswer;
  203.                                 a++;
  204.                                 if(a%((int)nbAnswer+1) == 0){
  205.                                     a=1;
  206.                                 }
  207.                             }
  208.                     }
  209.                     init = 1;
  210.                     break;
  211.                 }
  212.                 case 3:{
  213.                     if(initAnswer == 0){
  214.                         printf("Before trying to modify the array, please enter the correction in the array !");
  215.                         break;
  216.                     }
  217.                     if (init == 0){
  218.                         printf("Before trying to modify the array, please enter the students in the array !");
  219.                         break;
  220.                     }
  221.                     int menuloop3 = 1;
  222.                     while(menuloop3 == 1){                      // MODIFY ARRAY
  223.                         printf("|********************MENU**********************|\n");
  224.                         printf("|What do you want to modify in the array ?     |\n");
  225.                         printf("|                                              |\n");
  226.                         printf("|1 Modify the correction                       |\n");
  227.                         printf("|2 Modify the service number of a student      |\n");
  228.                         printf("|3 Modify the answers of a student             |\n");
  229.                         printf("|4 Exit                                        |\n");
  230.                         printf("|                                              |\n");
  231.                         printf("|----------------------------------------------|\n");
  232.                         scanf("%lf",&underMenu2);
  233.                         system("cls");
  234.                         while((int)underMenu2<=0 || (int)underMenu2>4){
  235.                             printf("Error, please enter a correct value : ");
  236.                             scanf("%lf",&underMenu2);
  237.                             system("cls");
  238.                         }
  239.                         switch((int)underMenu2){
  240.                             case 1:{                            // MODIFY SELECTION OF THE CORRECTION
  241.                                 printf("\n\nWould you like to modify a specific question or all ? (0 -> specific question /\\ 1 -> All the questions )\n");
  242.                                 printf("Choice : ");
  243.                                 scanf("%lf",&answerUnderMenu2);
  244.                                 system("cls");
  245.                                 while((int)answerUnderMenu2<0 ||(int)answerUnderMenu2>1){
  246.                                     printf("Error, enter a correct value : ");
  247.                                     scanf("%lf",&answerUnderMenu2);
  248.                                     system("cls");
  249.                                 }
  250.                                 if(answerUnderMenu2 == 1){              // ANSWER SELECTED FOR CORRECTION
  251.                                     for(i=0;i<(int)nbAnswer;i++){
  252.                                         printf("Question number %d : ",i+1);
  253.                                         scanf("%lf",&valueAnswer);
  254.                                         system("cls");
  255.                                         while((int)valueAnswer<=0 ||(int)valueAnswer>5){
  256.                                             printf("\n\nYou can not enter a negative number, a 0 or a higher number than 5 as a correction. An answer is between 1 and 5 !");
  257.                                             printf("Value : ");
  258.                                             scanf("%lf",&valueAnswer);
  259.                                             system("cls");
  260.                                         }
  261.                                         answerArray[i]=(int)valueAnswer;
  262.                                     }
  263.                                 }else{
  264.                                     printf("The good answers are : \n");            // DISPLAY THEM
  265.                                     for(i=0;i<(int)nbAnswer;i++){
  266.                                         printf("Question %d : %d | ",i+1,answerArray[i]);
  267.                                         if(i%6==5){
  268.                                             printf("\n");
  269.                                         }
  270.                                     }
  271.                                     printf("\n\nWhich question would you like to change ?");
  272.                                     scanf("%lf",&questionChange);
  273.                                     while((int)questionChange<=0 ||(int)questionChange>(int)nbAnswer){
  274.                                         printf("\n\nThis question does not exist ! The questions are from 1 to %g ! Please enter a correct value : ",nbAnswer);
  275.                                         scanf("%lf",&questionChange);
  276.                                         system("cls");
  277.                                     }
  278.                                     printf("\n\nThe response of the question number %g is : %d ",questionChange,answerArray[(int)questionChange-1]);
  279.                                     printf("\n\nEnter the new value : ");
  280.                                     scanf("%lf",&answerChange);
  281.                                     system("cls");
  282.                                     while((int)answerChange<=0 ||(int)answerChange>5){
  283.                                         printf("\n\nError, enter a correct value, between 1 and 5 : ");
  284.                                         scanf("%lf",&answerChange);
  285.                                         system("cls");
  286.                                     }
  287.                                     answerArray[(int)questionChange-1]=(int)answerChange;
  288.                                 }
  289.                                 break;
  290.                             }
  291.                             case 2:{                        // SELECTION OF THE STUDENT YOU WANT
  292.                                 verifStudent=0;
  293.                                 printf("\n\nList of students : \n");
  294.                                 for(i=0;i<valueStudent;i++){
  295.                                     if(i%((int)nbAnswer+1)== 0){
  296.                                         printf(" Student %d ||",studentArray[i]);
  297.                                     }
  298.                                 }
  299.                                 printf("Enter the student you want to modify : ");
  300.                                 scanf("%lf",&modifySelect);
  301.                                 while(modifySelect/10000 < 1 || modifySelect/100000 >=1 || (int)modifySelect<=0){
  302.                                     printf("Error, the service number of a student has to be entered with 5 numbers ! ");
  303.                                     printf("Student number : ");
  304.                                     scanf("%lf",&modifySelect);
  305.                                     system("cls");
  306.                                 }
  307.                                 while(verifStudent == 0){
  308.                                     for(i=0;i<valueStudent;i++){
  309.                                         if(studentArray[i] == (int)modifySelect){
  310.                                             verifStudent=1;
  311.                                         }
  312.                                     }
  313.                                     if(verifStudent==0){
  314.                                         printf("Error, this student does not exist. Please enter a correct number : ");
  315.                                         scanf("%lf",&modifySelect);
  316.                                         system("cls");
  317.                                     }
  318.                                 }
  319.                                 printf("\n\nNow modify his service number : ");             // MODIFY A STUDENT
  320.                                 scanf("%lf",&modifyService);
  321.                                 while(modifyService/10000 < 1 || modifyService/100000 >=1 || (int)modifyService<=0){
  322.                                     printf("Error, the service number of a student has to be entered with 5 numbers ! ");
  323.                                     printf("Student number : ");
  324.                                     scanf("%lf",&modifyService);
  325.                                     system("cls");
  326.                                 }
  327.                                 while(existStudent == 0){
  328.                                     for(i=0;i<valueStudent;i++){
  329.                                         if(studentArray[i] == (int)modifyService){
  330.                                             existStudent++;
  331.                                         }
  332.                                     }
  333.                                     if(existStudent==0){
  334.                                         break;
  335.                                     }
  336.                                     if(existStudent>0){
  337.                                         printf("Error, this student already exists. Please enter a unique number : ");
  338.                                         scanf("%lf",&modifyService);
  339.                                         system("cls");
  340.                                         existStudent=0;
  341.                                     }
  342.  
  343.                                 }
  344.                                 printf("His service number is now : %g ",modifyService);
  345.                             break;
  346.                             }
  347.                             case 3:{                    // DISPLAY AND MODIFY ANSWERS OF A STUDENT
  348.                                 verifStudent=0;
  349.                                 printf("\n\nList of students : \n");
  350.                                 for(i=0;i<valueStudent;i++){
  351.                                     if(i%((int)nbAnswer+1)== 0){
  352.                                         printf(" Student %d ||",studentArray[i]);
  353.                                     }
  354.                                 }
  355.                                 printf("Enter the student you want to modify : ");
  356.                                 scanf("%lf",&modifySelect);
  357.                                 while(modifySelect/10000 < 1 || modifySelect/100000 >=1 || (int)modifySelect<=0){
  358.                                     printf("Error, the service number of a student has to be entered with 5 numbers ! ");
  359.                                     printf("Student number : ");
  360.                                     scanf("%lf",&modifySelect);
  361.                                     system("cls");
  362.                                 }
  363.                                 while(verifStudent == 0){
  364.                                     for(i=0;i<valueStudent;i++){
  365.                                         if(studentArray[i] == (int)modifySelect){
  366.                                             verifStudent=1;
  367.                                         }
  368.                                     }
  369.                                     if(verifStudent==0){
  370.                                         printf("Error, this student does not exist. Please enter a correct number : ");
  371.                                         scanf("%lf",&modifySelect);
  372.                                         system("cls");
  373.                                     }
  374.  
  375.                                 }
  376.                                 printf("Here is the answers of the student :");
  377.                                 for(i=0;i<valueStudent;i++){
  378.                                     if(studentArray[i] == (int)modifySelect){
  379.                                         for(j=0;j<nbAnswer;j++){
  380.                                             printf(" Question %d : %d ||",j+1,studentArray[i+j+1]);
  381.                                         }
  382.                                     }
  383.                                 }
  384.                                 printf("Modify his answers : ");
  385.                                 for(i=0;i<valueStudent;i++){
  386.                                     if(studentArray[i] == (int)modifySelect){
  387.                                         for(j=0;j<nbAnswer;j++){
  388.                                             printf(" Question %d : \n",j+1);
  389.                                             scanf("%lf",&changeValue);
  390.                                             system("cls");
  391.                                             while((int)changeValue<1 || (int)changeValue>5){
  392.                                                 printf("Error, answer needs to be between 1 and 5. Correct value : ");
  393.                                                 scanf("%lf",&changeValue);
  394.                                                 system("cls");
  395.                                             }
  396.                                             studentArray[i+j+1]=(int)changeValue;
  397.                                         }
  398.                                     }
  399.                                 }
  400.                             }
  401.                             case 4:{
  402.                                 menuloop3 = 0;
  403.                                 break;
  404.                             }
  405.                         }
  406.                     }
  407.                     break;
  408.                 }
  409.                 case 4:{                    // SELECTION OF THE STUDENTS AND GET HIS ANSWERS
  410.                     if(initAnswer == 0){
  411.                         printf("Before trying to display a student, please enter the correction in the array !");
  412.                         break;
  413.                     }
  414.                     if (init == 0){
  415.                         printf("Before trying to display a student, please enter the students in the array !");
  416.                         break;
  417.                     }
  418.                     verifStudent=0;
  419.                     printf("\n\nList of students : \n");
  420.                     for(i=0;i<valueStudent;i++){
  421.                         if(i%((int)nbAnswer+1)== 0){
  422.                             printf(" Student %d ||",studentArray[i]);
  423.                         }
  424.                     }
  425.                     printf("Enter the student you want to modify : ");
  426.                     scanf("%lf",&modifySelect);
  427.                     while(modifySelect/10000 < 1 || modifySelect/100000 >=1 || (int)modifySelect<=0){
  428.                         printf("Error, the service number of a student has to be entered with 5 numbers ! ");
  429.                         printf("Student number : ");
  430.                         scanf("%lf",&modifySelect);
  431.                         system("cls");
  432.                     }
  433.                     while(verifStudent == 0){
  434.                         for(i=0;i<valueStudent;i++){
  435.                             if(studentArray[i] == (int)modifySelect){
  436.                                 verifStudent=1;
  437.                             }
  438.                         }
  439.                         if(verifStudent==0){
  440.                             printf("Error, this student does not exist. Please enter a correct number : ");
  441.                             scanf("%lf",&modifySelect);
  442.                             system("cls");
  443.                         }
  444.                     }
  445.                     printf("Here is the answers of the student :");
  446.                     for(i=0;i<valueStudent;i++){
  447.                         if(studentArray[i] == (int)modifySelect){
  448.                             for(j=0;j<nbAnswer;j++){
  449.                                 printf(" Question %d : %d ||",j+1,studentArray[i+j+1]);
  450.                             }
  451.                         }
  452.                     }
  453.                     break;
  454.                 }
  455.                 case 5:{                // MENU STATS
  456.                     if(initAnswer == 0){
  457.                         printf("Before trying to display statistics, please enter the correction in the array !");
  458.                         break;
  459.                     }
  460.                     if (init == 0){
  461.                         printf("Before trying to display statistics, please enter the students in the array !");
  462.                         break;
  463.                     }
  464.                     int menuloop4 = 1;
  465.                     rangeStats=1+(int)nbAnswer+((int)nbStudent*2);
  466.                     statsArray = malloc(sizeof(int)*rangeStats);
  467.                     a=0;
  468.                     while(menuloop4 == 1){
  469.                         dataRange=(int)nbAnswer+1;
  470.                         printf("\n\n|***************************Stats***************************|\n");
  471.                         printf("|Here you can have some statistics :                        |\n");
  472.                         printf("|                                                           |\n");
  473.                         printf("|1 Display the average of the evaluation                    |\n");
  474.                         printf("|2 Display the mark of each student                         |\n");
  475.                         printf("|3 Display the class of each student                        |\n");
  476.                         printf("|4 Display the best student                                 |\n");
  477.                         printf("|5 Display the most successful question                     |\n");
  478.                         printf("|6 Display the less successful question                     |\n");
  479.                         printf("|7 Display the number of good answers for each question     |\n");
  480.                         printf("|8 Exit                                                     |\n");
  481.                         printf("|                                                           |\n");
  482.                         printf("|                                                           |\n");
  483.                         printf("|***********************************************************|\n");
  484.                         printf("\n\nGo to : ");
  485.                         scanf("%lf",&underMenu4);
  486.                         system("cls");
  487.                         while((int)underMenu4<=0 || (int)underMenu4>9){
  488.                             printf("Error, please enter a correct value : ");
  489.                             scanf("%lf",&underMenu4);
  490.                             system("cls");
  491.                         }
  492.                         switch((int)underMenu4){
  493.                             case 1:{                // INITIALISATION OF THE AVERAGE AND ALL OTHER STATS
  494.                                 mark = 0;
  495.                                 if(initStats==1){
  496.                                     printf("\n\nThe average is %.2lf \n\n",average);
  497.                                     break;
  498.                                 }
  499.                                 for(i=0;i<=valueStudent;i++){
  500.                                     if(i%((int)nbAnswer+1)==0){
  501.                                             if(j==(int)nbAnswer){
  502.                                                 statsArray[dataRange]=mark;
  503.                                                 dataRange++;
  504.                                             }
  505.                                         average=average+mark;
  506.                                         mark = 0;
  507.                                         j=0;
  508.                                         statsArray[dataRange]=studentArray[i];
  509.                                         dataRange++;
  510.                                     }
  511.                                     if(i%((int)nbAnswer+1)!=0){
  512.                                         if(studentArray[i]==answerArray[j]){
  513.                                             mark++;
  514.                                         }
  515.                                         j++;
  516.                                     }
  517.  
  518.  
  519.                                 }
  520.                                 average=average/(int)nbStudent;
  521.                                 printf("\n\nThe average is : %.2lf \n\n",average);
  522.                                 initStats = 1;
  523.                                 break;
  524.                             }
  525.                             case 2:{                // SPECIFIC STUDENT STATS
  526.                                 if(initStats==0){
  527.                                     printf("\n\nPlease initialize the statistics with the average first !\n\n");
  528.                                     break;
  529.                                 }
  530.                                 mark = 0;
  531.                                 for(i=0;i<=valueStudent;i++){
  532.                                     if(i%((int)nbAnswer+1)==0){
  533.                                             if(j==(int)nbAnswer){
  534.                                                 printf("\n\nThe student %d got a mark of : %d\n\n",statsArray[dataRange-1],statsArray[dataRange]);
  535.                                                 dataRange++;
  536.                                             }
  537.                                         j=0;
  538.                                         dataRange++;
  539.                                     }
  540.                                     if(i%((int)nbAnswer+1)!=0){
  541.                                         if(studentArray[i]==answerArray[j]){
  542.                                             mark++;
  543.                                         }
  544.                                         j++;
  545.                                     }
  546.                                 }
  547.                                 break;
  548.                             }
  549.                             case 3:{                    // EACH STUDENT STATS
  550.                                 if(initStats==0){
  551.                                     printf("\n\nPlease calculate the average before trying to get classes. It doesn't mean anything to get the class without the average anyway ...\n\n");
  552.                                     break;
  553.                                 }
  554.                                 for(i=dataRange;i<rangeStats;i=i+2){
  555.                                     class=statsArray[i+1]-(int)average;
  556.                                     if(class>0){
  557.                                         printf("\n\nThe student %d is at %c %d from the average\n\n",statsArray[i],43,class);
  558.                                     }
  559.                                     if(class<0){
  560.                                         printf("\n\nThe student %d is at %c %d from the average\n\n",statsArray[i],45,class);
  561.                                     }
  562.                                     if(class == 0){
  563.                                         printf("\n\nThe student %d is on the average\n\n",statsArray[i]);
  564.                                     }
  565.                                 }
  566.                                 break;
  567.                             }
  568.                             case 4:{                    // WORST AND BEST STUDENT
  569.                                 if(initStats==0){
  570.                                     printf("\n\nPlease initialize the statistics with the average first !\n\n");
  571.                                     break;
  572.                                 }
  573.                                 min=statsArray[dataRange+1];
  574.                                 minStudent=statsArray[dataRange];
  575.                                 for(i=dataRange;i<rangeStats-1;i=i+2){
  576.                                     if(statsArray[i+1]>max){
  577.                                         max=statsArray[i];
  578.                                         maxStudent=statsArray[i+1];
  579.                                     }
  580.                                     if(statsArray[i+1]<min){
  581.                                         min=statsArray[i];
  582.                                         minStudent=statsArray[i+1];
  583.                                     }
  584.                                 }
  585.                                 printf("\n\nThe best student is the number %d with a mark of %d !\n",max,maxStudent);
  586.                                 printf("The worst student is the number %d with a mark of %d !\n\n",min,minStudent);
  587.                                 break;
  588.                             }
  589.                             case 5:{
  590.                                 if(initStats==0){                       // STATS MAX
  591.                                     printf("\n\nPlease initialize the statistics with the average first !\n\n");
  592.                                     break;
  593.                                 }
  594.                                 for(i=1;i<=(int)nbAnswer;i++){
  595.                                     statsArray[i] = 0;
  596.                                 }
  597.                                 for(i=0;i<=valueStudent;i++){
  598.                                     if(i%((int)nbAnswer+1)==0){
  599.                                         j=0;
  600.                                     }
  601.                                     if(i%((int)nbAnswer+1)!=0){
  602.                                         if(studentArray[i]==answerArray[j]){
  603.                                             statsArray[j+1]++;
  604.                                         }
  605.                                         j++;
  606.                                     }
  607.                                 }
  608.                                 for(i=1;i<=(int)nbAnswer;i++){
  609.                                     if((int)max<(int)statsArray[i]){
  610.                                         max=statsArray[i];
  611.                                         maxIndex=i;
  612.                                     }
  613.                                 }
  614.                                 printf("\n\nThe most successful question is the number %d\n\n",maxIndex);
  615.                                 break;
  616.                             }
  617.                             case 6:{                        // STATS MIN
  618.                                 if(initStats==0){
  619.                                     printf("\n\nPlease initialize the statistics with the average first !\n\n");
  620.                                     break;
  621.                                 }
  622.                                 min = statsArray[1];
  623.                                 for(i=1;i<=(int)nbAnswer;i++){
  624.                                     statsArray[i] = 0;
  625.                                 }
  626.                                 for(i=0;i<=valueStudent;i++){
  627.                                     if(i%((int)nbAnswer+1)==0){
  628.                                         j=0;
  629.                                     }
  630.                                     if(i%((int)nbAnswer+1)!=0){
  631.                                         if(studentArray[i]==answerArray[j]){
  632.                                             statsArray[j+1]++;
  633.                                         }
  634.                                         j++;
  635.                                     }
  636.                                 }
  637.                                 for(i=1;i<=(int)nbAnswer;i++){
  638.                                     if((int)min>(int)statsArray[i]){
  639.                                         min=i;
  640.                                     }
  641.                                 }
  642.                                 printf("\n\nThe less successful question is the number %d\n\n",min);
  643.                                 break;
  644.                             }
  645.                             case 7:{                // STATS NUMBER OF GOOD ANSWERS
  646.                                 if(initStats==0){
  647.                                     printf("\n\nPlease initialize the statistics with the average first !\n\n");
  648.                                     break;
  649.                                 }
  650.                                 for(i=1;i<=(int)nbAnswer;i++){
  651.                                     printf("\n\nThe question %d as %d good answers !\n\n",i,statsArray[i]);
  652.                                 }
  653.                                 break;
  654.                             }
  655.                             case 8:{
  656.                                 menuloop4=0;
  657.                                 break;
  658.                             }
  659.  
  660.                         }
  661.                     }
  662.                     break;
  663.                 }
  664.                 case 6:{                           // INITIATION OF THE ARRAY
  665.                     if(init == 1 || initAnswer == 1){
  666.                         printf("Please, reset the array before trying to generate an other one !");
  667.                         break;
  668.                     }
  669.                     printf("|*********************Array********************|\n");
  670.                     printf("|                                              |\n");
  671.                     printf("|Would you like to load a random array ? [1]   |\n");
  672.                     printf("|Or load a pre-completed array ? [0]           |\n");
  673.                     printf("|                                              |\n");
  674.                     printf("|**********************************************|\n");
  675.                     printf("\n\nChoice : ");
  676.                     scanf("%lf",&underMenu3);
  677.                     system("cls");
  678.                     while((int)underMenu3<0 || (int)underMenu3>2){
  679.                             printf("Error, please enter a correct value : ");
  680.                             scanf("%lf",&underMenu3);
  681.                             system("cls");
  682.                         }
  683.                     switch((int)underMenu3){
  684.                         case 1:{                        // RANDOM EVERYTHING !
  685.                             nbAnswer = rand()%91+10;
  686.                             answerArray = malloc(sizeof(int)*(int)nbAnswer);
  687.                             nbStudent = rand()%501+1;
  688.                             valueStudent = ((int)nbAnswer+1)*(int)nbStudent;
  689.                             studentArray = malloc(sizeof(int)*valueStudent);
  690.                             for(i=0;i<valueStudent;i++){
  691.                                 if(i%((int)nbAnswer+1)==0){
  692.                                     studentNumber=rand();
  693.                                     while(studentNumber/10000<1){
  694.                                         studentNumber=rand();
  695.                                     }
  696.                                     studentArray[i]=studentNumber;
  697.                                 }
  698.                                 if(i%((int)nbAnswer+1)!=0){
  699.                                     studentArray[i]=rand()%5+1;
  700.                                 }
  701.                             }
  702.                             init = 1;
  703.                             initAnswer = 1;
  704.                             break;
  705.                         }
  706.                         case 0:{                        // PRE-LOADED ARRAY
  707.                             nbAnswer=10;
  708.                             answerArray = malloc(sizeof(int)*(int)nbAnswer);
  709.                             nbStudent = 10;
  710.                             valueStudent = ((int)nbAnswer+1)*(int)nbStudent;
  711.                             studentArray = malloc(sizeof(int)*valueStudent);
  712.                             answerArray[0]=1;
  713.                             answerArray[1]=2;
  714.                             answerArray[2]=3;
  715.                             answerArray[3]=4;
  716.                             answerArray[4]=5;
  717.                             answerArray[5]=4;
  718.                             answerArray[6]=3;
  719.                             answerArray[7]=2;
  720.                             answerArray[8]=1;
  721.                             answerArray[9]=5;
  722.                             studentArray[0]=12345;
  723.                             studentArray[1]=1;
  724.                             studentArray[2]=2;
  725.                             studentArray[3]=3;
  726.                             studentArray[4]=4;
  727.                             studentArray[5]=5;
  728.                             studentArray[6]=5;
  729.                             studentArray[7]=4;
  730.                             studentArray[8]=2;
  731.                             studentArray[9]=3;
  732.                             studentArray[10]=1;
  733.                             studentArray[11]=12340;
  734.                             studentArray[12]=1;
  735.                             studentArray[13]=4;
  736.                             studentArray[14]=5;
  737.                             studentArray[15]=2;
  738.                             studentArray[16]=5;
  739.                             studentArray[17]=4;
  740.                             studentArray[18]=4;
  741.                             studentArray[19]=2;
  742.                             studentArray[20]=1;
  743.                             studentArray[21]=1;
  744.                             studentArray[22]=54121;
  745.                             studentArray[23]=1;
  746.                             studentArray[24]=2;
  747.                             studentArray[25]=3;
  748.                             studentArray[26]=4;
  749.                             studentArray[27]=5;
  750.                             studentArray[28]=5;
  751.                             studentArray[29]=4;
  752.                             studentArray[30]=2;
  753.                             studentArray[31]=3;
  754.                             studentArray[32]=1;
  755.                             studentArray[33]=13245;
  756.                             studentArray[34]=5;
  757.                             studentArray[35]=2;
  758.                             studentArray[36]=2;
  759.                             studentArray[37]=4;
  760.                             studentArray[38]=1;
  761.                             studentArray[39]=5;
  762.                             studentArray[40]=4;
  763.                             studentArray[41]=1;
  764.                             studentArray[42]=3;
  765.                             studentArray[43]=1;
  766.                             studentArray[44]=14225;
  767.                             studentArray[45]=2;
  768.                             studentArray[46]=2;
  769.                             studentArray[47]=2;
  770.                             studentArray[48]=4;
  771.                             studentArray[49]=1;
  772.                             studentArray[50]=5;
  773.                             studentArray[51]=4;
  774.                             studentArray[52]=1;
  775.                             studentArray[53]=2;
  776.                             studentArray[54]=1;
  777.                             studentArray[55]=23545;
  778.                             studentArray[56]=4;
  779.                             studentArray[57]=2;
  780.                             studentArray[58]=2;
  781.                             studentArray[59]=1;
  782.                             studentArray[60]=1;
  783.                             studentArray[61]=5;
  784.                             studentArray[62]=2;
  785.                             studentArray[63]=1;
  786.                             studentArray[64]=4;
  787.                             studentArray[65]=1;
  788.                             studentArray[66]=14545;
  789.                             studentArray[67]=4;
  790.                             studentArray[68]=4;
  791.                             studentArray[69]=5;
  792.                             studentArray[70]=1;
  793.                             studentArray[71]=1;
  794.                             studentArray[72]=5;
  795.                             studentArray[73]=2;
  796.                             studentArray[74]=2;
  797.                             studentArray[75]=5;
  798.                             studentArray[76]=1;
  799.                             studentArray[77]=11111;
  800.                             studentArray[78]=2;
  801.                             studentArray[79]=2;
  802.                             studentArray[80]=2;
  803.                             studentArray[81]=2;
  804.                             studentArray[82]=1;
  805.                             studentArray[83]=5;
  806.                             studentArray[84]=3;
  807.                             studentArray[85]=1;
  808.                             studentArray[86]=4;
  809.                             studentArray[87]=4;
  810.                             studentArray[88]=22522;
  811.                             studentArray[89]=2;
  812.                             studentArray[90]=3;
  813.                             studentArray[91]=5;
  814.                             studentArray[92]=2;
  815.                             studentArray[93]=1;
  816.                             studentArray[94]=1;
  817.                             studentArray[95]=3;
  818.                             studentArray[96]=1;
  819.                             studentArray[97]=4;
  820.                             studentArray[98]=4;
  821.                             studentArray[99]=23345;
  822.                             studentArray[100]=1;
  823.                             studentArray[101]=1;
  824.                             studentArray[102]=1;
  825.                             studentArray[103]=2;
  826.                             studentArray[104]=1;
  827.                             studentArray[105]=5;
  828.                             studentArray[106]=4;
  829.                             studentArray[107]=1;
  830.                             studentArray[108]=4;
  831.                             studentArray[109]=4;
  832.                             init = 1;
  833.                             initAnswer = 1;
  834.                             break;
  835.                         }
  836.                     }
  837.                     break;
  838.                 }
  839.                 case 7:{                            // RESET THE ARRAY
  840.                     if(initAnswer == 0 && init == 0){
  841.                         printf("\n\nThere is nothing to reset. Please, try to focus !\n\n");
  842.                         break;
  843.                     }
  844.                     if(initAnswer == 1 && init == 0){
  845.                         free(answerArray);
  846.                         free(statsArray);
  847.                         initAnswer=0;
  848.                         printf("\n\nThe answers have been reseted !\n\n");
  849.                         break;
  850.                     }
  851.                     if(initAnswer == 0 && init == 1){
  852.                         free(studentArray);
  853.                         free(statsArray);
  854.                         init = 0;
  855.                         printf("\n\nthe students have been reseted !\n\n");
  856.                         break;
  857.                     }
  858.                     if(initAnswer == 1 && init == 1){
  859.                         free(answerArray);
  860.                         free(studentArray);
  861.                         free(statsArray);
  862.                         printf("\n\nThe array has been reseted !\n\n");
  863.                         init = 0;
  864.                         initAnswer = 0;
  865.                         break;
  866.                     }
  867.                 }
  868.                 case 8:{                // QUITE MENU
  869.                     menuloop=0;
  870.                     break;
  871.                 }
  872.             }
  873.         }
  874.  
  875.     printf("\n\n\n********* Would you like to restart the program ? Press [1/0] *********\n\n");
  876.     printf("/!\\ Any error will close the program /!\\ \n\n");
  877.     printf("Choice : ");
  878.     scanf("%lf",&answer);
  879.     system("cls");
  880.     free(statsArray);
  881.     free(answerArray);
  882.     free(studentArray);
  883.     }
  884.     return 0;
  885. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement