Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using namespace std;
- #include "Pile.h"
- #include <iomanip>
- #include <algorithm> //shuffle
- #include <sstream>
- #include <stdexcept>
- #include <cstdlib>
- Pile::Pile()
- {
- p = vector<Card>();
- }
- //draws card from the top of the pile and removes it from the vector
- Card Pile:: dealCard()
- {
- if(p.size() > 0)
- {
- Card tempCard = p.front();
- p.erase(p.begin());
- return tempCard;
- }
- else
- throw std::length_error("Pile is empty");
- }
- int Pile:: getCount() const
- {
- return p.size();
- }
- void Pile:: shuffle()
- {
- random_shuffle(p.begin(), p.end());
- }
- void Pile:: clear()
- {
- p.clear();
- }
- Pile Pile:: operator + (const Card& c) const
- {
- Pile tempPile; //make a copy of the pile to be returned
- tempPile.p = p;
- tempPile.p.push_back(c); //push the new card onto the end of the pile
- return tempPile; //return the new pile
- }
- Pile Pile:: operator + (Pile& b)
- {
- Pile tempPile;
- tempPile.p = p;
- while(b.p.size() > 0)
- {
- tempPile.p.push_back(b.p.front());
- b.p.erase(b.p.begin());
- }
- return tempPile;
- }
- ostream& operator << (ostream& out, const Pile& b)
- {
- int count = 0;
- int index = 0;
- int max = b.getCount();
- for(int i = 0; i < max; i++)
- {
- out << b.p[index] << setw(2);
- count++;
- index++;
- if(count == 10)
- {
- out << endl;
- count = 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement