summaryrefslogtreecommitdiff
path: root/Bicycle.h
diff options
context:
space:
mode:
Diffstat (limited to 'Bicycle.h')
-rw-r--r--Bicycle.h83
1 files changed, 83 insertions, 0 deletions
diff --git a/Bicycle.h b/Bicycle.h
new file mode 100644
index 0000000..59d1770
--- /dev/null
+++ b/Bicycle.h
@@ -0,0 +1,83 @@
+#ifndef BICYCLE_H
+#define BICYCLE_H
+
+#include "Vehicle.h"
+
+#include <string>
+#include <iostream>
+using namespace std;
+
+
+template<class T>
+class Bicycle : public Vehicle<T>
+{
+ public:
+ Bicycle();
+ Bicycle(int, int, string, int); //set x, y, name and capacity (remember that capacity can be at most 2)
+ ~Bicycle();
+
+ //Redefined functions inherited from Vehicle
+ void move(int, int); // move to the requested x, y location divided by 2
+ void set_capacity(int); // set the capacity value; can't be larger than 2
+
+};
+
+//Add default constructor
+//Include: cout << "Creating new bicyle " << this->name << endl;
+template <typename T>
+Bicycle<T>::Bicycle()
+{
+ this->x_pos = 0;
+ this->y_pos = 0;
+ this->name = "Default";
+ this->capacity = 1;
+ this->current_passenger = -1;
+ this->passengers = new T[this->capacity];
+ cout << "Creating new bicyle " << this->name << endl;
+}
+
+
+//Add constructor
+//Include: cout << "Creating new bicyle " << this->name << endl;
+template <typename T>
+Bicycle<T>::Bicycle(int x, int y, string n, int c) : Vehicle<T>()
+{
+ this->x_pos = x;
+ this->y_pos = y;
+ this->name = n;
+ this->capacity = c > 2 ? 2 : c;
+ this->current_passenger = -1;
+ this->passengers = new T[this->capacity];
+ cout << "Creating new bicyle " << this->name << endl;
+}
+
+//Add destructor
+//Include: cout << "Destroyed a bicycle named: " << this->name << endl;
+template <typename T>
+Bicycle<T>::~Bicycle()
+{
+ cout << "Destroyed a bicycle named: " << this->name << endl;
+}
+
+
+//Add move function
+//Include: cout << "Moving to bicycle " << this->name << " to x: " << this->x_pos << " y: " << this->y_pos << endl;
+template <typename T>
+void Bicycle<T>::move(int x, int y)
+{
+ this->x_pos = x/2;
+ this->y_pos = y/2;
+ cout << "Moving to bicycle " << this->name << " to x: " << this->x_pos << " y: " << this->y_pos << endl;
+}
+
+//Add capacity function
+//Include: cout << "Setting bicycle " << this->name << " to " << this->capacity << endl;
+template <typename T>
+void Bicycle<T>::set_capacity(int c)
+{
+ int n = c > 2 ? 2 : c<0?-c:c;
+ Vehicle<T>::set_capacity(n);
+ cout << "Setting bicycle " << this->name << " to " << this->capacity << endl;
+}
+
+#endif