Парни выручите плз.Не пойму что не так. Сорри за кучу кода . В общем тут суть такова .Еесть класс компания . Есть класс работник . компания состоит из работников.
Работники бывают -самые абстрактные(класс worker) -с базовой зарплатой( worker_with_base наследуется от предыдущего) -с процентом от продаж(worker_procent_of_sum наследуется от первого) - и с зарплатой и с процентом от продаж(worker_plus_base -наследуется от двух вышеперечисленных )
ну вот при написании последнего класса появилась ошибочка ....
company.h
| Код | #ifndef COMPANY_H #define COMPANY_H # include "worker.h" class company { private : name employees_list[1000]; int number_employee; public : company(); void add_in_list(string first , string last ); void add_in_list( worker w_1 ); int get_number_employee(); void print (); };
#endif
|
company.cpp
| Код | # include <iostream> # include "company.h" # include "worker.h" using namespace std;
company::company():number_employee(0) {} void company::add_in_list(string first , string last ) { employees_list[number_employee].first_name=first; employees_list[number_employee++].last_name=last; } void company::add_in_list( worker w_1 ) { employees_list[number_employee].first_name=w_1.get_first_name(); employees_list[number_employee++].last_name=w_1.get_last_name(); } int company::get_number_employee() { return number_employee; } void company::print () { cout << "at this company works " <<get_number_employee() <<" persons:\n"; for (int i=0;i<number_employee; i++) cout <<"\t" <<employees_list[i].first_name<< " "<< employees_list[i].last_name<<endl; cout << endl; }
|
worker.h
| Код | #ifndef WORKER_H #define WORKER_H # include <string> using namespace std; struct name { string first_name; string last_name; }; class worker { private: string first_name; string last_name; int time_of_work; public: worker(string s1, string s2 , int time); string get_first_name(); string get_last_name(); void print(); }; #endif
|
worker.cpp
| Код | # include <iostream> # include "worker.h"
worker::worker(string s1, string s2 , int time):first_name(s1), last_name(s2), time_of_work(time) {} string worker::get_first_name() { return first_name; } string worker::get_last_name() { return last_name; } void worker::print() { cout << get_first_name() << " " << get_last_name()<<endl; cout<<"\t"<< "his experience is " << time_of_work << " days\n"; }
|
worker_with_base.h
| Код | # ifndef WORKER_WITH_BASE # define WORKER_WITH_BASE # include "worker.h" class worker_with_base:public worker { public: worker_with_base(string f,string l,int days, double fix); void set_base(double fix); double get_base(); void print (); protected: double base; };
#endif
|
worker_with_base.cpp
| Код | #include "worker_with_base.h" # include "worker.h" # include <iostream> using namespace std;
worker_with_base::worker_with_base(string f,string l,int days, double fix):worker(f,l,days),base(fix) {} void worker_with_base::set_base(double fix) { base=fix; } double worker_with_base::get_base() { return base; } void worker_with_base::print () { worker::print(); cout << "and have base salary " << get_base() << endl; }
|
worker_procent_of_sum.h
| Код | #ifndef WORKER_PROCENT_OF_SUM #define WORKER_PROCENT_OF_SUM
# include "worker.h" # include <iostream> using namespace std; class worker_procent_of_sum:public worker { public: worker_procent_of_sum(string s1,string s2,int d,double sum,double prc) ; void set_sum_all(double); void set_percent(double); double salary(); void print (); protected: double sum_all; double percent; }; #endif
|
worker_procent_of_sum.cpp
| Код | # include "worker.h" #include "worker_procent_of_sum.h" using namespace std; //конструктор worker_procent_of_sum::worker_procent_of_sum(string s1,string s2,int d,double sum,double prc) :worker(s1,s2,d),sum_all(sum),percent(prc) {}
void worker_procent_of_sum::set_percent(double perc) { percent=perc; } void worker_procent_of_sum::set_sum_all(double s) { sum_all=s; } double worker_procent_of_sum::salary() { return (percent/100)*sum_all; } void worker_procent_of_sum::print() { worker::print(); cout <<"\tand his sum of sale " <<sum_all<<endl<< "\tpercent of sale " << percent<<endl<< "\t he earned"<<salary()<<endl; }
|
worker_percent_plus_base.h
| Код | # ifndef WORKER_PERCENT_PLUS_BASE # define WORKER_PERCENT_PLUS_BASE
# include "worker_procent_of_sum.h" # include "worker_with_base.h"
class worker_percent_plus_base:public worker_procent_of_sum,public worker_with_base { private : double full_salary; public : worker_percent_plus_base(string first,string las,int days,double fix ,double sum_of_sale, double procent); double salary(); void print(); };
# endif
|
worker_percent_plus_base.cpp
| Код | # include "worker_percent_plus_base.h"
worker_percent_plus_base::worker_percent_plus_base(string first,string las,int days,double fix ,double sum_of_sale, double procent) :worker_procent_of_sum(first,las,days,sum_of_sale,procent),base(fix) { full_salary=salary(); }
double worker_percent_plus_base::salary() { return get_base()+worker_procent_of_sum::salary(); } void worker_percent_plus_base::print() { worker_procent_of_sum::print(); cout << "\tand his base " << base << endl; }
|
main.cpp
| Код | # include <iostream> # include <string> # include "company.h" # include "worker.h" # include "worker_with_base.h" using namespace std;
int main () { worker worker_1("Ivan","Petrov",573); worker worker_2("Egor","sergeev",123); worker worker_3("Evgeniy","Matveev",666); worker worker_4("Petr","Ivanov",12000); worker_1.print(); worker_2.print(); worker_3.print(); worker_4.print(); company head_company; head_company.add_in_list(worker_1); head_company.add_in_list(worker_2); head_company.add_in_list(worker_3); head_company.add_in_list(worker_4); head_company.add_in_list("Sidor","Sidorov"); head_company.print(); worker_with_base base_1("Aleksandr","Ivanov",3,100); base_1.print(); return 0; }
|
ошибки таковы и весьма непонятны
| Код | 1>------ Build started: Project: множественное и единичное наследование, Configuration: Debug Win32 ------ 1>Compiling... 1>worker_percent_plus_base.cpp worker_percent_plus_base.cpp(6) : error C2512: 'worker_with_base' : no appropriate default constructor available worker_pe-cpp(6) : error C2614: 'worker_percent_plus_base' : illegal member initialization: 'base' is not a base or member
1>множественное и единичное наследование - 2 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
|
|