fork download
  1. # include <iostream>
  2. # include <fstream>
  3. # include <map>
  4. # include <string>
  5. # include <cstdlib>
  6. # include <sstream>
  7. using namespace std;
  8.  
  9. #define JAI "Jai"
  10. #define VEERU "Veeru"
  11.  
  12.  
  13.  
  14. // Abstract Class [Interface]
  15. class busCompanies
  16. {
  17. public:
  18. // virtual void writeToFile() = 0;
  19. virtual void insert(int arrival, int departure) = 0;
  20. virtual map<int, int> getMap() = 0;
  21. };
  22.  
  23. class jai : public busCompanies
  24. {
  25. map<int, int> jaiMap;
  26. map<string, string> jaiOutputMap;
  27. public:
  28.  
  29. void insert(int arrival, int departure) {
  30. jaiMap[departure] = arrival;
  31. }
  32.  
  33. map<int, int> getMap() {
  34. return jaiMap;
  35. }
  36.  
  37. // void writeToFile();
  38. };
  39.  
  40. class veeru : public busCompanies
  41. {
  42. map<int, int> veeruMap;
  43. map<string, string> veeruOutputMap;
  44. public:
  45. void insert(int arrival, int departure) {
  46. veeruMap[departure] = arrival;
  47. }
  48.  
  49. map<int, int> getMap() {
  50. return veeruMap;
  51. }
  52. // void writeToFile();
  53. };
  54.  
  55. class ramgarh
  56. {
  57. busCompanies *bc;
  58. public:
  59. static busCompanies* getBusCompany(string name) {
  60. if (name == JAI)
  61. return new jai;
  62. else if (name == VEERU)
  63. return new veeru;
  64. }
  65.  
  66. void efficientService() {
  67. bc = new jai();
  68. map<int, int> jMap = bc->getMap();
  69.  
  70. delete bc;
  71. bc = new veeru();
  72. map<int, int> vMap = bc->getMap();
  73.  
  74. map<int, int>:: iterator jMit, vMit;
  75.  
  76. for (jMit = jMap.begin(); jMit != jMap.end(); jMit++) {
  77. int dep = jMit->first;
  78. int arr = jMit->second;
  79.  
  80. vMit = vMap.find(dep);
  81. if (vMit != vMap.end()) {
  82. if (arr == vMit->second)
  83. //remove from veeru.
  84. }
  85.  
  86.  
  87. }
  88. };
  89.  
  90. class jointTimeTable
  91. {
  92. busCompanies *m_busCompany;
  93. public:
  94. int getTimeDifference(string, string, int*, int*);
  95. void readInput(string fileName);
  96. };
  97.  
  98. int jointTimeTable::getTimeDifference(string dep, string arr, int *arrTime, int *depTime) {
  99. stringstream ss;
  100. int depH ; int depM; int arrH; int arrM;
  101. ss << dep;
  102. char extra;
  103. ss >> depH >> extra >> depM;
  104. ss.clear();
  105. ss << arr;
  106. ss >> arrH >> extra >> arrM;
  107. *depTime = depH*100 + depM;
  108. *arrTime = arrH*100 + arrM;
  109. int startTime = 0;
  110. int endTime = 0;
  111.  
  112. if (arrH < depH){
  113. startTime = 24*60 - (depH*60 + depM);
  114. endTime = (arrH)*60+(arrM);
  115. return startTime+endTime;
  116. }
  117. startTime = (depH)*60+(depM);
  118. endTime = (arrH)*60+(arrM);
  119. return endTime-startTime;
  120. }
  121.  
  122. void jointTimeTable::readInput(string fileName) {
  123. std::string line, name, arrival, departure;
  124.  
  125. // File reading and store in respective Classes.
  126. ifstream inFile (fileName.c_str());
  127. if (inFile.is_open()) {
  128. while (getline(inFile, line)) {
  129. int len = line.length();
  130.  
  131. int firstSpace = line.find(" ", 0);
  132. name = line.substr(0, firstSpace);
  133.  
  134. int nxtSpace = line.find(" ", firstSpace+1);
  135. arrival = line.substr(firstSpace+1, nxtSpace-firstSpace-1);
  136.  
  137. departure = line.substr(nxtSpace+1, len-nxtSpace-1);
  138. // cout<<name<<" "<< arrival<< " "<<departure<<endl;
  139.  
  140. // insert arrival/departure in JAI/VEERU Class.
  141. m_busCompany = ramgarh::getBusCompany(name);
  142.  
  143. int arr, dep;
  144. int serviceTime = getTimeDifference(arrival, departure, &arr, &dep);
  145.  
  146. if (serviceTime <= 60) {
  147. cout<<name<<" "<< arr<< " "<<dep<<endl;
  148. m_busCompany->insert(arr, dep);
  149. }
  150. }
  151. inFile.close();
  152. } else
  153. cout<<"File cannot be Opened"<<endl;
  154. }
  155.  
  156. int main()
  157. {
  158. jointTimeTable timeTable;
  159. timeTable.readInput("service.txt");
  160.  
  161.  
  162. return 0;
  163. }
  164.  
  165.  
  166.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:98:89: error: cannot define member function 'ramgarh::jointTimeTable::getTimeDifference' within 'ramgarh'
 int jointTimeTable::getTimeDifference(string dep, string arr, int *arrTime, int *depTime) {
                                                                                         ^
prog.cpp:122:47: error: cannot define member function 'ramgarh::jointTimeTable::readInput' within 'ramgarh'
 void jointTimeTable::readInput(string fileName) {
                                               ^
prog.cpp:163:1: error: expected '}' at end of input
 }
 ^
prog.cpp: In member function 'void ramgarh::efficientService()':
prog.cpp:84:4: error: expected primary-expression before '}' token
    }
    ^
prog.cpp: At global scope:
prog.cpp:163:1: error: expected unqualified-id at end of input
 }
 ^
stdout
Standard output is empty