Advertisement
SabirSazzad

Student class (Constructor, Distructor)

Feb 23rd, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. class Student{
  4. private:
  5.     int *marks;
  6.     int numOfCourse;
  7. public:
  8.     Student():Student(1){}
  9.     Student(int numOfCourse){
  10.         this->numOfCourse = numOfCourse;
  11.         this->marks = new int[this->numOfCourse];
  12.  
  13.         this->takeMarks();
  14.     }
  15.     void takeMarks(){
  16.         cout<<"Enter "<<this->numOfCourse << "  marks for this student\n";
  17.         for(int i=0; i<this->numOfCourse; i++)
  18.             cin>>this->marks[i];
  19.     }
  20.  
  21.     void showMarks(){
  22.      for(int i=0; i<this->numOfCourse; i++)
  23.         cout<<this->marks[i]<<"  ";
  24.      cout<<endl;
  25.     }
  26.     ~Student(){
  27.       delete [] this->marks;
  28.     }
  29. };
  30.  
  31.  
  32. int main(){
  33. Student *s1 = new Student;
  34. Student s2;
  35. s2 = *s1;
  36. delete s1;
  37.  
  38. s2.showMarks();
  39.  
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement