pgiovanni

Untitled

Oct 14th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.19 KB | None | 0 0
  1. #include "Route.h"
  2. #include <iostream>
  3. #include <fstream>
  4. #include <algorithm>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9.  
  10. Route::Route() {}
  11.  
  12. void Route::populate(string path_to_route) {
  13.  
  14.     ifstream choose_route;
  15.  
  16.     choose_route.open (path_to_route);
  17.  
  18.     string stop;
  19.     while (choose_route.good()) {
  20.         getline(choose_route, stop);
  21.         raw_route.push_back(stop);
  22.     }
  23.     choose_route.close();
  24.  
  25. }
  26. void Route::sort_packages() {
  27.     vector<int> package_indexes;
  28.     string one_package_in;
  29.     bool continue_scanning = true;
  30.  
  31.  
  32.  
  33.     do {
  34.  
  35.         getline(cin, one_package_in);
  36.         if (one_package_in == "stop")
  37.             continue_scanning = false;
  38.         for (unsigned int package_index = 0; package_index < raw_route.size(); ++package_index) {
  39.  
  40.             if (one_package_in == raw_route[package_index])
  41.                 package_indexes.push_back(package_index);
  42.         }
  43.  
  44.  
  45.         if (find(raw_route.begin(), raw_route.end(), one_package_in) == raw_route.end() && one_package_in != "stop") {
  46.             cout << "Package not on route, Please check your spelling." << endl;
  47.         }
  48.  
  49.  
  50.     } while (continue_scanning);
  51.  
  52.     sort(package_indexes.begin(), package_indexes.end());
  53.  
  54.  
  55.     for (unsigned int i = 0; i < package_indexes.size(); ++i)
  56.  
  57.         cout << "Stop " + to_string(i) + ": " + raw_route[package_indexes[i]] << endl;
  58.  
  59. }
  60. void Route::time_calculation() {
  61.     string location;
  62.     bool continue_searching = true;
  63.     cout << "Enter your current location" << endl;
  64.    
  65.  
  66.    
  67.    
  68.    
  69.     do {
  70.         getline(cin, location);
  71.        
  72.         for (float i = 0; i < raw_route.size(); ++i) {
  73.            
  74.             if (location == raw_route[i] && find(raw_route.begin(), raw_route.end(), location) != raw_route.end()) {
  75.  
  76.  
  77.                 float percent_completed = i / raw_route.size() * 100;
  78.                 float percent_left = 100 - (i / raw_route.size()) * 100;
  79.  
  80.  
  81.  
  82.  
  83.                 cout << "You have done " + to_string(percent_completed) +
  84.                     "% of the stops on this route. \nYou have " + to_string(percent_left) +
  85.                     "% percent of the stops left on the route." << endl;
  86.                 continue_searching = false;
  87.  
  88.  
  89.             }
  90.            
  91.            
  92.         }
  93.        
  94.         if (find(raw_route.begin(), raw_route.end(), location) == raw_route.end())
  95.             cout << "Invalid entry!" << endl;
  96.        
  97.     } while (continue_searching);
  98.  
  99. }
  100. void Route::raw_route_piece(string path_to_piece) {
  101.  
  102.    
  103.  
  104. }
Add Comment
Please, Sign In to add comment