this is what i have, and i have lots of mistakes in class to class...and friends functions
dont know why, need your help
CCar.h:
#ifndef _CCar_H //מונע אפשרות להכללות כפולות של המודול
#define _CCar_H
#include "CWorker.h"
#define LEN_N_FIRMA 20
//class CWorker;
class CCar
{
char m_firma[LEN_N_FIRMA]; // car firma
int m_price; // car price
friend CWorker::CWorker(const char*,const char *firma ,int price ,int numOfChildren);
public:
CCar(const char *firma='\0',int price=0);
};
#endif
CWorker.h:
#define LEN_N_W 20
#define LEN_C 10
class CWorker
{
char m_name[LEN_N_W]; // worker's name
CCar *m_pCar; // car
//CChild m_cArr[LEN_C]; // array of children
int m_numChildren; // number of children to this worker
// ??? m_totalNumChildren; // counter of all children of all workers
public:
CWorker(const char*,const char *firma='\0' ,int price=0 ,int numOfChildren=0);
// CWorker(const CWorker&);
~CWorker();
void showWorker()const;
};
#endif
CCarr.cpp
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <assert.h>
#include <string>
#include "CCar.h"
using namespace std;
CCar::CCar(const char *firma, int price):m_price(price)
{
strcpy(m_firma,firma);
}
CWorker.cpp:
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <assert.h>
#include <string>
#include "CWorker.h"
#include "CCar.h"
#include "CChild.h"
using namespace std;
CWorker::CWorker(const char *name,const char *firma,int price,int numOfChildren):m_numChildren(numOfChildren)
{
strcpy(m_pCar->m_firma,firma);
m_pCar->m_price=price;
strcpy(m_name,name);
m_pCar= new CCar();
assert(m_pCar);
}
/*CWorker::CWorker(const CWorker&worker)
{
int i;
for(i=0;i<worker.m_numChildren;i++);
m_pCar=new CCar[i+1];
assert(m_pCar);
memcpy(m_pCar,worker.m_pCar,(i+1)*sizeof(CCar));
m_numChildren=worker.m_numChildren;
strcpy(m_name,worker.m_name);
}*/
CWorker::~CWorker()
{
delete [] m_pCar;
}
void CWorker::showWorker() const
{
cout<<m_name<<":";
cout<<endl;
}
main.cpp:
#include <iostream>
#include <assert.h>
#include "CCar.h"
#include "CChild.h"
#include "CWorker.h"
using namespace std;
void main()
{
CCar car("Mercedes" , 50000);
CWorker *Sasson = new CWorker("Sasson Sassoni");
assert(Sasson);
Sasson->showWorker();
/* addChild(*Sasson, CChild("Sassoniile", 3));
addChild(*Sasson, CChild("Sassonchick", 7));
Sasson->setCar("Mercedes", 900000);
Sasson->showWorker();
cout<<"======================\n" << endl;
// compare cars by names only
cout<< "Checking cars = " << car.isSameCar(*Sasson)<<endl<<endl;
cout<<"======================\n" << endl;
CWorker Rambo = *Sasson;
Rambo.setName("Rambo");
addChild(Rambo , CChild("Rambole" , 5));
Rambo.showWorker();
cout<<"======================\n" << endl;
// array of children
CChild A[] = { CChild("Shilgi1" , 1) , CChild("Shilgi2" , 2) , CChild("Shilgi3" , 3) };
CWorker Shilgiya("Shilgiya" , "Fiat" , 22000 , A , 3);
Shilgiya.showWorker();
// the total number of children belongs to all workers exists
cout<<"totalNumChildren (of all worker till now) = " <<
CWorker::showTotalNumChildren()<<endl<<endl;
delete Sasson;
cout<<"totalNumChildren (of all worker till now) = " <<
CWorker::showTotalNumChildren()<<endl<<endl;*/
}
i am not allude to change anything in CCar class..
would be pleased for any help.