
Patrick B. answered 07/08/21
Math and computer tutor/teacher
#ifndef _CAR
#define _CAR
typedef
class Car
{
protected:
char * carMake;
char * carModel;
int carYear;
public:
Car(char * make, char * model, int yr);
Car(const Car&);
~Car();
void SetCarMake( char * make);
void SetCarModel(char * model);
void SetCarYear(int yr);
int GetCarMakeLength();
int GetCarModelLength();
char * GetCarMake(char *);
char * GetCarModel(char *);
int GetCarYear();
void Print(char *strMsg=(char*)0);
} * TCar;
#define CAR_SIZE (sizeof(Car))
#endif
//********************************************************************************************//
#ifndef _CAR
#include "Car.h"
#endif
#include
#include
#include
void Car::SetCarMake( char * make)
{
int nStrLen = strlen(make)+1;
this->carMake = (char *)malloc(nStrLen+1);
strcpy(this->carMake,make);
}
void Car::SetCarModel(char * model)
{
int nStrLen = strlen(model)+1;
this->carModel = (char *)malloc(nStrLen+1);
strcpy(this->carModel,model);
}
void Car::SetCarYear(int yr)
{
this->carYear = yr;
}
Car::Car(char * make, char * model, int yr)
{
this->SetCarMake(make);
this->SetCarModel(model);
this->SetCarYear(yr);
}
Car::Car(const Car& car)
{
this->SetCarMake(car.carMake);
this->SetCarModel(car.carModel);
this->SetCarYear(car.carYear);
}
Car::~Car()
{
if (this->carMake!=NULL) { free(this->carMake); }
if (this->carModel!=NULL) { free(this->carModel); }
}
int Car::GetCarMakeLength() { return( strlen(this->carMake) +1); }
int Car::GetCarModelLength(){ return( strlen(this->carModel)+1); }
char * Car::GetCarMake(char * buff) { strcpy(buff,this->carMake); return(buff); }
char * Car::GetCarModel(char * buff) { strcpy(buff,this->carModel); return(buff); }
int Car::GetCarYear(){ return(carYear); }
void Car::Print(char *strMsg)
{
if (strMsg!=NULL)
{
printf("********************************************************************\n");
printf(strMsg);
}
printf("********************************************************************\n");
printf(" Make = >%s< \n",this->carMake);
printf(" Model = >%s< \n",this->carModel);
printf(" year = %d \n",this->carYear);
}