// @topic T00301 Introduction to classes
// @brief Employee class and main function in one file
// An example of Employee class and its public interface
// An enumeration is an easy way to create integer constants:
enum {
SOUTH = 1,
NORTH, // 2
WEST, // 3
EAST // 4
};
class Employee {
double salary;
bool full_time_position;
int employee_id;
public:
///////////////////////////////////////////////
// operations that make up Employee interface:
///////////////////////////////////////////////
void init( double sal, bool full_time, int id ) {
salary = sal;
full_time_position = full_time;
employee_id = id;
}
void flip_status() {
full_time_position = !full_time_position;
}
void double_salary() {
//salary *= 2;
salary = 2 * salary;
}
};//class Employee definition ends here
int main()
{
int x = 1; // single integer
// array of integers:
int arr[ 5 ] = { 10, 20, 30, 40, 50 };
// [0] [1] [2].[3].[4]
arr[ WEST ] = arr[ SOUTH ]; // 40 <= 10
// create an object
Employee emp;
// initialize object by calling its init() member function:
emp.init( 25000.06, false, 10024 );
// call another member function:
//emp.salary = 2 * emp.salary;
emp.double_salary();
// create another object
Employee emp2;
emp2.init( 25000.06, true, 10025 );
// create a third Employee object by manufacturing an exact copy of emp2
Employee emp3 = emp2;
// call some more member functions on Employee objects:
emp.flip_status();
emp2.flip_status();
emp3.flip_status();
return 0;
}