LibertyPaul

7lab

May 9th, 2012
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.46 KB | None | 0 0
  1. #include <iostream>//cin&cout.
  2. #include <string>//Лень плясать с бубном вокруг массивов char. Поэтому юзаю стринги!
  3. #include <conio.h>//Для getch();
  4. using namespace std;
  5.  
  6.  
  7. int Studentcount=0;
  8.  
  9.  
  10. class Student{
  11.     string *surname, *name, *midname, *groupname;
  12.     unsigned short *birthyear;
  13.  
  14. public:
  15.     string *get_surname(){
  16.         return surname;
  17.     }
  18.    
  19.     void set_surname(string s){
  20.         *surname=s;
  21.     }
  22.    
  23.     string *get_name(){
  24.         return name;
  25.     }
  26.    
  27.     void set_name(string s){
  28.         *name=s;
  29.     }
  30.    
  31.     string *get_midname(){
  32.         return midname;
  33.     }
  34.    
  35.     void set_midname(string s){
  36.         *midname=s;
  37.     }
  38.    
  39.     unsigned short *get_birthyear(){
  40.         return birthyear;
  41.     }
  42.    
  43.     void set_birthyear(unsigned short x){
  44.         *birthyear=x;
  45.     }
  46.    
  47.     string *get_groupname(){
  48.         return groupname;
  49.     }
  50.    
  51.     void set_groupname(string s){
  52.         *groupname=s;
  53.     }
  54.    
  55.  
  56.     static Student *get_new(){
  57.         return new Student;
  58.     }
  59.    
  60.     void remove(){
  61.         this->~Student();
  62.     }
  63.  
  64.  
  65. private:
  66.     Student(string s1="Default_value", string s2="Default_value", string s3="Default_value", unsigned short i4=0, string s4="Default_value"){
  67.         cout<<"\nВход в функцию Student::Student();\n";
  68.         cout<<"В ОЗУ содержатся "<<++Studentcount<<" элементов\n";
  69.         name=new string;
  70.         *name=s1;
  71.         surname=new string;
  72.         *surname=s2;
  73.         midname=new string;
  74.         *midname=s3;
  75.         birthyear=new unsigned short;
  76.         *birthyear=i4;
  77.         groupname=new string;
  78.         *groupname=s4;
  79.     }
  80.     ~Student(){
  81.         cout<<"\nВход в функцию Student::~Student();\n";
  82.         cout<<"В ОЗУ содержатся "<<--Studentcount<<" элементов\n";
  83.         delete surname;
  84.         delete name;
  85.         delete midname;
  86.         delete groupname;
  87.         delete birthyear;
  88.     }
  89. public:
  90.     Student(const Student& t){
  91.         *surname=*(t.surname);
  92.         *name=*(t.name);
  93.         *midname=*(t.midname);
  94.         *birthyear=*(t.birthyear);
  95.         *groupname=*(t.groupname);
  96.     }
  97. };
  98.    
  99. Student *test(Student *s){
  100.     return s;
  101. }
  102.  
  103.    
  104. int main(int argc, char **argv){
  105.     setlocale(LC_ALL, "rus");
  106.     cout<<"Beginning of int main function"<<endl;
  107.     Student *one=Student::get_new();
  108.     one->set_name("Ivan");
  109.     one->set_surname("Ivanov");
  110.     one->set_midname("Ivanovych");
  111.     one->set_birthyear(1970);
  112.     one->set_groupname("vkb21");
  113.    
  114.     Student *mas[100];
  115.     for(int i=0;i<100;i++){
  116.         mas[i]=Student::get_new();
  117.     }
  118.     for(int i=99;i>=0;i--){
  119.         mas[i]->remove();
  120.     }
  121.     one->remove();
  122.     cout<<"Ending of int main function"<<endl;
  123.     getch();
  124.     return 0;
  125. }
Advertisement
Add Comment
Please, Sign In to add comment