Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.55 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <string.h>
  5.  
  6. #define ISENSize 30
  7. #define noteSize 10
  8.  
  9. char* names[50] = {
  10.     "Dedra Ackman",
  11.     "Fred Thielen",
  12.     "Salome Zurcher",
  13.     "Elanor Iliff",
  14.     "Arline Lansberry",
  15.     "Columbus Jaycox",
  16.     "Vella Mccardell",
  17.     "Charlotte Rademacher",
  18.     "Magnolia Batt",
  19.     "Nelda Chapell",
  20.     "Lise Charrier",
  21.     "Danita Reichling",
  22.     "Angella Sica",
  23.     "Octavia Printz",
  24.     "Connie Morreale",
  25.     "Melodie Bechtold",
  26.     "Klara Bulter",
  27.     "Marni Irvine",
  28.     "Lorine Milum",
  29.     "Deonna Mcclure",
  30.     "Mei Strozier",
  31.     "Roselia Yelvington",
  32.     "Johnna Bridge",
  33.     "Lurlene Lady",
  34.     "Arlyne Sayer",
  35.     "Lashunda Hamada",
  36.     "Ines Larsen",
  37.     "Pearlene Hembree",
  38.     "Kory Gildea",
  39.     "Jenna Rothfuss",
  40.     "Lino Tuttle",
  41.     "Dario Steed",
  42.     "Larissa Maroney",
  43.     "Kelle Keel",
  44.     "Jack Horton",
  45.     "Eura Duane",
  46.     "Providencia Langer",
  47.     "Randee Rathjen",
  48.     "Hayley Gulley",
  49.     "Eugenia Brownson",
  50.     "Jo Helbig",
  51.     "Margarito Mcmahon",
  52.     "Yuette Hartline",
  53.     "Melida Hardeman",
  54.     "Jerilyn Lapine",
  55.     "Weldon Marquess",
  56.     "Lyla Obando",
  57.     "Magali Perrotti",
  58.     "Prudence Gaccione",
  59.     "Peggie Denney"
  60. };
  61.  
  62. typedef struct Student_{
  63.     char* name;
  64.     char* promotion;
  65.     float marks[noteSize];
  66. } Student;
  67.  
  68. float mark(Student student){
  69.     float marks = 0;
  70.     for(int i = 0; i < noteSize; i++){
  71.         marks += student.marks[i];
  72.     }
  73.     marks /= noteSize;
  74.     return marks;
  75. }
  76.  
  77. float markClass(char* class, Student student[]){
  78.     float markClass = 0;
  79.     int counter = 0;
  80.     for(int i = 0; i < ISENSize; i++){
  81.         if(strcmp(student[i].promotion, class) == 0){
  82.             markClass += mark(student[i]);
  83.             counter++;
  84.         }
  85.     }
  86.     markClass /= counter;
  87.     return markClass;
  88. }
  89.  
  90. Student randomizeStudent(){
  91.     Student student;
  92.     student.name = names[rand() % 50];
  93.  
  94.     int random = rand() % 4;
  95.     if(random == 0)
  96.         student.promotion = "CIR1";
  97.     if(random == 1)
  98.         student.promotion = "CIR2";
  99.     if(random == 2)
  100.         student.promotion = "CIR3";
  101.     if(random == 3)
  102.         student.promotion = "M1";
  103.     if(random == 4)
  104.         student.promotion = "M2";
  105.  
  106.     for(int i = 0; i < noteSize; i++)
  107.         student.marks[i] = rand() % 20;
  108.     return student;
  109. }
  110.  
  111. int main(int argc, char* argv[]){
  112.     srand(time(NULL));
  113.  
  114.     //Générer aléatoirement les étudiants
  115.     Student isen[ISENSize];
  116.     for(int i = 0; i < ISENSize; i++){
  117.         isen[i] = randomizeStudent();
  118.     }
  119.     char* result = argv[1];
  120.  
  121.     printf("La moyenne de la classe de %s est de %f\n", result, markClass(result, isen));
  122.     return 0;
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement