Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.16 KB | None | 0 0
  1.  
  2. #include "bus.h"
  3. #include "functions.h"
  4. #include <string>
  5. #include <iostream>
  6. #include<fstream>
  7. int SIZE = 50;
  8. using namespace std;
  9.  
  10. int main() {
  11.  
  12. fstream inFile;
  13. string input;
  14. string temp;
  15. int i = 0;
  16.  
  17. Bus * busArray[SIZE];
  18. for (int i = 0; i < SIZE; i++){
  19. busArray[i] = nullptr;
  20. }
  21.  
  22. inFile.open("C:\\Users\\Mohammad\\Documents\\CS200\\Eclipse Workspace\\KhanA4\\src\\a4data.txt");
  23. if(inFile.fail()){
  24. cout << "Unsuccessful to open file" << endl;
  25. return -1;
  26. }
  27.  
  28. //setArray(busArray, inFile);
  29. getline(inFile,temp);
  30. while(!inFile.eof()){
  31.  
  32. busArray[i] = new Bus(temp.substr(0,5), temp.substr(5,10),stoi(temp.substr(15,3)),stoi(temp.substr(18,7)),temp.c_str()[25]);
  33. i++;
  34. getline(inFile,temp);
  35. }
  36.  
  37. display(busArray);
  38. do{
  39. cout << "Enter A Transaction Code(D = display, L = list a bus, C=change, X=exit)";
  40. cin >> input;
  41. cout << input << endl;
  42. if(input.c_str()[0]== 'D'){
  43. display(busArray);
  44. }
  45. else if(input.c_str()[0] == 'L'){
  46. listt(busArray,input);
  47. }
  48. else if(input.c_str()[0] == 'C'){
  49. change(busArray,input);
  50. }
  51. cout << "Enter transaction code (D = display, L = list a bus, C=change, X=exit \n)";
  52. getline(cin,input);
  53. }while(input.c_str()[0] != 'X');
  54.  
  55. for(int i = 0; i<SIZE; i++){
  56. delete busArray[i];
  57. }
  58. cout << "Thank you and have a nice day!" << endl;
  59. inFile.close();
  60. return 0;
  61. }
  62.  
  63.  
  64. #include "functions.h"
  65.  
  66.  
  67.  
  68. void listt(Bus* array[],string x){
  69. int i =0;
  70. int y = 0;
  71. while( array[i] != nullptr){
  72. if(array[i]->getBusID() == x.substr(2,5)){
  73.  
  74. cout << "=======================================================================\n";
  75. cout << "BUS ID\t\t" << "BUS MANUFACTURER\t" << "BUS CAPACITY\t" << "MILEAGE\t" <<setw(5) <<"Status" << endl;
  76. cout << "=======================================================================\n";
  77. cout << array[i]->getBusID() << "\t\t" << array[i]->getmanufacturer()
  78. << "\t\t" <<setw(5) <<array[i]->getCapacity() << "\t\t"<<array[i]-> getMileage() << "\t" << setw(5) <<array[i]->getStatus() << '\n';
  79. cout << "---end of list---" << endl;
  80.  
  81. y++;
  82. }
  83. i++;
  84. }
  85. if(y <= 0){
  86. cout << "Not Found" << endl;
  87. }
  88. }
  89.  
  90. void change(Bus* array[],string x){
  91. int i = 0;
  92. int y = 0;
  93. while(array[i] != nullptr){
  94. if(array[i]->getBusID() == x.substr(2,5)){
  95. cout << "Change successful!" << endl;
  96. array[i]->setStatus(x.c_str()[8]);
  97. y++;
  98. }
  99. i++;
  100. }
  101. if(y <= 0){
  102. cout <<"not Found" << endl;
  103. }
  104. }
  105.  
  106. void display(Bus * array[]){
  107. int i = 0;
  108. cout << "=======================================================================\n";
  109. cout << "BUS ID\t\t" << "BUS MANUFACTURER\t" << "BUS CAPACITY\t" << "MILEAGE\t" <<setw(5) <<"Status" << endl;
  110. cout << "=======================================================================\n";
  111.  
  112. while(array[i] != nullptr){
  113. cout << array[i]->getBusID() << "\t\t" << array[i]->getmanufacturer()
  114. << "\t\t" <<setw(5) <<array[i]->getCapacity() << "\t\t"<<array[i]-> getMileage() << "\t" << setw(5) <<array[i]->getStatus() << '\n';
  115. i++;
  116.  
  117. }
  118.  
  119. cout << "---end of list---" << endl;
  120. }
  121.  
  122. /*
  123. * Bus.h
  124. *
  125. * Created on: Oct 7, 2019
  126. * Author: Mohammad
  127. */
  128. #include <string>
  129. #include <iostream>
  130. #ifndef BUS_H_
  131. #define BUS_H_
  132. using namespace std;
  133.  
  134. class Bus{
  135. private:
  136. string busID;
  137. string manufacturer;
  138. int capacity;
  139. int mileage;
  140. char status;
  141. public:
  142. Bus();
  143. Bus(string,string,int,int,char);
  144. string getBusID();
  145. string getmanufacturer();
  146. int getCapacity();
  147. int getMileage();
  148. char getStatus();
  149. void setStatus(char);
  150. };
  151.  
  152.  
  153. #endif /* BUS_H_ */
  154.  
  155.  
  156. /*
  157. * Bus.cpp
  158. *
  159. * Created on: Oct 9, 2019
  160. * Author: Mohammad
  161. */
  162. #include "Bus.h"
  163. #include <iostream>
  164. #include <string>
  165. using namespace std;
  166.  
  167. Bus::Bus(string bus,string manu,int cap,int miles,char stat){
  168. busID = bus;
  169. manufacturer = manu;
  170. capacity = cap;
  171. mileage = miles;
  172. status = stat;
  173. }
  174. string Bus::getBusID(){
  175. return busID;
  176. }
  177. string Bus::getmanufacturer(){
  178. return manufacturer;
  179. }
  180. int Bus::getCapacity(){
  181. return capacity;
  182. }
  183. int Bus::getMileage(){
  184. return mileage;
  185. }
  186. char Bus::getStatus(){
  187. return status;
  188. }
  189. void Bus::setStatus(char x){
  190. status = x;
  191. }
  192.  
  193. #include "bus.h"
  194. #include <fstream>
  195. #include <iomanip>
  196. #ifndef FUNCTIONS_HPP_
  197. #define FUNCTIONS_HPP_
  198.  
  199. void display(Bus * []);
  200. void setArray(Bus * [],fstream &);
  201. void listt(Bus*[],string);
  202. void change(Bus*[],string);
  203.  
  204. #endif /* FUNCTIONS_HPP_ */
  205.  
  206.  
  207.  
  208. #include "functions.h"
  209.  
  210.  
  211.  
  212. void listBus(Bus* array[],string x){
  213. int i =0;
  214. int y = 0;
  215. while( array[i] != nullptr){
  216. if(array[i]->getBusID() == x.substr(2,5)){
  217.  
  218. cout << "=======================================================================\n";
  219. cout << "BUS ID\t\t" << "BUS MANUFACTURER\t" << "BUS CAPACITY\t" << "MILEAGE\t" <<setw(5) <<"Status" << endl;
  220. cout << "=======================================================================\n";
  221. cout << array[i]->getBusID() << "\t\t" << array[i]->getmanufacturer()
  222. << "\t\t" <<setw(5) <<array[i]->getCapacity() << "\t\t"<<array[i]-> getMileage() << "\t" << setw(5) <<array[i]->getStatus() << '\n';
  223. cout << "---end of list---" << endl;
  224.  
  225. y++;
  226. }
  227. i++;
  228. }
  229. if(y <= 0){
  230. cout << "Not Found" << endl;
  231. }
  232. }
  233.  
  234. void change(Bus* array[],string x){
  235. int i = 0;
  236. int y = 0;
  237. while(array[i] != nullptr){
  238. if(array[i]->getBusID() == x.substr(2,5)){
  239. cout << "Change successful!" << endl;
  240. array[i]->setStatus(x.c_str()[8]);
  241. y++;
  242. }
  243. i++;
  244. }
  245. if(y <= 0){
  246. cout <<"not Found" << endl;
  247. }
  248. }
  249.  
  250. void display(Bus * array[]){
  251. int i = 0;
  252. cout << "=======================================================================\n";
  253. cout << "BUS ID\t\t" << "BUS MANUFACTURER\t" << "BUS CAPACITY\t" << "MILEAGE\t" <<setw(5) <<"Status" << endl;
  254. cout << "=======================================================================\n";
  255.  
  256. while(array[i] != nullptr){
  257. cout << array[i]->getBusID() << "\t\t" << array[i]->getmanufacturer()
  258. << "\t\t" <<setw(5) <<array[i]->getCapacity() << "\t\t"<<array[i]-> getMileage() << "\t" << setw(5) <<array[i]->getStatus() << '\n';
  259. i++;
  260.  
  261. }
  262.  
  263. cout << "---end of list---" << endl;
  264. }
  265.  
  266. #include <string>
  267. #include <iostream>
  268. #ifndef BUS_H_
  269. #define BUS_H_
  270. using namespace std;
  271.  
  272. class Bus{
  273. private:
  274. string busID;
  275. string manufacturer;
  276. int capacity;
  277. int mileage;
  278. char status;
  279. public:
  280. Bus();
  281. Bus(string,string,int,int,char);
  282. string getBusID();
  283. string getmanufacturer();
  284. int getCapacity();
  285. int getMileage();
  286. char getStatus();
  287. void setStatus(char);
  288. };
  289.  
  290.  
  291. #endif /* BUS_H_ */
  292.  
  293.  
  294. /*
  295. * Bus.cpp
  296. *
  297. * Created on: Oct 9, 2019
  298. * Author: Mohammad
  299. */
  300. #include "Bus.h"
  301. #include <iostream>
  302. #include <string>
  303. using namespace std;
  304.  
  305. Bus::Bus(string bus,string manu,int cap,int miles,char stat){
  306. busID = bus;
  307. manufacturer = manu;
  308. capacity = cap;
  309. mileage = miles;
  310. status = stat;
  311. }
  312. string Bus::getBusID(){
  313. return busID;
  314. }
  315. string Bus::getmanufacturer(){
  316. return manufacturer;
  317. }
  318. int Bus::getCapacity(){
  319. return capacity;
  320. }
  321. int Bus::getMileage(){
  322. return mileage;
  323. }
  324. char Bus::getStatus(){
  325. return status;
  326. }
  327. void Bus::setStatus(char x){
  328. status = x;
  329. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement