Problem Statement
You are hired to develop a system that keeps track of all drivers and vehicles in a company. The company has many drivers and many different types of vehicles: bike, car, bus, truck, etc. A vehicle may have a driver assigned to it or no driver assigned to it. A driver is assigned to handle maximum one or no vehicle at a time. Sample attributes are listed below:
• Vehicle: Vehicle number, type, capacity, driver assigned
• Driver: driver id, name, vehicle assigned.
The system must be able to perform the following functions:
1. Create/Delete drivers and vehicles
2. Assign/Unassign a driver to/from a vehicle
3. List all drivers (all attributes must be shown)
4. List all vehicles (all attributes must be shown)
5. List all instances of a specified type of vehicle (all attributes of the instance must be shown)
The attached code below is what i have done so far which came along with errors :
#include <iostream>
#include <vector>
#include <string>
using namespace std;
class Driver{
private:
int ID;
string name;
string vehicle;
public:
Driver(){
int ID= 0;
string name= " ";
string vehicle= " ";
}
~Driver();
void setID(int ID)
{
this -> ID= ID;
}
void setname(string name)
{
this -> name= name;
}
void setVehicle (string vehicle)
{
this->vehicle = vehicle;
}
void print() const
{
cout << "Name = " << name << " .Id = " << ID << " .Vehicle = " << vehicle << endl;
}
};
class addDriver: public Driver{
public:
Driver(void add (Driver& driver),{
driver.setVehicle (name);
drivers.push_back (driver);
}
class Vehicle{
private:
int num;
string type;
int capacity;
Driver*driver;
public:
vector <Driver> drivers;
Vehicle(){
int num= 0;
string type= "";
int capacity= 0;
driver= new Driver;
}
Vehicle(int num, string type, int capacity, Driver*driver)
:num(num), type(type), capacity(capacity), driver(Driver){}
~Vehicle (){
delete driver;}
virtual void use() { cout << " vehicle in use" << endl;}
void setnum( int num){
this-> num= num;
}
int getnum() { return num; }
void setcapacity(int capacity) {
this -> capacity= capacity;
}
int getcapacity() { return capacity; }
void settype(string type) {
this -> type= type;
}
string gettype() {return type; }
void add (Driver& driver)
{
driver.setVehicle (name);
drivers.push_back (driver);
}
void print() const
{
cout << endl << name << " list:\n";
cout << "---------\n";
for (int i = 0; i < drivers.size(); i++)
drivers[i].print();
};
class Taxi: public Vehicle{
private:
int taxi_id;
public:
Vehicle(int taxi_id, int num, int capacity, string type, Driver*driver)
: taxi_id(taxi_id), Vehicle(num), Vehicle(capacity), Vehicle(type), Vehicle(Driver){
cout << "a taxi is created: " << " taxi's id: " << taxi_id << "taxi plate number:" << getnum() << " " << getcapacity() << " " << gettype()
<< "taxi's driver:" << Driver << endl;
}
void use() { cout << "taxi in use \n;"}
void setid(int taxi_id){
this -> taxi_id= taxi_id;
}
int getid() { return taxi_i; }
void add (Driver& driver)
{
driver.setVehicle (name);
drivers.push_back (driver);
}
void print() const
{
cout << endl << name << " list:\n";
cout << "---------\n";
for (int i = 0; i < drivers.size(); i++)
drivers[i].print();
class Car: public Vehicle{
private:
int car_id;
public:
Car(int car_id, int num, int capacity, srting type)
:car_id(car_id), num(num), capacity(capacity), type(type), Vehicle(Driver){
cout << " a car is created: "<< "car's id: " << car_id <<" car plate number : " << getnum() << " " << getcapacity() << " " << gettype()
<< "car's driver:" << Driver<< endl;
}
void use() { cout << " car in use \n";}
void setCarId(int car_id){
this -> car_id= car_id;
}
int getCarId() { return car_id;}
void add (Driver& driver)
{
driver.setVehicle (name);
drivers.push_back (driver);
}
void print() const
{
cout << endl << name << " list:\n";
cout << "---------\n";
for (int i = 0; i < drivers.size(); i++)
drivers[i].print();
};
class Truck : public Vehicle{
private:
int truckId;
public:
Truck(int truckId, int num, int capacity, string type)
:truckId(truckId), Vehicle(num), Vehicle(capacity), Vehicle(type){
cout << "a truck is created:" << " truck id : " << truckId << "truck's plate number: " << getnum()<<" " << getcapacity << " " <<gettype()
<< " truck's driver:" << Driver << endl; }
void use() { cout << " truck in use " << endl;
void setTruckId(int truckId){
this -> truckId= truckId;
}
int getTruckId() { return truckId;}
void add (Driver& driver)
{
driver.setVehicle (name);
drivers.push_back (driver);
}
void print() const
{
cout << endl << name << " list:\n";
cout << "---------\n";
for (int i = 0; i < drivers.size(); i++)
drivers[i].print();
};
void createDriver() {
cout << " enter id "
<< " enter name" << endl;
cin >> ID;
cin >> name;
D1.push_back(ID, name));
};
void destroyDriver() {
cout << " enter id to be deleted: "
<< " enter name to be deleted: " <<endl;
cin >> ID;
cin >> name;
D1.clear(Driver(ID, name));
};
void createVehicle() {
cout << "enter number "
<< "enter capacity"
<< "enter type" << endl;
cin >> num;
>> capacity;
>> type;
V1.push_back(Vehicle(num,capacity,type));
};
void deleteVehicle() {
cout << " enter vehicle number to be deleted "
<< "enter capacity"
<< "enter type" << endl;
cin >> num;
>> capacity;
>> type;
V1.clear(Vehicle( num, capacity, type));
};
void assigndriver() {
};
void unassigndriver() {
};
void listdrivers(){
};
void listvehicles(){
};
vector<Driver> D1;
vector<Vehicle> V1;
int main(){
int size;
string name;
int id;
string vehicle;
cout << "HOW MANY DRIVERS TO ASSIGN? ";
cin >> size;
cout << endl;
for (int i = 0; i < size; i++) {
cout << "Driver #" << i+1<< " : Enter name = ";
cin >> name;
cout << "Driver #" << i+1<< " : Enter id = ";
cin >> id;
cout << "Driver #" << i+1<< " : Enter vehicle = ";
cin >> vehicle;
Driver driver;
driver.setname (name);
driver.setID (id);
driver.setVehicle(vehicle);
drivers.push_back (driver);
}
Vehicle car ("Car");
Vehicle taxi ("Taxi");
Vehicle truck ("Truck");
cout << endl;
cout << "All drivers:\n";
cout << "-----------\n";
for (int i = 0; i < size; i++)
drivers[i].print();
car.use();
truck.use();
taxi.use();
cout << endl;
}
This post has been edited by macosxnerd101: 29 August 2011 - 06:07 AM
Reason for edit:: Please use code tgas

New Topic/Question
Reply



MultiQuote





|