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-