Advertisement
poohitan

tree.h

Feb 7th, 2012
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 KB | None | 0 0
  1. #include <string>
  2. #include <iostream>
  3. #include <fstream>
  4. using namespace std;
  5. class Tree {
  6. protected:
  7.     string name;
  8.     unsigned age;
  9.     unsigned branches;
  10. public:
  11.     friend ifstream & operator>>(ifstream & in, Tree & t) {
  12.         in>>t.name;
  13.         in>>t.age;
  14.         in>>t.branches;
  15.         return in;
  16.     }
  17.  
  18.     friend ostream & operator<<(ostream & os, const Tree & t) {
  19.         os<<"Name: "<<t.name<<endl;
  20.         os<<"Age: "<<t.age<<endl;
  21.         os<<"Number of branches: "<<t.branches<<endl<<endl;
  22.         return os;
  23.     }
  24.  
  25.     string get_name()const {return name;}  
  26.     unsigned get_branches()const {return branches;}
  27. };
  28.  
  29. class Plod:public Tree {
  30. private:
  31.     string sort;
  32.     double vrozh;
  33. public:
  34.     friend ifstream & operator>>(ifstream & in, Plod & p) {
  35.         in>>p.name;
  36.         in>>p.age;
  37.         in>>p.branches;
  38.         in>>p.sort;
  39.         in>>p.vrozh;
  40.         return in;
  41.     }
  42.  
  43.     friend ostream & operator<<(ostream & os, const Plod & p) {
  44.         os<<"Name: "<<p.name<<endl;
  45.         os<<"Age: "<<p.age<<endl;
  46.         os<<"Number of branches: "<<p.branches<<endl;
  47.         os<<"Sort: "<<p.sort<<endl;
  48.         os<<"Vrozhaynist: "<<p.vrozh<<endl<<endl;
  49.         return os;
  50.     }
  51.  
  52.     string get_sort()const {return sort;}
  53.     double get_vrozh()const {return vrozh;}
  54. };
  55.  
  56. class Decor:public Tree {
  57. private:
  58.     double height;
  59.     double pryrist;
  60. public:
  61.     double get_height()const {return height;}
  62.     double get_pryrist()const {return pryrist;}
  63. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement