Advertisement
J00ker

Untitled

Nov 6th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.43 KB | None | 0 0
  1. #ifndef COD_H_INCLUDED
  2. #define COD_H_INCLUDED
  3.  
  4. /// 1
  5. void VerificareLitera() {
  6.     char c;
  7.     printf("c = ");
  8.     c = getchar();
  9.     if(c >= 'A' && c <= 'Z')
  10.         c -= ('A' - 'a');
  11.     printf("%c\n", c);
  12. }
  13.  
  14. /// 2
  15. void Operatie() {
  16.     int a, b, rez, er = 0;
  17.     char op;
  18.     printf("operatie: ");
  19.     scanf("%d %c %d", &a, &op, &b);
  20.     //printf("\n%d %c %d", a, op, b);
  21.     switch(op) {
  22.         case '+': rez = a + b; break;
  23.         case '-': rez = a - b; break;
  24.         case '*': rez = a * b; break;
  25.         case '/':
  26.             if(a == 0) er = 1;
  27.             else rez = a / b;
  28.             break;
  29.         case '%': rez = a % b; break;
  30.         default:               break;
  31.     }
  32.     if(er) printf("a trebuie sa fie nenul!\n");
  33.     else   printf("%d\n", rez);
  34. }
  35.  
  36. /// 3
  37. /// A
  38. struct Candidat {
  39.     int nr_legitimatie;
  40.     char nume[64];
  41.     int nota_mate, nota_info, nota_bac;
  42.     double medie;
  43.     char admis, buget;
  44. };
  45.  
  46. /// B
  47. #define MedieAdmitere(nota_mate, nota_info, nota_bac) ((nota_mate + nota_info) * 0.4 + nota_bac * 0.2)
  48.  
  49. /// C
  50. #define PragPromovabilitate 5
  51.  
  52. /// D
  53. struct Candidat C[100];
  54. int n, neadmisi = 0;
  55.  
  56. void AfisareCandidati() {
  57.     int i;
  58.     printf("\n");
  59.     for(i = 0; i < n; i++) {
  60.         printf("%d\t", C[i].nr_legitimatie);
  61.         printf("%s\t", C[i].nume, 64, stdin);
  62.         printf("%d %d %d\n", C[i].nota_mate, C[i].nota_info, C[i].nota_bac);
  63.     }
  64. }
  65.  
  66. void SwapCandidati(struct Candidat *a, struct Candidat *b) {
  67.     struct Candidat aux;
  68.     aux = *a;
  69.     *a = *b;
  70.     *b = aux;
  71. }
  72.  
  73. void SortareCandidati(int dupaNume) {
  74.     int i, j;
  75.  
  76.     for(i = 0; i < n - 1; i++) {
  77.         for(j = i + 1; j < n; j++) {
  78.             if((dupaNume && (strcmp(C[i].nume, C[j].nume) >= 0)) ||
  79.               (!dupaNume && (C[i].medie < C[j].medie)))
  80.                 SwapCandidati(&C[i], &C[j]);
  81.         }
  82.     }
  83. }
  84.  
  85. void CitireCandidati() {
  86.     int i;
  87.  
  88.     printf("n = "); scanf("%d", &n);
  89.     for(i = 0; i < n; i++) {
  90.         printf("Numar legitimatie: ");
  91.         scanf("%d", &C[i].nr_legitimatie);
  92.         getchar();
  93.  
  94.         printf("Nume: ");
  95.         fgets(C[i].nume, 64, stdin);
  96.         C[i].nume[ strlen(C[i].nume) - 1 ] = '\0';
  97.  
  98.         printf("Nota mate: ");
  99.         scanf("%d", &C[i].nota_mate);
  100.         printf("Nota info: ");
  101.         scanf("%d", &C[i].nota_info);
  102.         printf("Nota bac: ");
  103.         scanf("%d", &C[i].nota_bac);
  104.  
  105.         C[i].medie = MedieAdmitere(nota_mate, nota_info, nota_bac);
  106.         C[i].admis = (medie > PragPromovabilitate) ? "Y" : "N";
  107.         if(C[i].admis == "N") neadmisi++;
  108.     }
  109.     //AfisareCandidati();
  110.     SortareCandidati(1);
  111.     AfisareCandidati();
  112. }
  113.  
  114. /// E
  115. void CompletareBuget() {
  116.     int i;
  117.     int bugetari = (n - neadmisi) * 3 / 4;
  118.  
  119.     SortareCandidati(0);
  120.  
  121.     for(i = 0; i < n; i++) {
  122.         if(i < bugetari)
  123.             C[i].buget = "Y";
  124.         else if(C[i].admis == "Y")
  125.             C[i].buget = "N";
  126.     }
  127.     SortareCandidati(1);
  128.     AfisareCandidati();
  129. }
  130.  
  131. /// F
  132. void AfisareCandidati2(int optiune) {
  133.     int i, j;
  134.  
  135.     switch(optiune) {
  136.         case 1:
  137.             SortareCandidati(1);
  138.             break;
  139.         case 2:
  140.             for(i = 0; i < n; i++)
  141.                 for(j = i + 1; j < n; j++)
  142.                     if(C[i].buget == "Y") {
  143.                         printf("%d\t", C[i].nr_legitimatie);
  144.                         printf("%s\t", C[i].nume, 64, stdin);
  145.                         printf("%d %d %d\n", C[i].nota_mate, C[i].nota_info, C[i].nota_bac);
  146.                     }
  147.             break;
  148.         case 3:
  149.             for(i = 0; i < n; i++)
  150.                 for(j = i + 1; j < n; j++)
  151.                     if(C[i].buget == "N") {
  152.                         printf("%d\t", C[i].nr_legitimatie);
  153.                         printf("%s\t", C[i].nume, 64, stdin);
  154.                         printf("%d %d %d\n", C[i].nota_mate, C[i].nota_info, C[i].nota_bac);
  155.                     }
  156.             break;
  157.         case 4:
  158.             SortareCandidati(0);
  159.             for(i = 0; i < n; i++)
  160.                 for(j = i + 1; j < n; j++)
  161.                     if(C[i].admis == "N") {
  162.                         printf("%d\t", C[i].nr_legitimatie);
  163.                         printf("%s\t", C[i].nume, 64, stdin);
  164.                         printf("%d %d %d\n", C[i].nota_mate, C[i].nota_info, C[i].nota_bac);
  165.                     }
  166.             break;
  167.         default: break;
  168.     }
  169. }
  170.  
  171. /// 4
  172.  
  173.  
  174. #endif // COD_H_INCLUDED
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement