Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <fstream>
- using namespace std;
- class Car {
- protected:
- string model;
- public:
- Car(string model){
- this -> model = model;
- }
- virtual ~Car(){
- }
- };
- class Porshe : public Car{
- public:
- Porshe(string model):Car(model){
- }
- virtual ~Porshe(){
- cout <<"Porshe " << model << endl;
- }
- };
- class Lada : public Car{
- public:
- Lada(string model):Car(model){
- }
- virtual ~Lada(){
- cout <<"Lada " << model << endl;
- }
- };
- class Honda : public Car{
- public:
- Honda(string model):Car(model){
- }
- virtual ~Honda(){
- cout <<"Honda " << model << endl;
- }
- };
- class Mazda : public Car{
- public:
- Mazda(string model):Car(model){
- }
- virtual ~Mazda(){
- cout <<"Mazda " << model << endl;
- }
- };
- void delet(vector <Car*> &vect){
- for (int i = 0; i < vect.size(); i++)
- delete vect[i];
- vect.clear();
- }
- int main() {
- ifstream fin("cars.txt");
- string marka, model;
- vector <Car*> cars;
- int i = 0;
- while (fin >> marka) {
- fin >> model;
- ++i;
- if (marka == "Porshe") {
- cars.push_back(new Porshe(model));
- } else
- if (marka == "Lada") {
- cars.push_back(new Lada(model));
- } else
- if (marka == "Honda") {
- cars.push_back(new Honda(model));
- } else
- if (marka == "Mazda") {
- cars.push_back(new Mazda(model));
- } else
- cout << "Wrong car name line "<<i <<endl;
- }
- delet(cars);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement