SlideShare una empresa de Scribd logo
1 de 6
Descargar para leer sin conexión
D:Asenmainmain.cpp                                                                   25 Ìàé 2008 ã. 13:00

#include <iostream>
#include <string>

using namespace std;



/*********************************
*     class Student
*********************************/
class Student{

private:
    int number;
    string name;
    string pName;
    double uspeh;
    double dohod;

public:
    Student(){
        number=0;
        name="";
        pName="";
        uspeh=0;
        dohod=0;
    }

      Student( Student & s);

      // задава стойности на променливите
      void init(int number,string name,double uspeh,double dohod){
          this->number=number;
          this->name=name;
          this->uspeh=uspeh;
          this->dohod=dohod;
          this->pName=properName();   // Тъй като списъка на ученици може да бъде
                                            // извеждан повече от веднъж, съхраняваме
                                            // крадкия запис на името, като за сметка
                                            // на малко повече памет, спестяваме
                                            // повторна обработка на имената


      }

      string properName();
      string getProperName(){ return this->pName; };
      string getName(){ return this->name; };
      int getNumber(){ return this->number; }
      double getUspeh(){ return this->uspeh; }
      double getDohod(){ return this->dohod; }




};
                                                              -1-
D:Asenmainmain.cpp                                                                                  25 Ìàé 2008 ã. 13:00



Student::Student( Student & s){
    number=s.getNumber();
    name=s.getName();
    uspeh=s.getUspeh();
    dohod=s.getDohod();
    pName=s.getProperName();
}

// Тази функция взима променливата съдържаща пълните имена
// и отдеря от тях фамилията и инициалите
string Student::properName(){
        char fname=name[0];                                           //Първата буква от първото име
        char pname=name[(name.find(" ")+1)];                          //Първата буква от презимето


            int l=name.length();                                      //Взимаме дължината на името


            // Намираме частта на името, след първият интервал,
            // където ще тръсим фамилията
            string temp=name.substr((name.find(" ")+2),(l-1));
            temp=temp.substr((temp.find(" ")),(l-1));

            return temp+" "+fname+"."+pname+".";
      }

/*********************************
*     class Students
*********************************/
class Students{

private:
    int numStudents;                          // Брой на студентите
    Student * studentsArray;                  // Масив с всички ученици




public:
    Students(int n=0){
        numStudents=n;
        studentsArray=0;
        if(n > 0) this->init();
    }
    ~Students(){
        delete [] studentsArray;
    }
    void init();
    void inputStudent(int i);
    const void printStudents();
    void sort();
    void printStipendii(double,double);




};
                                                                      -2-
D:Asenmainmain.cpp                                                                     25 Ìàé 2008 ã. 13:00



// Създава масива с учениците, и извиква
// функция за въвеждане на информацията за всеки един
void Students::init(){
    if(numStudents > 0){
        studentsArray=new Student[numStudents];
        for(int i=0;i<numStudents;i++) this->inputStudent(i);
    }

}

// Въвежда информация от клавиатурата за всеки ученик
void Students::inputStudent(int i){
    int number;
    char name[51];
    double uspeh;
    double dohod;

      cout << "n----------------nnStudent: " << (i+1) << "nn";
      cout << "Nomer: ";
      cin >> number;
      bool validname=true;

      do{
            if(!validname) cout<<"*** Vuvedete imeto vuv format Ime Brezime Familiq ***n";
            cout << "Imena: ";
            cin.ignore();
            cin.getline(name,50);

            // Проверяваме дали в името има поне два интервала
            string testname=name;

            int tfind=testname.find(" ");
            if(tfind > 0 && tfind < 51){

            int l=testname.length();

            string temp=testname.substr((testname.find(" ")+2),(l-1));
            tfind=temp.find(" ");
            if(tfind > 0 && tfind < 51) validname=true;
            else validname=false;
            } else validname=false;
            // край на проверката


      }while(!validname);

      do{
          cout<<"Sreden uspeh [3.00 - 6.00]: ";
          cin >> uspeh;
      }while(uspeh<3 || uspeh>6);

      do{
            cout<<"Sreden dohod na 4len ot semeistvoto [1.00 - 999.99]: ";
            cin >> dohod;
                                                                 -3-
D:Asenmainmain.cpp                                                                          25 Ìàé 2008 ã. 13:00

      }while(dohod<1 || dohod>999.99);

      cout << "n----------------nn";

      studentsArray[i].init(number,name,uspeh,dohod);
}

// Изкарва списък на всички ученици
const void Students::printStudents(){

      cout<<"nSpisuk:nn";
      for(int i=0;i<numStudents;i++){
          cout<<studentsArray[i].getNumber()<<"t"
              <<studentsArray[i].getProperName()<<"t"
              <<studentsArray[i].getUspeh()<<"t"
              <<studentsArray[i].getDohod()<<"n";

      }

}

// Сортира учениците по критериите в условието
void Students::sort(){
    Student temp;

      for(int i=0;i<numStudents;i++)
          for(int j=(i+1);j<numStudents;j++){

                   if(
                         (studentsArray[i].getUspeh() < studentsArray[j].getUspeh()) ||

                             (studentsArray[i].getUspeh() == studentsArray[j].getUspeh() &&
                                 (studentsArray[i].getDohod() > studentsArray[j].getDohod() ||
                                     (studentsArray[i].getDohod() == studentsArray[j].getDohod() &&
                                         studentsArray[i].getNumber() > studentsArray[j].getNumber()
                                 )
                             )
                         )

                    ){
                         temp=studentsArray[i];
                         studentsArray[i]=studentsArray[j];
                         studentsArray[j]=temp;
                   }



            }
}




void Students::printStipendii(double M, double K){

      for(int i=0;i<numStudents;i++){
                                                        -4-
D:Asenmainmain.cpp                                                                 25 Ìàé 2008 ã. 13:00

            // Първото поле е стипендията
        cout << (studentsArray[i].getUspeh() >= 5.50 ? 100 :
                (((studentsArray[i].getUspeh() >= M && studentsArray[i].getDohod() < K)?60:0
)))<<"t"
                <<studentsArray[i].getNumber()<<"t"
                <<studentsArray[i].getProperName()<<"t"
                <<studentsArray[i].getUspeh()<<"t"
                <<studentsArray[i].getDohod()<<"n";
    }
}

/*********************************
*     функция main()
*********************************/
int main(){
    int numStudents=0;

      do{
          cout<<"Broi na u4enicite [10 - 500]: ";
          cin >> numStudents;
      }while(numStudents<10 || numStudents>500);



      Students s(numStudents);

      cout<<endl;

      s.printStudents();

      cout<<"nSortirane...n";
      s.sort();

      cout<<"nKlasirane:";
      s.printStudents();

      double M,K;

      cout<<endl;

      do{
          cout<<"Vuvedete M [3.00 - 5.49]: ";
          cin >> M;
      }while(M<3 || M>5.49);

      do{
          cout<<"Vuvedete K [1.00 - 999.99]: ";
          cin >> K;
      }while(K<1 || K>999.99);

      cout<<endl;

      s.printStipendii(M,K);

      cout<<endl<<endl;
                                                    -5-
D:Asenmainmain.cpp                                 25 Ìàé 2008 ã. 13:00

      cout<<"Bye!nnPress any key to exit.";

      system("pause >nul");
      return 0;
}




                                                -6-

Más contenido relacionado

Destacado

CV Roy Basoeki
CV Roy BasoekiCV Roy Basoeki
CV Roy Basoekitime4web
 
Miquel Martí i Pol
Miquel Martí i PolMiquel Martí i Pol
Miquel Martí i PolQuim Civil
 
0116-leadership-resilience-md
0116-leadership-resilience-md0116-leadership-resilience-md
0116-leadership-resilience-mdPat Sanaghan
 
Sulucionario electromagnetismo cheng
Sulucionario electromagnetismo cheng Sulucionario electromagnetismo cheng
Sulucionario electromagnetismo cheng Saku Garcia
 
Aspire one series service guide
Aspire one series service guideAspire one series service guide
Aspire one series service guideSetyo Prasadja
 
Beautiful Women Of China
Beautiful Women Of ChinaBeautiful Women Of China
Beautiful Women Of ChinaRen
 
Tarif jne-oke-2013-bdg-1-juni-2013
Tarif jne-oke-2013-bdg-1-juni-2013Tarif jne-oke-2013-bdg-1-juni-2013
Tarif jne-oke-2013-bdg-1-juni-2013ridwansf2
 
Creating the Startup The Accounting Panorama
Creating the Startup The Accounting PanoramaCreating the Startup The Accounting Panorama
Creating the Startup The Accounting PanoramaSteve Lines
 
Windows 8.1 Deployment - Tools, Tools, Tools
Windows 8.1 Deployment - Tools, Tools, ToolsWindows 8.1 Deployment - Tools, Tools, Tools
Windows 8.1 Deployment - Tools, Tools, ToolsRoel van Bueren
 
Monografia fic
Monografia ficMonografia fic
Monografia ficromercen
 

Destacado (20)

CV Roy Basoeki
CV Roy BasoekiCV Roy Basoeki
CV Roy Basoeki
 
Miquel Martí i Pol
Miquel Martí i PolMiquel Martí i Pol
Miquel Martí i Pol
 
0116-leadership-resilience-md
0116-leadership-resilience-md0116-leadership-resilience-md
0116-leadership-resilience-md
 
Que es google docs
Que es google docsQue es google docs
Que es google docs
 
Yg Ini 1
Yg Ini 1Yg Ini 1
Yg Ini 1
 
Sulucionario electromagnetismo cheng
Sulucionario electromagnetismo cheng Sulucionario electromagnetismo cheng
Sulucionario electromagnetismo cheng
 
Lulusan SMK PI class of 2014
Lulusan SMK PI class of 2014Lulusan SMK PI class of 2014
Lulusan SMK PI class of 2014
 
Hwswb
HwswbHwswb
Hwswb
 
Matematica docentes
Matematica docentesMatematica docentes
Matematica docentes
 
Aspire one series service guide
Aspire one series service guideAspire one series service guide
Aspire one series service guide
 
Beautiful Women Of China
Beautiful Women Of ChinaBeautiful Women Of China
Beautiful Women Of China
 
Synapseindia android apps (operating system)
Synapseindia android apps (operating system)Synapseindia android apps (operating system)
Synapseindia android apps (operating system)
 
Tarif jne-oke-2013-bdg-1-juni-2013
Tarif jne-oke-2013-bdg-1-juni-2013Tarif jne-oke-2013-bdg-1-juni-2013
Tarif jne-oke-2013-bdg-1-juni-2013
 
33 Period week
33 Period week33 Period week
33 Period week
 
Creating the Startup The Accounting Panorama
Creating the Startup The Accounting PanoramaCreating the Startup The Accounting Panorama
Creating the Startup The Accounting Panorama
 
Manual património cultural aula 14 - mosteiro de s. bento s. tirso - cópia
Manual património cultural   aula 14 - mosteiro de s. bento s. tirso - cópiaManual património cultural   aula 14 - mosteiro de s. bento s. tirso - cópia
Manual património cultural aula 14 - mosteiro de s. bento s. tirso - cópia
 
Windows 8.1 Deployment - Tools, Tools, Tools
Windows 8.1 Deployment - Tools, Tools, ToolsWindows 8.1 Deployment - Tools, Tools, Tools
Windows 8.1 Deployment - Tools, Tools, Tools
 
Changhong
ChanghongChanghong
Changhong
 
1st Grade Unit 6: Blue jay finds a way
1st Grade Unit 6: Blue jay finds a way1st Grade Unit 6: Blue jay finds a way
1st Grade Unit 6: Blue jay finds a way
 
Monografia fic
Monografia ficMonografia fic
Monografia fic
 

fdgdfgdfg

  • 1. D:Asenmainmain.cpp 25 Ìàé 2008 ã. 13:00 #include <iostream> #include <string> using namespace std; /********************************* * class Student *********************************/ class Student{ private: int number; string name; string pName; double uspeh; double dohod; public: Student(){ number=0; name=""; pName=""; uspeh=0; dohod=0; } Student( Student & s); // задава стойности на променливите void init(int number,string name,double uspeh,double dohod){ this->number=number; this->name=name; this->uspeh=uspeh; this->dohod=dohod; this->pName=properName(); // Тъй като списъка на ученици може да бъде // извеждан повече от веднъж, съхраняваме // крадкия запис на името, като за сметка // на малко повече памет, спестяваме // повторна обработка на имената } string properName(); string getProperName(){ return this->pName; }; string getName(){ return this->name; }; int getNumber(){ return this->number; } double getUspeh(){ return this->uspeh; } double getDohod(){ return this->dohod; } }; -1-
  • 2. D:Asenmainmain.cpp 25 Ìàé 2008 ã. 13:00 Student::Student( Student & s){ number=s.getNumber(); name=s.getName(); uspeh=s.getUspeh(); dohod=s.getDohod(); pName=s.getProperName(); } // Тази функция взима променливата съдържаща пълните имена // и отдеря от тях фамилията и инициалите string Student::properName(){ char fname=name[0]; //Първата буква от първото име char pname=name[(name.find(" ")+1)]; //Първата буква от презимето int l=name.length(); //Взимаме дължината на името // Намираме частта на името, след първият интервал, // където ще тръсим фамилията string temp=name.substr((name.find(" ")+2),(l-1)); temp=temp.substr((temp.find(" ")),(l-1)); return temp+" "+fname+"."+pname+"."; } /********************************* * class Students *********************************/ class Students{ private: int numStudents; // Брой на студентите Student * studentsArray; // Масив с всички ученици public: Students(int n=0){ numStudents=n; studentsArray=0; if(n > 0) this->init(); } ~Students(){ delete [] studentsArray; } void init(); void inputStudent(int i); const void printStudents(); void sort(); void printStipendii(double,double); }; -2-
  • 3. D:Asenmainmain.cpp 25 Ìàé 2008 ã. 13:00 // Създава масива с учениците, и извиква // функция за въвеждане на информацията за всеки един void Students::init(){ if(numStudents > 0){ studentsArray=new Student[numStudents]; for(int i=0;i<numStudents;i++) this->inputStudent(i); } } // Въвежда информация от клавиатурата за всеки ученик void Students::inputStudent(int i){ int number; char name[51]; double uspeh; double dohod; cout << "n----------------nnStudent: " << (i+1) << "nn"; cout << "Nomer: "; cin >> number; bool validname=true; do{ if(!validname) cout<<"*** Vuvedete imeto vuv format Ime Brezime Familiq ***n"; cout << "Imena: "; cin.ignore(); cin.getline(name,50); // Проверяваме дали в името има поне два интервала string testname=name; int tfind=testname.find(" "); if(tfind > 0 && tfind < 51){ int l=testname.length(); string temp=testname.substr((testname.find(" ")+2),(l-1)); tfind=temp.find(" "); if(tfind > 0 && tfind < 51) validname=true; else validname=false; } else validname=false; // край на проверката }while(!validname); do{ cout<<"Sreden uspeh [3.00 - 6.00]: "; cin >> uspeh; }while(uspeh<3 || uspeh>6); do{ cout<<"Sreden dohod na 4len ot semeistvoto [1.00 - 999.99]: "; cin >> dohod; -3-
  • 4. D:Asenmainmain.cpp 25 Ìàé 2008 ã. 13:00 }while(dohod<1 || dohod>999.99); cout << "n----------------nn"; studentsArray[i].init(number,name,uspeh,dohod); } // Изкарва списък на всички ученици const void Students::printStudents(){ cout<<"nSpisuk:nn"; for(int i=0;i<numStudents;i++){ cout<<studentsArray[i].getNumber()<<"t" <<studentsArray[i].getProperName()<<"t" <<studentsArray[i].getUspeh()<<"t" <<studentsArray[i].getDohod()<<"n"; } } // Сортира учениците по критериите в условието void Students::sort(){ Student temp; for(int i=0;i<numStudents;i++) for(int j=(i+1);j<numStudents;j++){ if( (studentsArray[i].getUspeh() < studentsArray[j].getUspeh()) || (studentsArray[i].getUspeh() == studentsArray[j].getUspeh() && (studentsArray[i].getDohod() > studentsArray[j].getDohod() || (studentsArray[i].getDohod() == studentsArray[j].getDohod() && studentsArray[i].getNumber() > studentsArray[j].getNumber() ) ) ) ){ temp=studentsArray[i]; studentsArray[i]=studentsArray[j]; studentsArray[j]=temp; } } } void Students::printStipendii(double M, double K){ for(int i=0;i<numStudents;i++){ -4-
  • 5. D:Asenmainmain.cpp 25 Ìàé 2008 ã. 13:00 // Първото поле е стипендията cout << (studentsArray[i].getUspeh() >= 5.50 ? 100 : (((studentsArray[i].getUspeh() >= M && studentsArray[i].getDohod() < K)?60:0 )))<<"t" <<studentsArray[i].getNumber()<<"t" <<studentsArray[i].getProperName()<<"t" <<studentsArray[i].getUspeh()<<"t" <<studentsArray[i].getDohod()<<"n"; } } /********************************* * функция main() *********************************/ int main(){ int numStudents=0; do{ cout<<"Broi na u4enicite [10 - 500]: "; cin >> numStudents; }while(numStudents<10 || numStudents>500); Students s(numStudents); cout<<endl; s.printStudents(); cout<<"nSortirane...n"; s.sort(); cout<<"nKlasirane:"; s.printStudents(); double M,K; cout<<endl; do{ cout<<"Vuvedete M [3.00 - 5.49]: "; cin >> M; }while(M<3 || M>5.49); do{ cout<<"Vuvedete K [1.00 - 999.99]: "; cin >> K; }while(K<1 || K>999.99); cout<<endl; s.printStipendii(M,K); cout<<endl<<endl; -5-
  • 6. D:Asenmainmain.cpp 25 Ìàé 2008 ã. 13:00 cout<<"Bye!nnPress any key to exit."; system("pause >nul"); return 0; } -6-