Created
March 14, 2011 01:52
-
-
Save gaites/868655 to your computer and use it in GitHub Desktop.
practice using classes @SaiYT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "StdAfx.h" | |
#include "Employee.h" | |
#include <iostream> | |
//constructor | |
Employee::Employee(int initialAge, int initialYearsOfService, int initialSalary) | |
{ | |
initialAge = itsAge; | |
initialYearsOfService = itsYearsOfService; | |
initialSalary = itsSalary; | |
}; | |
//deconstructor function | |
Employee::~Employee() | |
{ }; | |
// "Get" functions | |
int Employee::GetAge() | |
{ | |
return itsAge; | |
} | |
int Employee::GetYearsOfService() | |
{ | |
return itsYearsOfService; | |
} | |
int Employee::GetSalary() | |
{ | |
return itsSalary; | |
} | |
// write functions | |
void Employee::SetAge(int age) | |
{ | |
itsAge = age; | |
} | |
void Employee::SetYearsOfService(int service) | |
{ | |
itsYearsOfService = service; | |
} | |
void Employee::SetSalary(int salary) | |
{ | |
itsSalary = salary; | |
} | |
int main() | |
{ | |
//create two objects of class employee and print the values of their age, years of service, and salary | |
Employee Carl(5, 10, 16); | |
Employee Steve(16, 20, 18); | |
cout << Employee.Carl.GetAge() << " " << Employee.Carl.GetYearsOfService() << " " << Employee.Carl.GetSalary(); | |
// exit; char response included to pause script. | |
char response; | |
cin >> response; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
class Employee | |
{ | |
public: | |
//constructor | |
Employee(int initialAge, int initialYearsOfService, int initialSalary); | |
//deconstructor | |
~Employee(); | |
// read | |
int GetAge() const; | |
int GetYearsOfService() const; | |
int GetSalary() const; | |
//write | |
void SetAge(int age); | |
void SetYearsOfService(int service); | |
void SetSalary(int salary); | |
private: | |
int itsAge; | |
int itsYearsOfService; | |
int itsSalary; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment