Discussion 1

Discussion 1 - Discussion notes 11/30/07 Classes * objects...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Discussion  notes 11/30/07 Classes * objects  are instances of classes/structures class Employee { int empid; string name; double salary; public: string get_name() const; int get_empid() const; double get_salary() const; void give_raise(double amt); }; Member functions :  only member functions can access your member variables void Employee::give_raise(double amt) { salary +=amt; } string Employee::get_name const; { return name; } .. Public / Private –  Access Modifiers cout << emp.name; // not allowed! cout<<emp.get_name();  // :) Constructors initialize class objects compiler's constructors assign a block of memory, with more blocks inside for variables.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Constructors are special functions. No return variables, same name as class ... void give_raise(double amt); Employee(); Emplyee(int id, string n, double sal); }; Employee::Employee() // default values { empid=0; name=""; salary=0; } Employee::Employee(int id, string n, double sal)
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/02/2008 for the course COM SCI 31 taught by Professor Kinsey during the Fall '98 term at UCLA.

Page1 / 4

Discussion 1 - Discussion notes 11/30/07 Classes * objects...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online