Schedule‎ > ‎

Ex_9.2_student.cpp

#include <iostream>
using namespace std;

class Student {
  public:
    Student(string name, int ID,
            string hobby);  //Constructor
    string getName() const;
    void setName(string name);
   
  private:
    string _name;
    int _ID; 
    string _hobby;
};

Student::Student(string name, int ID, string hobby)  {
  _name = name;
  _ID = ID;
  _hobby = hobby;
}
string Student::getName() const  {
  return _name;
}
void Student::setName(string name)  {
  _name = name;
}
int main() {
    Student student3("Ennio",  98765, "C+++");
    student3.setName("Marco");
    cout << "Student 3's name is " << student3.getName() << endl;
}

Comments