Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<stdio.h>
- #include<string.h>
- using namespace std;
- class student{
- private:
- char nume[30];
- public:
- void citire_stud(void);
- void afisare_rezultat(void);
- char* sortare_nume(void);
- };
- void student::citire_stud(void)
- {
- cout<<"Introduceti informatiile legate de student:"<<endl;
- cout<<"Numele studentului este: ";
- gets(nume);
- cout<<"\n";
- }
- char *student::sortare_nume(void){
- return nume;
- }
- void student::afisare_rezultat(void){
- cout<<nume<<endl;
- }
- int main(){
- int i, n, ok;
- student stud[15], aux;
- cout <<"Numar de studenti: "; cin >> n;
- getchar();
- for(i = 0;i < n; i++)
- stud[i].citire_stud();
- do{
- ok = 0;
- for(i= 0; i < n-1;i++)
- if(strcmp(stud[i].sortare_nume(),stud[i+1].sortare_nume()) > 0){
- ok = 1;
- aux = stud[i];
- stud[i] = stud[i+1];
- stud[i+1]=aux;
- }
- } while(ok);
- cout<<"Studenti ordonati alfabetic sunt: \n";
- for(i = 0;i < n; i++)
- stud[i].afisare_rezultat();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment