Advertisement
S1xe

S1xe

Apr 29th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. class Student
  4. {
  5. public:
  6.     Student():num(),score(){}
  7.     Student(int n,float s):num(n),score(s){}
  8.     void change(int n,float s)
  9.     {
  10.         num = n;
  11.         score = s;
  12.     }
  13.     void display()
  14.     {
  15.         cout << num << " " << score << endl;
  16.     }
  17.     void display()const
  18.     {
  19.         cout << num << " " << score << endl;
  20.     }
  21. private:
  22.     int num;
  23.     float score;
  24. };
  25.  
  26. int main(int argc, char* argv[])
  27. {
  28.     const Student st(100, 78.5);
  29.     st.display();
  30.     Student *p = (Student*)(&st);
  31.     p->change(1, 2);
  32.     p->display();
  33.     st.display();
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement