Advertisement
Guest User

Untitled

a guest
Jun 30th, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.21 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. #include<algorithm>
  4. #include<string>
  5. using namespace std;
  6. class young{
  7. protected:
  8.     string fn;
  9.     int age;
  10. public :
  11.     young(string a = "julia", int b = 20){
  12.         fn = a;
  13.         age = b;
  14.     }
  15.     ~young(){}
  16.     friend istream& operator>>(istream&, young &);
  17.     friend ostream& operator<<(ostream&, young &);
  18.        
  19. };
  20. class university {
  21. protected:
  22.     string name;
  23.     int fakult;
  24. public:
  25.     university(string a = "tsu", int b = 18){
  26.         name = a;
  27.         fakult = b;
  28.     }
  29.     ~university(){}
  30.     friend istream& operator>>(istream&, university &);
  31.     friend ostream& operator<<(ostream&, university&);
  32. };
  33. class student : public young, public university{
  34. protected:
  35.     string specialoba;
  36.     double grade;
  37. public:
  38.     student(string a = "julia", int b = 20, string c = "tsu", int d = 18, string g = " matemati", double k = 2.3) :
  39.         young(a, b), university(c, d), specialoba(g), grade(k){}
  40.     ~student(){}
  41.     double getgrade(){ return grade; }
  42.     friend istream& operator>>(istream&, student&);
  43.     friend ostream& operator<<(ostream&, student&);
  44. };
  45.  istream& operator>>(istream&ifs, young &h){
  46.     return ifs >> h.fn >>h. age;
  47. }
  48.  ostream& operator<<(ostream&ofs, young &h){
  49.     return ofs << " saxelia " << h.fn << "  age   " <<h. age << endl;
  50.  
  51. }
  52.  istream& operator>>(istream&ifs, university&h){
  53.     return ifs >>h. name >>h. fakult;
  54. }
  55. ostream& operator<<(ostream&ofs, university &h){
  56.     return ofs << " uni saxelia " << h.name << " fakraod  " << h.fakult << endl;
  57. }
  58.  istream& operator >> (istream &ifs, student &k){
  59.     ifs >> (young &)k >> (university&)k >> k.specialoba >> k.grade;
  60.     return ifs;
  61. }
  62. ostream & operator<<(ostream &ofs, student &l){
  63.     ofs << (young &)l << (university&)l << "speciealoba : " << l.specialoba << " grade:  " << l.grade << endl;
  64.     return ofs;
  65. }
  66. int main(){
  67.     young a;
  68.     cout << " shemoitane youngis monacemi : " << endl;
  69.     cin >> a;
  70.  
  71.     university *x;
  72.     x=new university("tsu", 10);
  73.     cout << a;
  74.     cout << &x;
  75.     student * y = new student[3];
  76.     ifstream ifs("text.txt");
  77.     for (int i = 0; i < 3; i++)
  78.         ifs >> y[i];
  79.     sort(y, y + 3, [](student &a, student &b) {return a.getgrade()>b.getgrade(); });
  80.     ofstream ofs("ratee.txt");
  81.     for (int i = 0; i < 3; i++)
  82.         ofs << y[i];
  83.     delete x;
  84.     delete [] y;
  85.     return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement