Last active
December 10, 2015 11:29
-
-
Save vertrigo/4427985 to your computer and use it in GitHub Desktop.
Новый год встретил хорошо. Начинаю практику в объектно-ориентированном программировании на C++.
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 <iostream> | |
#include <conio.h> | |
#include <string.h> | |
class employee | |
{ | |
public: | |
employee(char *, long, float); | |
~employee(void) { printf("object for %s is distructing\n",name); } | |
void show_employee(void); | |
void change_salary(float) ; | |
long get_id(void); | |
private: | |
char name [64] ; | |
long employee_id; | |
float salary; | |
}; | |
employee::employee(char *name, long employee_id, float salary) | |
{ | |
strcpy(employee::name, name) ; | |
employee::employee_id = employee_id; | |
if (salary < 50000.0) | |
employee::salary = salary; | |
else // Недопустимый оклад | |
employee::salary = 0.0; | |
} | |
void employee::show_employee(void) | |
{ | |
printf("name: %s\n",name); | |
printf("emp_id: %i\n",employee_id); | |
printf("salary: %5.2f\n",salary); | |
} | |
void employee::change_salary(float new_salary) | |
{ | |
salary = new_salary; | |
} | |
void main(void) | |
{ | |
float n; | |
employee worker("Andrei", 101, 10101.0); | |
employee *manager = new employee("Olga", 32, 10200.0); | |
manager->show_employee(); | |
delete manager; | |
worker.show_employee(); | |
printf("Enter new salary for Andrei:\n"); | |
scanf("%f",&n); | |
worker.change_salary(n); | |
worker.show_employee(); | |
getch(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment