fork download
  1. #include<iostream>
  2. #include<string>
  3. #include<fstream>
  4. using namespace std;
  5. class Vehical
  6. {
  7. protected:
  8. int reg_no;
  9. int id;
  10. public:
  11. Vehical()
  12. {
  13. reg_no = 0;
  14. id = 0;
  15. }
  16. virtual void inputData() = 0;
  17. virtual void printData() = 0;
  18. virtual void writingDet() = 0;
  19. virtual int search(string) = 0;
  20. };
  21. class Bike :public Vehical
  22. {
  23. private:
  24. string Bike_clr;
  25. string bike_typ;
  26. int model;
  27. public:
  28. Bike() :Vehical()
  29. {
  30. Bike_clr = "";
  31. bike_typ = "";
  32. model = 0;
  33. }
  34. void inputData()
  35. {
  36. cout << "Enter registration no of Bike : " << ' ';
  37. cin >> reg_no;
  38. cout << "Enter ID of Bike : " << ' ';
  39. cin >> id;
  40. cin.ignore();
  41. cout << "Enter Bike Color : " << ' ';
  42. getline(cin, Bike_clr);
  43. cout << "Enter Bike Type : " << ' ';
  44. getline(cin, bike_typ);
  45. cout << "Enter Model (year) : " << ' ';
  46. cin >> model;
  47. }
  48. void printData()
  49. {
  50. cout << "Reg No. " << reg_no << endl;
  51. cout << "ID no. " << id << endl;
  52. cout << "Bike Color " << Bike_clr << endl;
  53. cout << "Bike Type " << bike_typ << endl;
  54. cout << "Model Year " << model << endl;
  55. }
  56. void writingDet()
  57. {
  58. ofstream file;
  59. if (bike_typ == "Heavy Bike")
  60. {
  61. file.open("Heavy Bike.txt", ios::app);
  62. if (file.is_open())
  63. {
  64. file << reg_no << endl;
  65. file << id << endl;
  66. file << Bike_clr << endl;
  67. file << bike_typ << endl;
  68. file << model << endl;
  69. file << endl;
  70. }
  71. else
  72. {
  73. cerr << "Your File cannot be open" << endl;
  74. }
  75. }file.close();
  76. }
  77. int search(string clr)
  78. {
  79. string line;
  80. ifstream fm;
  81. fm.open("Heavy Bike.txt");
  82. for (line; getline(fm, line);)
  83. {
  84.  
  85. if (line.find(clr) != string::npos)
  86. {
  87. cout << "\n\nFound" << endl;
  88. fm >> reg_no;
  89. cout << reg_no << endl;
  90. fm >> id;
  91. cout << id << endl;
  92. getline(fm, Bike_clr);
  93. cout << Bike_clr << endl;
  94. getline(fm, bike_typ);
  95. cout << bike_typ << endl;
  96. fm >> model;
  97. cout << model << endl;
  98. }
  99. }
  100. return 1;
  101. }
  102. };
  103. class Car :public Vehical
  104. {
  105. private:
  106. string car_clr;
  107. string car_typ;
  108. int crmodel;
  109. public:
  110. Car()
  111. {
  112. car_clr = "";
  113. car_typ = "";
  114. crmodel = 0;
  115. }
  116. void inputData()
  117. {
  118. cout << endl;
  119. cout << "Enter registration no of Car : " << ' ';
  120. cin >> reg_no;
  121. cout << "Enter ID of Car : " << ' ';
  122. cin >> id;
  123. cin.ignore();
  124. cout << "Enter Car Color : " << ' ';
  125. getline(cin, car_clr);
  126. cout << "Enter Car Type : " << ' ';
  127. getline(cin, car_typ);
  128. cout << "Enter Model (year) : " << ' ';
  129. cin >> crmodel;
  130. cin.ignore();
  131. cout << endl;
  132. cout << endl;
  133. }
  134. void printData()
  135. {
  136. cout << "Reg No. " << reg_no << endl;
  137. cout << "ID no. " << id << endl;
  138. cout << "Car Color " << car_clr << endl;
  139. cout << "Car Type " << car_typ << endl;
  140. cout << "Model Year " << crmodel << endl;
  141. }
  142. };
  143. int main()
  144. {
  145. Vehical* vc[5];
  146. Bike bk;
  147. string clr;
  148. bool found;
  149. for (int i = 0; i < 2; i++)
  150. {
  151. vc[i] = new Bike;
  152. vc[i] = &bk;
  153. vc[i]->inputData();
  154. vc[i]->writingDet();
  155. }
  156. cin.ignore();
  157. cout << "\nEnter Color of Bike you want : " << ' ';
  158. getline(cin, clr);
  159. for (int k = 0; k < 2; k++)
  160. {
  161. found = vc[k]->search(clr);
  162. if (found)
  163. {
  164. break;
  165. }
  166. else
  167. {
  168. continue;
  169. }
  170. }
  171. cout << endl;
  172. system("PAUSE");
  173. return 0;
  174. }
Success #stdin #stdout #stderr 0s 4788KB
stdin
Standard input is empty
stdout
Enter registration no of Bike :  Enter ID of Bike :  Enter Bike Color :  Enter Bike Type :  Enter Model (year) :  Enter registration no of Bike :  Enter ID of Bike :  Enter Bike Color :  Enter Bike Type :  Enter Model (year) :  
Enter Color of Bike you want :  
stderr
sh: 1: PAUSE: not found