暫無描述

main.cpp 4.0KB

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