Class dogs
Class employee
Void show_employee(void)
{
cout << "Имя: " << name << endl;
cout << "Номер служащего: " << employee_id << endl;
cout << "Оклад: " << salary << endl;
};
};
int main()
{
system("chcp 1251");
employee worker, boss;
strcpy(worker.name, "Иванов");
worker.employee_id = 12345;
worker.salary = 25000;
strcpy(boss.name, "Савин");
boss.employee_id = 01;
boss.salary = 100000.00;
worker.show_employee();
boss.show_employee();
system("pause");
}
2.2.Определение методов класса вне класса.
| class employee |
| { |
| public: |
| char name[64]; |
| long employee_id; |
| float salary; |
| void show_employee(void); // Прототип функции |
| }; |
| void employee:: show_employee (void) //Имя класса |
| { |
| сout << "Имя: " << name << endl; //Имя элемента cout << "Номер служащего: " << employee_id << endl; |
| cout << "Оклад: " << salary << endl; |
| }; |
highlightSyntax('cpp_80196','cpp');
Primer 2 Лекция 2.
#include <iostream>
#include <string.h>
using namespace std;
{
public:
char name [64];
long employee_id;
float salary;
void show_employee(void);
};
void employee::show_employee(void)
{
cout << "Имя: " << name << endl;
cout << "Номер служащего: " << employee_id << endl;
cout << "Оклад: " << salary << endl;
};
int main()
{
system("chcp 1251");
employee worker, boss;
strcpy(worker.name, "Иванов");
worker.employee_id = 12345;
worker.salary = 25000;
strcpy(boss.name, "Савин");
boss.employee_id = 01;
boss.salary = 100000.00;
worker.show_employee();
boss.show_employee();
system("pause");
}
highlightSyntax('cpp_63749','cpp'); 2.3. Методы класса.
| return_type class_name::function_name(parameters) |
| { // Операторы } |
highlightSyntax('cpp_93191','cpp');
Primer 3 Лекция 2.
#include <iostream>
#include <string.h>
using namespace std;
{
public:
char breed[64];
int average_weight;
int average_height;
int show_breed();
};
int dogs::show_breed()
{
cout << "Порода: " << breed << endl;
cout << "Средний вес: " << average_weight << endl;
cout << "Средняя высота: " << average_height << endl;
}
int main()
{
system("chcp 1251");
dogs happy, matt;
strcpy(happy.breed, "Долматин");
happy.average_weight = 58;
happy.average_height = 24;
strcpy(matt.breed, "Колли");
matt.average_weight =22;
matt.average_height = 15;
happy.show_breed();
matt.show_breed();
system("pause");
}
| class employee |
| { |
| public: |
| char name [64]; |
| long employee_id; |
| float salary; |
| void show_employee(void); |
| } |
highlightSyntax('cpp_41585','cpp');
| class some_class |
| { |
| public: |
| int some_variable; |
| void initialize_private(int, float); // Общие элементы |
| void show_data(void); |
| private: |
| int key_value; // Частные элементы |
| float key_number; |
| } |
highlightSyntax('cpp_54287','cpp');
| object.some_variable = 1001; |
| object.initialize_private(2002, 1.2345); |
| object.show_data() |
highlightSyntax('cpp_91703','cpp');
nuclear_reactor.melt_down = 101
highlightSyntax('cpp_67871','cpp');
| int nuke::assign_meltdown(int value) |
| { |
| if ((value > 0) && (value <= 5)) |
| { |
| melt_down = value; |
| return(0); // Успешное присваивание |
| } else return(-1); // Недопустимое значение |
| } |
2.5. Использование общих и частных элементов класса.
| class employee |
| { |
| public: |
| int assign_values(char *, long, float); |
| void show_employee(void); |
| int change_salary(float); |
| long get_id(void); |
| private: |
| char name [64]; |
| long employee_id; |
| float salary; |
| } |






