Помогите дописать сортировку

  • Автор темы figo20089
  • Дата начала
F

figo20089

Гость
#1
[codebox]#include <iostream>
#include <string>
using namespace std;
const int N=2
;


class Osoba
{
public:
string imja_osobu;
int data_narodzhennja;
int vik;

public:
Osoba():imja_osobu("0"),data_narodzhennja(0),vik(0){}
Osoba(string a,int p,int n):imja_osobu(a),data_narodzhennja(p),vik(n){}
virtual void input();
virtual void print();
virtual void sort(Osoba& k,Osoba& l);
Osoba&Osoba::operator=(const Osoba& a);
bool Osoba::operator>(Osoba & a);
bool Osoba::operator<(Osoba & a);

};
void Osoba::input()
{
cout << "Input: "<< endl;
cout << "imja: ";
cin >> imja_osobu;
cout << "data_narodzhennja: ";
cin >>data_narodzhennja;
cout << "vik: ";
cin >> vik;
}
void Osoba::print()
{
cout << "imja:" << imja_osobu << endl;
cout << "data_narodzhennja: " << data_narodzhennja << endl;
cout << "vik: " << vik << endl;
}
void Osoba::sort(Osoba & k, Osoba & l)
{
int temp;
temp = k.vik;
k.vik = l.vik+1;
l.vik+1 = temp;
}
bool Osoba::operator>(Osoba & a)
{
if(vik>a.vik)
{
return 1;
}
else
{
return 0;
}
}
bool Osoba::operator<(Osoba & a)
{
if(vik<a.vik)
{
return 1;
}
else
{
return 0;
}
}
Osoba&Osoba::operator=(const Osoba& a)
{
if(this!=&a)
{
imja_osobu=a.imja_osobu;
data_narodzhennja=a.data_narodzhennja;
vik=a.vik;
}
return *this;
}
class Student:public Osoba{
public:
string Navchalnui_zaklad;
int Rik_zakinchennja_navchalnogo_zakladu;
public:
Student();
Student(string a,int p,int n,string o,int z);
virtual void input();
virtual void print();
Student&Student::operator=(const Student& a);
bool Student::operator>(Student & a);
bool Student::operator<(Student & a);
};
Student::Student()
{
imja_osobu='0';
data_narodzhennja=0;
vik=0;
Navchalnui_zaklad='0';
Rik_zakinchennja_navchalnogo_zakladu=0;
}
Student::Student(string a,int p,int n,string o,int z)
{
imja_osobu=a;
data_narodzhennja=p;
vik=n;
Navchalnui_zaklad=o;
Rik_zakinchennja_navchalnogo_zakladu=z;
}
bool Student::operator>(Student& a)
{
if(vik>a.vik)
{
return 1;
}
else
{
return 0;
}
}
bool Student::operator<(Student & a)
{
if(vik<a.vik)
{
return 1;
}
else
{
return 0;
}
}
Student&Student::operator=(const Student& a)
{
if(this!=&a)
{
imja_osobu=a.imja_osobu;
data_narodzhennja=a.data_narodzhennja;
vik=a.vik;
Navchalnui_zaklad=a.Navchalnui_zaklad;
Rik_zakinchennja_navchalnogo_zakladu=a.Rik_zakinchennja_navchalnogo_zakladu;
}
return *this;
}
void Student::input()
{
cout << "Input imja studenta: "<< endl;
cin >> imja_osobu;
cout << "data_narodzhennja: ";
cin >>data_narodzhennja;
cout << "vik: ";
cin >> vik;
cout << "Navchalnui_zaklad: ";
cin >> Navchalnui_zaklad;
cout<<"Rik_zakinchennja_navchalnogo_zakladu: ";
cin>>Rik_zakinchennja_navchalnogo_zakladu;
}
void Student::print()
{
cout << "imja studenta: " << imja_osobu << endl;
cout << "data_narodzhennja: " << data_narodzhennja << endl;
cout << "vik: " << vik << endl;
cout << "Navchalnui_zaklad: " << Navchalnui_zaklad << endl;
cout<<"Rik_zakinchennja_navchalnogo_zakladu: "<<Rik_zakinchennja_navchalnogo_zakladu <<endl;
}
class Uchen:public Osoba{
private:
string Navchalnui_zaklad;
string Misce_prozhuvannja;
int Rik_zakinchennja_shkolu;
public:
Uchen();
Uchen(string a,int p,int n,string o,string r,int v);
virtual void input();
virtual void print();
Uchen&Uchen::operator=(const Uchen& a);
bool Uchen::operator>(Uchen & a);
bool Uchen::operator<(Uchen & a);
};
Uchen::Uchen()
{
imja_osobu='0';
data_narodzhennja=0;
vik=0;
Navchalnui_zaklad='0';
Misce_prozhuvannja='0';
Rik_zakinchennja_shkolu=0;
}
Uchen::Uchen(string a,int p,int n,string o,string r,int v)
{
imja_osobu=a;
data_narodzhennja=p;
vik=n;
Navchalnui_zaklad=o;
Misce_prozhuvannja=r;
Rik_zakinchennja_shkolu=v;
}
bool Uchen::operator>(Uchen & a)
{
if(vik>a.vik)
{
return 1;
}
else
{
return 0;
}
}
bool Uchen::operator<(Uchen & a)
{
if(vik<a.vik)
{
return 1;
}
else
{
return 0;
}
}
Uchen&Uchen::operator=(const Uchen& a)
{
if(this!=&a)
{
imja_osobu=a.imja_osobu;
data_narodzhennja=a.data_narodzhennja;
vik=a.vik;
Navchalnui_zaklad=a.Navchalnui_zaklad;
Misce_prozhuvannja=a.Misce_prozhuvannja;
Rik_zakinchennja_shkolu=a.Rik_zakinchennja_shkolu;
}
return *this;
}
void Uchen::input()
{
cout << "Input Imja_uchnja: "<< endl;

cin >> imja_osobu;
cout << "data_narodzhennja: ";
cin >>data_narodzhennja;
cout << "vik: ";
cin >> vik;
cout << "Navchalnui_zaklad: ";
cin >> Navchalnui_zaklad;
cout << "Misce_prozhuvannja: ";
cin >> Misce_prozhuvannja;
cout << "Rik_zakinchennja_shkolu: ";
cin >> Rik_zakinchennja_shkolu;
}
void Uchen::print()
{
cout << "Imja_uchnja: " << imja_osobu << endl;
cout << "data_narodzhennja: " <<data_narodzhennja << endl;
cout << "vik: " << vik << endl;
cout << "Navchalnui_zaklad: " << Navchalnui_zaklad << endl;
cout << "Misce_prozhuvannja: " << Misce_prozhuvannja << endl;
cout << "Rik_zakinchennja_shkolu: " << Rik_zakinchennja_shkolu << endl;
}
void poshyk(Osoba ** a,int n)
{
string imja;
cout << "Input imja osoby jaku potribno znaitu: " << endl;
cin >>imja;
int kilkist=0;
for(int i=0;i<n;i++)
{
if(a->imja_osobu==imja)
{
a->print();
kilkist++;
}
}
if(kilkist==0)
{
cout << "Takoji osobu nema" << endl;
}
}
void main()
{
Osoba *mas[N];
for(int i=0;i<N;i++)
{
char k;
do
{
cout << "Please input 1 dlja vvedennja danuh pro Studenta" << endl;
cout << "Please input 2 dlja vvedennja danuh pro Uchnja" << endl;
cin >> k;
}
while((k!='1')&&(k!='2'));
if(k=='1')
{
mas=new Student;
mas->input();
}
if(k=='2')
{
mas=new Uchen;
mas->input();
}
}
poshyk(mas,N);

cout << endl << endl;

for(int i=0;i<N;i++)
{
mas->print();
cout << endl;
}
for(int i=0;i>N;i++)
{
delete mas;
}

cin. get();
cin. get();
}[/codebox]