Advertisement
Mentosan

-

Oct 19th, 2018
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string.h>
  4.  
  5. using namespace std;
  6.  
  7. ofstream out("elevi.txt");
  8.  
  9. void Spatiu();
  10.  
  11. int main() {
  12.  
  13.     int n, note[100];
  14.     char elevi[32][100], aux[30], elevi2[32][100];
  15.     cout << "Numarul de elevi: ";   cin >> n;
  16.  
  17.     int poz = 0;
  18.     while(poz < n) {
  19.         cout << "- Nume: "; cin >> elevi[poz];
  20.         cout << "- Nota: "; cin >> note[poz];
  21.         poz++;
  22.     }
  23.  
  24.     Spatiu();
  25.     out << "Nr.crt\t\tNume Elev\t\tNota" << endl;
  26.     for(int i = 0; i < n; i++)
  27.         out << i << "\t\t  " << elevi[i] << "   \t\t" << note[i] << endl;
  28.  
  29.     for(int i = 0; i < n; i++)  strcpy(elevi2[i], elevi[i]);
  30.     for(int i = 0; i < n; i++) {
  31.         for(int j = i + 1; j < n; j++) {
  32.             if(strcmp(elevi[i], elevi[j]) > 0) {
  33.                 strcpy(aux, elevi[i]);
  34.                 strcpy(elevi[i], elevi[j]);
  35.                 strcpy(elevi[j], aux);
  36.             }
  37.         }
  38.     }
  39.  
  40.     Spatiu();
  41.     for(int i = 0; i < n; i++)
  42.         out << elevi[i] << endl;
  43.  
  44.     for(int i = 0; i < n; i++) {
  45.         for(int j = i + 1; j < n; j++) {
  46.             if(note[i] < note[j]) {
  47.                 int auxA = note[i];
  48.                 note[i] = note[j];
  49.                 note[j] = auxA;
  50.                 strcpy(aux, elevi2[i]);
  51.                 strcpy(elevi2[i], elevi2[j]);
  52.                 strcpy(elevi2[j], aux);
  53.             }
  54.         }
  55.     }
  56.  
  57.     Spatiu();
  58.     for(int i = 0; i < n; i++)
  59.         out << elevi2[i] << " - " << note[i] << endl;
  60.     out.close();
  61.     return 0;
  62. }
  63.  
  64. void Spatiu() {
  65.     out << endl;
  66.     for(int i = 0; i < 50; i++) out << "-";
  67.     out << endl;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement