Тема: C++
Від модератора: додав теги code (кнопка <>), наступного разу самостійно, будь ласка - Koala
Як тут визначити конструктори по 3 шт у кожному класі.
#include <iostream>
#include <queue>
#include <stdlib.h>
#include <string>
using namespace std;
class Osoba
{
protected:
string name;
string surname;
string middlename;
//int date;
int day;
int month;
int year;
public:
void messege()
{
cout << "data about OSOBA"<< endl;
}
void setInfo(string Info_name, string Info_surname, string Info_middlename)
{
name = Info_name;
surname = Info_surname;
middlename = Info_middlename;
}
void getInfo(ostream& os)
{
os << "Info: " << name << "." << surname << "." << middlename << endl;
}
void setDate(int date_day, int date_month, int date_year)
{
day = date_day;
month = date_month;
year = date_year;
}
void getDate(ostream& os)
{
os << "Date: " << day << "." << month << "." << year << endl;
}
};
class worker:public Osoba
{
private:
int experience;
int hours;
int payforhour;
int payroll;
public:
static void messege()
{
cout << "data about worker"<< endl;
}
void setPayinfo(int Payinfo_experience, int Payinfo_hours, int Payinfo_payforhour, int Payinfo_payroll)
{
experience = Payinfo_experience;
hours = Payinfo_hours;
payforhour = Payinfo_payforhour;
payroll = Payinfo_payroll;
}
friend ostream& operator<<(ostream& os,const worker& w);
friend bool operator<(const worker& v,const worker& w);
};
ostream& operator<<(ostream& os,const worker& w)
{
os << "Info: " << w.name << "." << w.surname << "." << w.middlename << endl;
os << "Date: " << w.day << "." << w.month << "." << w.year << endl;
os << "Payinfo: " << w.experience << "." << w.hours << "."
<< w.payforhour << "." << w.payroll << endl;
return os;
}
bool operator<(const worker& v,const worker& w)
{
return v.experience<w.experience; // по чем устанавливать приоритет !!!!
}
ostream& operator<<(ostream& os,priority_queue<worker>& priorityQueue)
{
while (!priorityQueue.empty()) {
worker st = priorityQueue.top();
os << st<< '\n';
priorityQueue.pop();
}
return os;
}
int main(int argc, char* argv[])
{
setlocale(LC_ALL, "rus");
priority_queue<worker> priorityQueue;
int N=3;
for(int i=0;i<N;i++)
{
int experience, hours, payforhour, payroll;
string name, surname, middlename;
int day, month, year;
cout << "Введите данные про особу"<< endl;
cout << "Имя"<< endl;
cin>>name;
cout << "Фамилия"<< endl;
cin>>surname;
cout << "Отчество"<< endl;
cin>>middlename;
cout << "Введите данные про день рождения"<< endl;
cout << "день"<< endl;
cin>>day;
cout << "месяц"<< endl;
cin>>month;
cout << "год"<< endl;
cin>>year;
cout << "Опыт"<< endl;
cin>>experience;
cout << "Часы роботы"<< endl;
cin>>hours;
cout << "Зарплата за час"<< endl;
cin>>payforhour;
cout << "табельный оклад"<< endl;
cin>>payroll;
cin.get();
worker objworker;
objworker.setPayinfo(experience, hours, payforhour, payroll);
objworker.Osoba::setInfo(name,surname,middlename);
objworker.Osoba::setDate(day,month,year);
objworker.messege();
cout<<objworker;
priorityQueue.push(objworker);
}
cout<<endl<<priorityQueue;
cin.get();
return 0;
};