#include <fstream>
#include <string>  

class Account
{
private: 
  string id;
  double balance;
  
public:
  Account (const string &d)
  {	
    id=d;
    balance=0;		
  }	
  
  const string getID()
  {
    return id;
  }
  
  const double getBalance()
  {
    return balance;
  }
  
  void setBalance(double b)
  {
    balance=b;
  }
  
  void deposit(int x)
  {
    if(x>0)
      balance+=x;
  }
  
  bool withdraw(int x)
  {
    if (balance>=x && x>0)
      {
	balance-=x;
	return true;
      }
    return false;
  }
    
  bool operator==(Account &b)const
  { 
    if(id.compare(b.getID())==0)
      return true;
    return false;
  }

  friend bool operator<(const Account &a,const Account &b)
  {
    if (a.balance<b.balance)
      return true;
    return false;
  }

  void outputTo(ofstream filename) {
   // prints member functions out to file
  filename << id << "       " << balance << endl;
  }
  string input string
  void inputFrom(ifstream filename) {
   getline(filename, inputstring);
  }  
};//end class Account

int main() {

 string ID;
 double balance;
 int choice = 0;
 string filename;
 
 cout << "Use and existing file or create new one. Supply filename: ";
 cin >> filename;
 
 if (!filename) {
 // case they want to use a existing file
 ifstream file (filename.c_str());
 inputFrom(filename.c_str());
 }
 else {
 
 // case they want to create new one
 ofstream file (filename.c_str());
 
 // prompt for account information
 char choice = 'Y';
 while((choice == 'Y') || (choice == 'y')) {
 cout << "Enter your new account ID and balance: ";
 cin >> ID >> balance;
 Account bob(ID,balance);
 cout << "Would you like to add another account? Y/N" << endl;
 bob.outputTo(filename.c_str());
 cin >> choice;
 } // end of while loop
 
 } // end ofelse statement
} // end of main class
