Browse Source

Drone explores for user defined time

logicp 8 years ago
parent
commit
30b43e29b3
3 changed files with 60 additions and 20 deletions
  1. 38 16
      drone.cpp
  2. 2 3
      drone.h
  3. 20 1
      main.cpp

+ 38 - 16
drone.cpp

@@ -8,35 +8,57 @@
 #include <limits>
 #include "drone.h"
 
+using namespace std;
+
 drone::drone() {}
 
 drone::drone(int payload) {
     payload = payload;
 }
 
-int drone::explore() {
-    std::time_t startTime = std::time(nullptr);
+void drone::self_destruct(bool explosives) {
+    std::cout << "Self destruct timer initiated";
+}
 
-    std::time_t currentTime;
-    int explore_time;
-    double seconds;
+void drone::set_location(float longitude, float latitude) {
+    std::cout << "Location set to " << longitude << std::endl << "Latitude set to " << latitude << std::endl;
+}
 
-    std::cout << "Input explore duration for drone mission: " << std::endl;
-    std::cin >> explore_time;
-    std::time(&currentTime); //get the time now that the user has entered something and stick it in currentTime
+int drone::explore(int explore_time) {
 
-    seconds = std::difftime(currentTime, startTime);
-    std::cout << "It took you " << seconds << " seconds to enter something.\n";
+    int xRan;
+    int distance_travelled;
 
-    std::cout << "Input something else...";
-    std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
-    std::time(&currentTime);
+    srand( time(0)); // This will ensure a really randomized number by help of time.
 
-    seconds = std::difftime(currentTime, startTime);
-    std::cout << "It has now been " << seconds << " seconds since you started the program.\n";
+    xRan=rand()%9+1;
 
-    return 69;
 
+    distance_travelled = explore_time * xRan;
+
+    return distance_travelled;
+//    std::time_t startTime = std::time(nullptr);
+//
+//    std::time_t currentTime;
+//    double seconds;
+//
+//    std::cout << "Input explore duration for drone mission: " << std::endl;
+//    std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
+//    std::time(&currentTime); //get the time now that the user has entered something and stick it in currentTime
+//
+//    seconds = std::difftime(currentTime, startTime);
+//    std::cout << "It took you " << seconds << " seconds to enter something.\n";
+//
+//    std::cout << "Input something else...";
+//    std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
+//    std::time(&currentTime);
+//
+//    seconds = std::difftime(currentTime, startTime);
+//    std::cout << "It has now been " << seconds << " since you were asked to input something\n";
+
+
+
+    return 69;
 
 
 }

+ 2 - 3
drone.h

@@ -15,7 +15,7 @@ public:
     drone(int payload);
 
 
-    int explore();
+    int explore(int time);
 
     void self_destruct(bool explosives);
 
@@ -25,8 +25,7 @@ public:
         return active;
     }
 
-    void set_location(float longitude, float latitude) {
-    }
+    void set_location(float longitude, float latitude);
 
 
 private:

+ 20 - 1
main.cpp

@@ -1,17 +1,36 @@
 #include <iostream>
 #include <ctime>
+#include <iomanip>
+#include <zconf.h>
 #include "throttle.h"
 #include "drone.h"
 
 using namespace std;
 using namespace main_stronglogic;
 
+float lng, lat;
+int mission_time;
+int distance_travelled;
+
 drone my_drone;
 
 int main() {
     std::cout << "Beginning drone program" << std::endl;
 
-    my_drone.explore();
+    std::cout << "Please enter geolocation coordinates" << std::endl << "Longitude:" << std::endl;
+    std::cin >> lng;
+    std::cout << std::endl << "Latitude:" << std::endl;
+    std::cin >> lat;
+
+    my_drone.set_location(lng,lat);
+
+    cout << "Enter mission length in minutes" << endl;
+    cin >> mission_time;
+
+
+    distance_travelled = my_drone.explore(mission_time);
+
+    cout << "Drone has travelled " << distance_travelled << " km" << endl;
 
     return 0;
 }