Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <fstream>
  4.  
  5. using namespace std;
  6.  
  7. class Car {
  8. protected:
  9. string model;
  10. public:
  11. Car(string model){
  12. this -> model = model;
  13. }
  14. virtual ~Car(){
  15. }
  16. };
  17.  
  18. class Porshe : public Car{
  19. public:
  20. Porshe(string model):Car(model){
  21. }
  22. virtual ~Porshe(){
  23. cout <<"Porshe " << model << endl;
  24. }
  25. };
  26.  
  27. class Lada : public Car{
  28. public:
  29. Lada(string model):Car(model){
  30. }
  31. virtual ~Lada(){
  32. cout <<"Lada " << model << endl;
  33. }
  34. };
  35.  
  36. class Honda : public Car{
  37. public:
  38. Honda(string model):Car(model){
  39. }
  40. virtual ~Honda(){
  41. cout <<"Honda " << model << endl;
  42. }
  43. };
  44.  
  45. class Mazda : public Car{
  46. public:
  47. Mazda(string model):Car(model){
  48. }
  49. virtual ~Mazda(){
  50. cout <<"Mazda " << model << endl;
  51. }
  52. };
  53.  
  54. void delet(vector <Car*> &vect){
  55. for (int i = 0; i < vect.size(); i++)
  56. delete vect[i];
  57. vect.clear();
  58. }
  59.  
  60. int main() {
  61. ifstream fin("cars.txt");
  62. string marka, model;
  63. vector <Car*> cars;
  64. int i = 0;
  65. while (fin >> marka) {
  66. fin >> model;
  67. ++i;
  68. if (marka == "Porshe") {
  69. cars.push_back(new Porshe(model));
  70. } else
  71. if (marka == "Lada") {
  72. cars.push_back(new Lada(model));
  73. } else
  74. if (marka == "Honda") {
  75. cars.push_back(new Honda(model));
  76. } else
  77. if (marka == "Mazda") {
  78. cars.push_back(new Mazda(model));
  79. } else
  80. cout << "Wrong car name line "<<i <<endl;
  81. }
  82. delet(cars);
  83. return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement