Alx09

Untitled

Apr 28th, 2020
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<string.h>
  4.  
  5. using namespace std;
  6.  
  7. class student{
  8. private:
  9. char nume[30];
  10. public:
  11. void citire_stud(void);
  12. void afisare_rezultat(void);
  13. char* sortare_nume(void);
  14. };
  15.  
  16. void student::citire_stud(void)
  17. {
  18. cout<<"Introduceti informatiile legate de student:"<<endl;
  19. cout<<"Numele studentului este: ";
  20. gets(nume);
  21. cout<<"\n";
  22. }
  23. char *student::sortare_nume(void){
  24. return nume;
  25. }
  26.  
  27. void student::afisare_rezultat(void){
  28. cout<<nume<<endl;
  29. }
  30.  
  31. int main(){
  32. int i, n, ok;
  33. student stud[15], aux;
  34. cout <<"Numar de studenti: "; cin >> n;
  35. getchar();
  36. for(i = 0;i < n; i++)
  37. stud[i].citire_stud();
  38. do{
  39. ok = 0;
  40. for(i= 0; i < n-1;i++)
  41. if(strcmp(stud[i].sortare_nume(),stud[i+1].sortare_nume()) > 0){
  42. ok = 1;
  43. aux = stud[i];
  44. stud[i] = stud[i+1];
  45. stud[i+1]=aux;
  46. }
  47.  
  48. } while(ok);
  49. cout<<"Studenti ordonati alfabetic sunt: \n";
  50. for(i = 0;i < n; i++)
  51. stud[i].afisare_rezultat();
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment