This is a small C++ console project. I am using g++ to compile it on UNIX environment.
g++ test.cpp -o test -ansi -Wall -pedantic (I have to use this syntax)
I have a base class and 2 derived classes.
Base class : Vehicles
Derived class 1: Cars
Derived class 2: Buses
I have test data to populate. At the end of the data population I want to write all records onto the console to see if data population is working okay or not. All I get is empty screen. Somehow something doesn't work. Couldn't figured it out.
Data population has to run in another cpp file which called utility.cpp.
Here are my files:
//
// Vehicles.h
//
// Parent Vehicles class
//
#ifndef __VEHICLES_H__
#define __VEHICLES_H__
using namespace std;
class Vehicles
{
   protected:
      string rego; 
      string make; 
      string model; 
      int seats; 
      int weight;
      string type;
   public:
      Vehicles () { }
      Vehicles (string xrego, string xmake, string xmodel, int xseats, int xweight, 
                string xtype) 
      {
         rego = xrego;
         make = xmake;
         model = xmodel;
         seats = xseats;
         weight = xweight;
         type = xtype; 
      }
      void showVehicle() {
         cout << "\n" << rego << "\t" << make << "\t" << model << "\t"              
              << seats << "\t" << weight << "\t" << xtype;
      }
};
#endif
// car.h
//
// derived class
//
#ifndef __CAR_H__
#define __CAR_H__
class Car : public Vehicles
{
   public:
      Car () {}
      Car (string rego, string make, string model, int seats, int weight) { 
         Vehicles(rego, make, model, seats, weight, "This is a car record");
      }
};
#endif
//
// bus.h
//
// derived class
//
#ifndef __BUS_H__
#define __BUS_H__
class Bus : public Vehicles
{
   public:
      Bus () {}
      Bus (string rego, string make, string model, int seats, int weight) { 
         Vehicles(rego, make, model, seats, weight, "This is a bus record");
      }
};
#endif
//
// utility.h
//
#ifndef __UTILITY_H__
#define __UTILITY_H__
#include <string>
#include <iostream>
#include <stdlib.h>
extern Vehicles Vehicle_List[];
using std::string;
using namespace std;
#endif
// utility.cpp
#include "utility.h"
void populate_test_data()
{
   const int ARRAY_SIZE_X = 8;
   const int ARRAY_SIZE_Y = 6;   
   int x;
   string data[ARRAY_SIZE_X][ARRAY_SIZE_Y] = { 
      {"AAA111","FORD","FALCON","5","1500","CAR"},
      {"BBB222","HOLDEN","CRUZE","5","1300","CAR"},
      {"CCC333","TOYOTA","YARIS","4","1050","CAR"},
      {"DDD444","FORD","ESCAPE","5","1500","CAR"},
      {"EEE555","HOLDEN","CAPTIVA","7","1400","CAR"},
      {"FFF666","TOYOTA","COROLLA","5","1400","CAR"},
      {"GGG777","MERCEDES","TRAVEGO","60","3200","BUS"},
      {"HHH888","SCANIA","NONAME","55","3500","BUS"}
   };
   for(x = 0; x < ARRAY_SIZE_X; x++) { 
      if(data[x][5] == "CAR") {
         Vehicle_List[x] = Car(data[x][0], data[x][1], data[x][2],
                                  data[x][3], data[x][4]);
      }
      else {
         Vehicle_List[x] = Bus(data[x][0], data[x][1], data[x][2],
                                  data[x][3], data[x][4]);
      }          
   }
   system("clear");
   for(x = 0; x < ARRAY_SIZE_X; x++) { 
      cout << "\n" << x << ". ";
      Vehicle_List[x].showVehicle();
   }
   sleep(60);   
}
//
// driver.h
//
// header file for the driver program
//
#ifndef __DRIVER_H__
#define __DRIVER_H__
#include <iostream>
#include <string>
#include <stdlib.h>
#include "vehicles.h"
#include "bus.h"
#include "car.h"
using namespace std;
void populate_test_data();
#endif
// driver.cpp
#include "driver.h"
const int BOOKING_SIZE = 100;
Vehicles Vehicle_List[BOOKING_SIZE];
int main()
{
   populate_test_data();
   return 0;
}
 
    