Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string.h>
- using namespace std;
- ofstream out("elevi.txt");
- void Spatiu();
- int main() {
- int n, note[100];
- char elevi[32][100], aux[30], elevi2[32][100];
- cout << "Numarul de elevi: "; cin >> n;
- int poz = 0;
- while(poz < n) {
- cout << "- Nume: "; cin >> elevi[poz];
- cout << "- Nota: "; cin >> note[poz];
- poz++;
- }
- Spatiu();
- out << "Nr.crt\t\tNume Elev\t\tNota" << endl;
- for(int i = 0; i < n; i++)
- out << i << "\t\t " << elevi[i] << " \t\t" << note[i] << endl;
- for(int i = 0; i < n; i++) strcpy(elevi2[i], elevi[i]);
- for(int i = 0; i < n; i++) {
- for(int j = i + 1; j < n; j++) {
- if(strcmp(elevi[i], elevi[j]) > 0) {
- strcpy(aux, elevi[i]);
- strcpy(elevi[i], elevi[j]);
- strcpy(elevi[j], aux);
- }
- }
- }
- Spatiu();
- for(int i = 0; i < n; i++)
- out << elevi[i] << endl;
- for(int i = 0; i < n; i++) {
- for(int j = i + 1; j < n; j++) {
- if(note[i] < note[j]) {
- int auxA = note[i];
- note[i] = note[j];
- note[j] = auxA;
- strcpy(aux, elevi2[i]);
- strcpy(elevi2[i], elevi2[j]);
- strcpy(elevi2[j], aux);
- }
- }
- }
- Spatiu();
- for(int i = 0; i < n; i++)
- out << elevi2[i] << " - " << note[i] << endl;
- out.close();
- return 0;
- }
- void Spatiu() {
- out << endl;
- for(int i = 0; i < 50; i++) out << "-";
- out << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement