A shuttle van picks up passengers and drives them to a destination, where they leave the van. Store the names of the boarding passengers. Don't allow boarding if the van is full. Update the odometer when the van drives. Complete the following file: (image) ----------- Use the following files: van.h #ifndef VAN_H #define VAN_H #include #include using namespace std; /** This class models a shuttle van. */ class Van { public: /** Constructs a van with a given capacity. @param max_passengers the maximum number of passengers that this van can hold */ Van(int max_passengers); /** Boards a passengers up to the capacity of this van. @param name the name of the passenger attempting to board */ void board(string name); /** Drives the van and discharges the passengers. @param distance the distance driven */ void drive(double distance); /** Gets the passengers in this van. @return the number of passengers */ vector get_passengers() const; /** Gets the number of miles that this van has driven. @return the number of miles */ double get_miles_driven() const; private: double miles_driven; vector passengers; int capacity; }; #endif van_Tester.cpp #include using namespace std; #include "van.h" void print(vector v); int main() { Van van1(8); van1.board("Fred"); van1.board("Ann"); van1.board("Lee"); print(van1.get_passengers()); cout << "Expected: [Fred, Ann, Lee]" << endl; van1.board("Tim"); van1.board("Joe"); van1.board("Pat"); van1.board("May"); van1.board("Sue"); van1.board("Sally"); print(van1.get_passengers()); cout << "Expected: [Fred, Ann, Lee, Tim, Joe, Pat, May, Sue]" << endl; van1.drive(10); print(van1.get_passengers()); cout << "Expected: []" << endl; cout << van1.get_miles_driven() << endl; cout << "Expected: 10" << endl; van1.board("Sally"); print(van1.get_passengers()); cout << "Expected: [Sally]" << endl; van1.drive(12); print(van1.get_passengers()); cout << "Expected: []" << endl; cout << van1.get_miles_driven() << endl; cout << "Expected: 22" << endl; return 0; } void print(vector v) { cout << "["; if (v.size() > 0) { cout << v[0]; for (int i = 1; i < v.size(); i++) { cout << ", " << v[i]; } } cout << "]" << endl; }
A shuttle van picks up passengers and drives them to a destination, where they leave the van. Store the names of the boarding passengers. Don't allow boarding if the van is full. Update the odometer when the van drives.
Complete the following file: (image)
-----------
Use the following files:
van.h
#ifndef VAN_H #define VAN_H #include <string> #include <
van_Tester.cpp
#include <iostream> using namespace std; #include "van.h" void print(vector<string> v); int main() { Van van1(8); van1.board("Fred"); van1.board("Ann"); van1.board("Lee"); print(van1.get_passengers()); cout << "Expected: [Fred, Ann, Lee]" << endl; van1.board("Tim"); van1.board("Joe"); van1.board("Pat"); van1.board("May"); van1.board("Sue"); van1.board("Sally"); print(van1.get_passengers()); cout << "Expected: [Fred, Ann, Lee, Tim, Joe, Pat, May, Sue]" << endl; van1.drive(10); print(van1.get_passengers()); cout << "Expected: []" << endl; cout << van1.get_miles_driven() << endl; cout << "Expected: 10" << endl; van1.board("Sally"); print(van1.get_passengers()); cout << "Expected: [Sally]" << endl; van1.drive(12); print(van1.get_passengers()); cout << "Expected: []" << endl; cout << van1.get_miles_driven() << endl; cout << "Expected: 22" << endl; return 0; } void print(vector<string> v) { cout << "["; if (v.size() > 0) { cout << v[0]; for (int i = 1; i < v.size(); i++) { cout << ", " << v[i]; } } cout << "]" << endl; }
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images