Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Interfaces.h"
- #include <string>
- #include <iostream>
- #include <fstream>
- #include <sstream>
- #include <algorithm>
- using namespace std;
- class myObject
- {
- string description;
- public:
- myObject(string s) : description(s)
- {
- }
- virtual ~myObject()
- {
- }
- virtual void print() = 0;
- string operator*() { return description; }
- };
- class Book: public myObject
- {
- public:
- Book() : myObject(" ")
- {
- }
- Book(string s):myObject(s)
- {
- }
- virtual ~Book()
- {
- }
- virtual void print()
- {
- cout<<this<<endl;
- }
- };
- class Passenger : public myObject
- {
- public:
- Passenger() :myObject(" ")
- {
- }
- Passenger(string s) : myObject(s)
- {
- }
- virtual ~Passenger()
- {
- }
- virtual void print()
- {
- cout<<this<<endl;
- }
- };
- template <typename T>
- class Container : public myObject
- {
- T* objects;
- int size;
- public:
- Container(int i) : size(i)
- {
- objects = new T[size];
- }
- ~Container()
- {
- delete[] objects;
- }
- void initializeBook(string s, int i)
- {
- objects[i] = Book(s);
- }
- void initializePassenger(string s, int i)
- {
- objects[i] = Passenger(s);
- }
- void print()
- {
- for(int i=0; i <size;i++)
- {
- cout<<*objects[i]<<endl;
- }
- }
- };
- int main()
- {
- int numBooks = 0;
- int numPassengers = 0;
- ifstream in("Airline.csv");
- if ( in.fail()){
- cout<<"failed to open"<< endl;
- }
- string line;
- while(getline(in,line))
- {
- numPassengers++;
- }
- in.close();
- in.clear();
- in.open("Books.csv");
- if ( in.fail()){
- cout<<"failed to open 2"<< endl;
- }
- while(getline(in,line))
- {
- numBooks++;
- }
- in.clear();
- in.seekg(0,ios::beg);
- Container<Book> bookContainer(numBooks);
- if(in.is_open())
- {
- int i = 0;
- while(getline(in,line))
- {
- replace( line.begin(), line.end(), ',', ' ');
- bookContainer.initializeBook(line,i);
- i++;
- }
- }
- in.close();
- in.clear();
- in.open("Airline.csv");
- Container<Passenger> passengerContainer(numPassengers);
- if(in.is_open())
- {
- int i = 0;
- while(getline(in,line))
- {
- replace( line.begin(), line.end(), ',', ' ');
- passengerContainer.initializePassenger(line,i);
- i++;
- }
- }
- bookContainer.print();
- passengerContainer.print();
- in.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement