// Map.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include #include #include #include #include using namespace std; class Person { private: string firstname; string lastname; int age; public: Person(string fname, string lname, int a) :firstname(fname), lastname(lname), age(a) {}; virtual ~Person() {}; // shoud be virtual string GetName() const { return firstname + " " + lastname; }; int GetAge() const { return age; }; void SetName(string const& first, string const& last) { firstname = first; lastname = last; }; void SetAge(int const& newage) { age = newage; }; virtual void Say() { cout << "I am a person and my name is " << GetName() << endl; } }; class Customer : public Person { private: int id; public: Customer(string fname, string lname, int a, int ID) : Person(fname, lname, a), id(ID) {}; void Say() { cout << "I am a customer of your Bank and my name is " << GetName() << endl; //try protected }; }; class BankAccount { private: string id; public: BankAccount(string ID) :id(ID) {}; void SetID(string const &ID) { id = ID; }; string GetID() const { return id; }; virtual void CalculateFees() {}; }; int main() { Customer c1("Julia", "Lee", 28, 1); Customer c2("Kate", "London", 21, 2); Customer c3("John", "London", 22, 3); map customers; //initializing map //customers[1] = c1; //adding using the squared brackets only in case of default constructor //customers[3] = c2; pair p1(1, c1); //adding using the pairs pair p2(2, c2); pair p3(3, c3); customers.insert(p1); customers.insert(p2); customers.insert(p3); for (auto ip = customers.begin(); ip != customers.end(); ip++) { cout << "Number " << ip->first << " Name " << ip->second.GetName() << endl; //sorted } auto found = customers.find(2); cout << "Found Name " << found->second.GetName() << endl; //map ba;//will not work as the operator overloading for < is not defined map ba; BankAccount ba1("123"); BankAccount ba2("124"); //std::pair pa1(c1, ba1); pair pa1("1", ba1); pair pa2("2", ba2); ba.insert(pa1); ba.insert(pa2); system("pause"); return 0; }