Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iostream>
- #include <cstring>
- #include <cstdio>
- #include <string>
- #include <vector>
- #include <list>
- #include <string.h>
- #include "Dipendente.h"
- #include <fstream>
- Dipendente::Dipendente(){
- nome=0;
- cognome=0;
- tipoContratto=0;
- }
- Dipendente::Dipendente (const Dipendente &r ){
- nome=r.nome;
- cognome=r.cognome;
- tipoContratto=r.tipoContratto;
- redditoAnnuo.resize(r.redditoAnnuo.size());
- copy(r.redditoAnnuo.begin(),r.redditoAnnuo.end(),redditoAnnuo.begin());
- }
- void Dipendente::setNome(char* n){
- if(nome==NULL){
- nome=new char[strlen(n)+1];
- }
- else if(strlen(nome)<strlen(n)){
- delete []nome;
- nome=new char[strlen(n)+1];
- }
- strcpy(nome,n);
- }
- void Dipendente::setCognome(char *c)
- {
- if(cognome==NULL)
- {
- cognome=new char[strlen(c)+1];
- }
- else if(strlen(cognome)<strlen(c))
- {
- delete []cognome;
- cognome=new char[strlen(c)+1];
- }
- strcpy(cognome,c);
- }
- void Dipendente::setTipoContratto(char *t)
- {
- if(tipoContratto==NULL)
- {
- tipoContratto=new char[strlen(t)+1];
- }
- else if(strlen(tipoContratto)<strlen(t))
- {
- delete []tipoContratto;
- tipoContratto=new char[strlen(t)+1];
- }
- strcpy(tipoContratto,t);
- }
- /*
- void Dipendente::setAnni(vector<int> anni){
- redditoAnnuo.size()=anni.size();
- }
- */
- float Dipendente::mediaReddito(){
- float somma=0;
- for(int i=0;i<redditoAnnuo.size();i++){
- somma=redditoAnnuo[i]+somma;
- }
- return somma/redditoAnnuo.size();
- }
- bool Dipendente::operator ==(Dipendente& o){
- return nome==o.nome;
- }
- ostream& operator<<(ostream &os, Dipendente &d){
- os<<d.nome<<" "<<d.cognome<<" "<<d.tipoContratto<<" "<<d.redditoAnnuo.size()<<" ";
- for(int i=0;i<d.redditoAnnuo.size();i++){
- os<<d.redditoAnnuo[i];
- }
- return os;
- }
- istream &operator>>(istream &in,Dipendente &d){
- char appoggio[50];
- in>>appoggio;
- d.setNome(appoggio);
- in>>appoggio;
- d.setCognome(appoggio);
- in>>appoggio;
- d.setTipoContratto(appoggio);
- int n_esami;
- in>>n_esami;
- int tmp;
- // d.redditoAnnuo.resize(n_esami);
- for(int i=0;i<n_esami;i++){
- in>>tmp;
- d.redditoAnnuo.push_back(tmp);
- }
- in.ignore();
- return in;
- }
- bool operator<(Dipendente &d1,Dipendente &d2){
- return d1.cognome<d2.cognome || d1.cognome==d2.cognome && d1.nome<d2.nome ;
- }
- ostream &operator<<(ostream &out,vector<Dipendente> &d){
- for(int i=0;i<d.size();i++){
- out<<d[i];
- }
- return out;
- }
- istream &operator>>(istream &in,vector<Dipendente> &d){
- Dipendente app;
- while(!in.eof()){
- in>>app;
- d.push_back(app);
- }
- return in;
- }
- Dipendente::~Dipendente(){
- delete [] nome;
- delete []cognome;
- delete [] tipoContratto;
- }
- void split_soglia(vector<Dipendente>& v, int s, vector<Dipendente>& v1, vector<Dipendente>& v2){
- vector<Dipendente>::iterator my_it;
- for( my_it=v.begin(); my_it!=v.end();my_it++){
- if( my_it->mediaReddito()<=s)
- v1.push_back(*my_it);
- else
- v2.push_back(*my_it);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement