rendered paste body#include<iostream.h>
#include<string.h>
#include <stdlib.h>
class Vehicle
{
private:
char make[40];
char model[40];
char lp[7];
char color[10];
int doors;
int makeyear;
int hp;
int cylinders;
int enginvol;
public:
//Constructors
Vehicle();
Vehicle(char[],char[],char[],char[],int,int,int,int,int);
//Get methods
char* getMake();
char* getModel();
char* getLp();
char* getColor();
int getDoors();
int getMakeyear();
int getHp();
int getCylinders();
int getEnginvol();
//Set methods tou programmatisti
void setVehicle(char[],char[],char[],char[],int,int,int,int,int);
void setMake(char[]);
void setModel(char[]);
void setLp(char[]);
void setColor(char[]);
void setDoors(int);
void setMakeyear(int);
void setHp(int);
void setCylinders(int);
void setEnginvol(int);
//Input methods tou xristi
void inputVehicle();
void inputMake();
void inputModel();
void inputLp();
void inputColor();
void inputDoors();
void inputMakeyear();
void inputHp();
void inputCylinders();
void inputEnginvol();
//Other methods
void printVehicle();
bool checkLp();
bool checkChar(char);
};
class Employee{
private:
char name[30];
char address[40];
int phone;
char afm[10];
Vehicle myCar;
public:
Employee();
Employee(char *, char *, int, char *, Vehicle);
void setEmployee();
void setEmployee(char *, char *, int, char *, Vehicle);
void setName(char[]);
void setAddress(char[]);
void setPhone(int);
void setAfm(char[]);
void setMyCar(Vehicle);
char* getName();
char* getAddress();
int getPhone();
char* getAfm();
Vehicle getmyCar();
void printEmployee();
}
char* charphone();
int main()
{
Vehicle pel1,pel2;
pel1.setVehicle("Daihatsu","Sirion CX","NZP2473","Silver",4,2004,102,4,1300);
pel1.printVehicle();
pel2.inputVehicle();
pel2.printVehicle();
pel1.setLp("NZI5689");
pel1.printVehicle();
pel2.inputColor();
pel2.printVehicle();
return 0;
}
Employee::Employee(){
strcpy(name,"");
strcpy(address,"");
phone = 0;
strcpy(afm,"");
myCar = new Vehicle();
}
Employee::Employee(char* a, char* b, int c, char* d, Vehicle Car){
strcpy(name, a);
strcpy(address, b);
phone = c;
strcpy(afm, d);
myCar = Car;
}
void Employee::setEmployee(char* a, char* b, int c, char* d, Vehicle Car){
strcpy(name, a);
strcpy(address, b);
phone = c;
strcpy(afm, d);
myCar = Car;
}
void Employee::setEmployee(){
strcpy(name,"");
strcpy(address,"");
phone = 0;
strcpy(afm,"");
myCar = new Vehicle();
}
void setName(char[]){
cout << "Dwse to onoma : ";
cin >> name;
}
void setAddress(char[]){
cout << "Dwse th diefthunsh : ";
cin >> address;
}
void setPhone(int){
cout << "Dwse to thlefono : ";
cin >> phone;
}
void setAfm(char[]){
cout << "Dwse to AFM";
cin >> afm;
}
void setMyCar(Vehicle){
myCar.inputVehicle();
}
char* getName(){
return name;
}
char* getAddress(){
return address;
}
int getPhone(){
return phone;
}
char* getAfm(){
return afm;
}
Vehicle getmyCar(){
return myCar;
}
void printEmployee(){
cout << "Name:\t" name << endl << "Address:\t" << address << endl
<< "Telephone:\t" << charphone(phone) << endl << "AFM:\t" << afm << endl;
myCar.printVehicle();
}
char* charphone(int a){
char b[16];
for (i=15;i>11;i--){
c = a%10
b[i] = c;
}
b[11] = '-';
for (i=10;i>7;i--){
c = a%10
b[i] = c;
}
b[7] = '-';
for (i=6;i>2;i--){
c = a%10
b[i] = c;
}
b[2] = '0';
b[1] = '3';
b[0] = '+';
return b;
}
//Class Vehicle implementation
Vehicle::Vehicle()
{
strcpy(make,"");
strcpy(model,"");
strcpy(lp,"");
strcpy(color,"");
doors = 0;
makeyear = 0;
hp = 0;
cylinders = 0;
enginvol = 0;
}
Vehicle::Vehicle(char* a,char* b,char* c,char* d,int e,int f,int g,int h,int i)
{
strcpy(make,a);
strcpy(model,b);
strcpy(lp,c);
strcpy(color,d);
doors = e;
makeyear = f;
hp = g;
cylinders = h;
enginvol = i;
}
//Get methods
char* Vehicle::getMake()
{
return make;
}
char* Vehicle::getModel()
{
return model;
}
char* Vehicle::getLp()
{
return lp;
}
char* Vehicle::getColor()
{
return color;
}
int Vehicle::getDoors()
{
return doors;
}
int Vehicle::getMakeyear()
{
return makeyear;
}
int Vehicle::getHp()
{
return hp;
}
int Vehicle::getCylinders()
{
return cylinders;
}
int Vehicle::getEnginvol()
{
return enginvol;
}
//Set methods tou programmatisti
void Vehicle::setVehicle(char* a,char* b,char* c,char* d,int e,int f,int g,int h,int i)
{
strcpy(make,a);
strcpy(model,b);
strcpy(lp,c);
strcpy(color,d);
doors = e;
makeyear = f;
hp = g;
cylinders = h;
enginvol = i;
}
void Vehicle::setMake(char* a)
{
strcpy(make,a);
}
void Vehicle::setModel(char* a)
{
strcpy(model,a);
}
void Vehicle::setLp(char* a)
{
strcpy(lp,a);
}
void Vehicle::setColor(char* a)
{
strcpy(color,a);
}
void Vehicle::setDoors(int a)
{
doors = a;
}
void Vehicle::setMakeyear(int a)
{
makeyear = a;
}
void Vehicle::setHp(int a)
{
hp = a;
}
void Vehicle::setCylinders(int a)
{
cylinders = a;
}
void Vehicle::setEnginvol(int a)
{
enginvol = a;
}
//Input methods tou xristi
void Vehicle::inputVehicle()
{
inputMake();
inputModel();
inputLp();
inputColor();
inputDoors();
inputMakeyear();
inputHp();
inputCylinders();
inputEnginvol();
}
void Vehicle::inputMake()
{
cout<<endl<<"Dose tin xora kataskeuis tou autokinitou"<<endl;
cin>>make;
}
void Vehicle::inputModel()
{
cout<<endl<<"Dose to modelo tou autokinitou"<<endl;
cin>>model;
}
void Vehicle::inputLp()
{
cout<<endl<<"Dose tis pinakides tou autokinitou"<<endl;
cin>>lp;
while(!checkLp())
{
cout<<"Lathos morfi. Dose ksana ton arithmo pinakidas"<<endl;
cin>>lp;
}
}
void Vehicle::inputColor()
{
cout<<endl<<"Dose to xroma tou autokinitou"<<endl;
cin>>color;
}
void Vehicle::inputDoors()
{
cout<<endl<<"Dose poses portes exei"<<endl;
cin>>doors;
while(doors<2 || doors>7)
{
cout<<"Ektos orion. Dose ksana ton arithmo"<<endl;
cin>>doors;
}
}
void Vehicle::inputMakeyear()
{
cout<<endl<<"Dose to etos kataskeuis tou autokinitou"<<endl;
cin>>makeyear;
while(makeyear<1980 || makeyear>2008)
{
cout<<"Ektos orion. Dose ksana tin xronia"<<endl;
cin>>makeyear;
}
}
void Vehicle::inputHp()
{
cout<<endl<<"Dose tous ipous tou autokinitou"<<endl;
cin>>hp;
while(hp<60 || hp>1000)
{
cout<<"Ektos orion. Dose ksana tous ipous"<<endl;
cin>>hp;
}
}
void Vehicle::inputCylinders()
{
cout<<endl<<"Dose ta cylindrous tou autokinitou"<<endl;
cin>>cylinders;
while(cylinders<4 || cylinders>16)
{
cout<<"Ektos orion. Dose ksana ta kibika"<<endl;
cin>>cylinders;
}
}
void Vehicle::inputEnginvol()
{
cout<<endl<<"Dose ton kibismo mixanis tou autokinitou"<<endl;
cin>>enginvol;
while(enginvol<60 || enginvol>6000)
{
cout<<"Ektos orion. Dose ksana ton volume mixanis"<<endl;
cin>>enginvol;
}
}
//Other
bool Vehicle::checkLp()
{
int i;
for(i=0; i<3; i++)
{
lp[i] -= (lp[i]>90) ? 32 : 0;
if(!checkChar(lp[i])) return false;
}
if(lp[3]<'1' || lp[3]>'9') return false;
for(i=4; i<7; i++)
{
if(lp[i]<'0' || lp[i]>'9') return false;
}
return true;
}
bool Vehicle::checkChar(char c)
{
switch(c)
{
case 'E':
case 'T':
case 'Y':
case 'I':
case 'O':
case 'P':
case 'A':
case 'H':
case 'K':
case 'Z':
case 'X':
case 'B':
case 'N':
case 'M':
return true;
}
return false;
}
void Vehicle::printVehicle()
{
cout<<"Marka:" <<make <<endl
<<"Modelo:"<<model<<endl
<<"Pinakides:"<<lp<<endl
<<"Xroma:"<<color<<endl
<<"Portes:"<<doors<<endl
<<"Xronia kataskeuis:"<<makeyear<<endl
<<"Ipoi:"<<hp<<endl
<<"Kilindroi:"<<cylinders<<endl
<<"Kibismos:"<<enginvol<<endl;
}