Sin descripción

main.cpp 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #define QT_NO_DEBUG_OUTPUT
  2. #include "mainwindow.h"
  3. #include <QApplication>
  4. #include <cmath>
  5. #include <cassert>
  6. #include <fstream>
  7. using namespace std;
  8. // Function unitTests:
  9. // Some unit tests for the distance function
  10. // void unitTests(){
  11. // GISPOI ny( "NewYork", 40.7142, -74.0064 );
  12. // GISPOI london("London", 51.50, -0.1167 );
  13. // GISPOI la( "LA", 34.0522, -118.2428);
  14. // assert(abs( ny.odDistance(london) - 5576.74) < 10);
  15. // assert(abs( ny.odDistance(la) - 3940.14) < 10);
  16. // assert(abs( ny.odDistance(ny) - 0) < 100);
  17. // cout << "Passed all unit tests...\n";
  18. // }
  19. // Function printArrayOfCities(A, size):
  20. // Given A, an array of GISPOI objects and its size, prints
  21. // all the cities in the array.
  22. void printArrayOfCities(GISPOI A[], int size) {
  23. for (int i = 0; i < size; i++)
  24. A[i].print();
  25. }
  26. // Function countLinesInFile(f)
  27. // Given a reference to the object that represents a file, this function
  28. // counts and returns the number of lines in the file.
  29. int countLinesInFile(ifstream &file) {
  30. string dummy;
  31. int ctr = 0;
  32. while( getline(file,dummy)) ctr++;
  33. // 'reset' the file, so that it can be reread from the start
  34. file.clear();
  35. file.seekg(0, ios::beg) ;
  36. return ctr;
  37. }
  38. // Function readFileToArray(file, A, numCities):
  39. // Given the ifstream object of a file, an (empty) array of cities
  40. // and the number of records to read from the file, this function
  41. // reads the values from the file and populates the array with
  42. // objects.
  43. void readFileToArray(ifstream &file, GISPOI A[], int numOfCities) {
  44. // your code here
  45. cout << "Reading the file and storing in array of cities.."
  46. "(your job)" << endl;
  47. }
  48. // Function maxDistances(A, size, idxCityA, idxCityB):
  49. // Given the array of cities, determines the farthest two cities.
  50. // Returns (by reference) the indices of the two cities in the array.
  51. void maxDistances(GISPOI A[], int size, int &idxCityA, int &idxCityB){
  52. // your code here
  53. }
  54. // Function minDistances(A, size, idxCityA, idxCityB):
  55. // Given the array of cities, determines the closest two cities.
  56. // Returns (by reference) the indices of the two cities in the array.
  57. void minDistances(GISPOI A[], int size, int &idxCityA, int &idxCityB){
  58. // your code here
  59. cout << "Computing the two closest cities..." <<
  60. "(your job)" << endl;
  61. }
  62. // Function cycleDistance (A, size, P):
  63. // Given the array of cities, the size of the array and a array (P) with a
  64. // permutation of the integers [0, size-1] computes and returns the distance
  65. // to travel the cycle of cities A[P[0]] -- A[P[1]] -- .... -- A[P[size-1]]
  66. double cycleDistance(GISPOI A[], int size, int P[]){
  67. // your code here
  68. return 0.0;
  69. }
  70. // The main program can be summarized with this pseudocode:
  71. // 1. Reads the contents of the file to an array of structures.
  72. // 2. Computes the cities with max distance.
  73. // 3. Computes the cities with min distance.
  74. // 4. Computes the total distance of traveling the cities in a certain order.
  75. int main(int argc, char *argv[])
  76. {
  77. QApplication a(argc, argv);
  78. MainWindow w;
  79. w.show();
  80. cout << "Welcome to PR map!!!!" << endl;
  81. // open the file and check its validity
  82. // you need to use inFile.open(fileName.c_str()) instead of inFile.open(fileName)
  83. // since the open method expects a c-type string instead of a c++ string object
  84. // count the number of lines in the file
  85. // create an array of GISPOI objects with exactly as many elements as there
  86. // are lines in the file.
  87. // read the data from the file into the array of structures
  88. // paint the points onto the map window
  89. // Here: Put the code to invoke the max distance function and show a line
  90. // in the map between those two cities.
  91. // Here: Put the code to invoke the min distance function and show a line
  92. // in the map between those two cities.
  93. // Here: Put the code to compute the cycle distance using these permutation
  94. // P = {0, 2, 4, 6, 8, 1, 3, 5, 7, 9}
  95. // P = {0, 3, 6, 9, 1, 4, 7, 2, 5, 8}
  96. return a.exec();
  97. }