#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include "person.h"
//Конструктор объекта
Person::Person(int number, const char* fio, int sex, float age)
:_number(number),_sex(sex),_age(age)
{strncpy(_fio,fio,sizeof(_fio));}
//Конструктор объекта по умолчанию
Person::Person():_number(0),_sex(0),_age(0) 
{_fio[0]=0;}
void Person::Print() const
{cout<<*this;/*Вызывает оператор <<*/}
//Ввод данных в объект с клавиатуры
void Person::Input()
{cout<<"\n\t\t\tVvedite dannye o cheloveke:"<<endl;
cout<<"\n\tVvedite nomer:";
cin>>_number;
cout<<"\n\tVvedite imya:";
cin.ignore();//Пропуск символа в конце строки
cin.getline(_fio,sizeof(_fio),'\n'); 
cout<<"\n\tVvedite vozrast:";
cin>>_age;
cout<<"\n\tVvedite pol(0 - myjchina, 1 - jenschina):";
cin>>_sex;}
//Приведение к типу float. 
Person::operator float() const {return _age;}
//Получить значение:
int Person::GetNumber() const {return _number;}
const char* Person::GetFio() const {return _fio;}
int Person::IsJenschina() const {return _sex;}
int Person::IsMyjchina() const {return !_sex;}
float Person::GetAge() const {return _age;}
//Оператор сравнения двух объектов 
bool Person::operator==(Person const& other) const
{return _number==other._number&&
_age==other._age&&
_sex==other._sex&&
0==strcmp(_fio, other._fio);}
//Оператор неравенства
bool Person::operator!=(Person const& other) const
{return !(*this == other);/* Инверсия результата оператора ==*/}
//Оператор вывода в поток 
ostream& operator<<(ostream& os, Person const& pers)
{os<<"\tNomer:"<<pers._number<<"\tImya:"<< pers._fio<<"\tVozrast:"
<<pers._age<<"\tPol:"<<(pers._sex?'J':'M')<<endl;
return os;
}
Соседние файлы в папке Лабораторная_2_Высокоуровневые методы информатики и программирования ()