Advertisement
Guest User

Untitled

a guest
Jul 28th, 2015
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1.  
  2. #include "Interfaces.h"
  3. #include <string>
  4. #include <iostream>
  5. #include <fstream>
  6. #include <sstream>
  7. #include <algorithm>
  8.  
  9. using namespace std;
  10.  
  11. class myObject
  12. {
  13. string description;
  14. public:
  15.  
  16. myObject(string s) : description(s)
  17. {
  18. }
  19. virtual ~myObject()
  20. {
  21. }
  22. virtual void print() = 0;
  23. string operator*() { return description; }
  24. };
  25.  
  26. class Book: public myObject
  27. {
  28. public:
  29. Book() : myObject(" ")
  30. {
  31. }
  32. Book(string s):myObject(s)
  33. {
  34. }
  35. virtual ~Book()
  36. {
  37. }
  38. virtual void print()
  39. {
  40. cout<<this<<endl;
  41. }
  42.  
  43. };
  44.  
  45. class Passenger : public myObject
  46. {
  47. public:
  48. Passenger() :myObject(" ")
  49. {
  50. }
  51. Passenger(string s) : myObject(s)
  52. {
  53. }
  54. virtual ~Passenger()
  55. {
  56. }
  57. virtual void print()
  58. {
  59. cout<<this<<endl;
  60. }
  61. };
  62.  
  63. template <typename T>
  64. class Container : public myObject
  65. {
  66. T* objects;
  67. int size;
  68. public:
  69. Container(int i) : size(i)
  70. {
  71. objects = new T[size];
  72. }
  73. ~Container()
  74. {
  75. delete[] objects;
  76. }
  77. void initializeBook(string s, int i)
  78. {
  79. objects[i] = Book(s);
  80. }
  81. void initializePassenger(string s, int i)
  82. {
  83. objects[i] = Passenger(s);
  84. }
  85. void print()
  86. {
  87. for(int i=0; i <size;i++)
  88. {
  89. cout<<*objects[i]<<endl;
  90. }
  91. }
  92. };
  93.  
  94. int main()
  95. {
  96. int numBooks = 0;
  97. int numPassengers = 0;
  98. ifstream in("Airline.csv");
  99. if ( in.fail()){
  100. cout<<"failed to open"<< endl;
  101. }
  102.  
  103. string line;
  104. while(getline(in,line))
  105. {
  106. numPassengers++;
  107. }
  108. in.close();
  109. in.clear();
  110. in.open("Books.csv");
  111. if ( in.fail()){
  112. cout<<"failed to open 2"<< endl;
  113. }
  114.  
  115. while(getline(in,line))
  116. {
  117. numBooks++;
  118. }
  119.  
  120. in.clear();
  121. in.seekg(0,ios::beg);
  122.  
  123. Container<Book> bookContainer(numBooks);
  124.  
  125. if(in.is_open())
  126. {
  127. int i = 0;
  128.  
  129. while(getline(in,line))
  130. {
  131. replace( line.begin(), line.end(), ',', ' ');
  132.  
  133. bookContainer.initializeBook(line,i);
  134. i++;
  135. }
  136. }
  137. in.close();
  138. in.clear();
  139. in.open("Airline.csv");
  140. Container<Passenger> passengerContainer(numPassengers);
  141. if(in.is_open())
  142. {
  143. int i = 0;
  144. while(getline(in,line))
  145. {
  146. replace( line.begin(), line.end(), ',', ' ');
  147. passengerContainer.initializePassenger(line,i);
  148. i++;
  149. }
  150. }
  151. bookContainer.print();
  152. passengerContainer.print();
  153. in.close();
  154.  
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement