All pastes #911985 Raw Edit

Stuff

public cpp v1 · immutable
·published 2008-02-21 01:32 UTC
rendered paste body
// Jonathan Chan// CIS15 MY9 Prof. Sokol// Assignment 2 - WAR!#include <string>#include <sstream>#include <iostream>using namespace std;// Defines a SINGLE card!class card {    string card_center(string);    public:        int value;        string face;        // s=spade, h=heart, d=diamond, c=club, '\0'=no suit        char suit;        card(int value, string face, char suit='\0');        // functions        string display_card(int mode=1);};// either outputs the card value or a graphic of the card!string card::display_card(int mode) {            stringstream out;            if (mode==1) {                out << this->face << "-" << this->suit;            } else {                out << ".-------.\n";                if (this->suit == 's')                     out << "|   *   |\n"                         << "| *   * |\n"                        << "|*     *|\n"                        << "|  *I*  |\n";                else if (this->suit=='d')                    out << "|  / \\  |\n"                        << "| /   \\ |\n"                        << "| \\   / |\n"                        << "|  \\ /  |\n";                else if (this->suit=='c')                    out << "|   _   |\n"                        << "| _( )_ |\n"                        << "|(_ . _)|\n"                        << "|   I   |\n";                else if (this->suit=='h')                    out << "| ** ** |\n"                        << "|*  *  *|\n"                        << "| *   * |\n"                        << "|   *   |\n";                else                     out << "|       |\n"                        << "|       |\n"                        << "|       |\n"                        << "|       |\n";                out << card_center(face);                out << "'-------'";            }            return out.str();        }// Centers the card face on the cardstring card::card_center(string face) {    if (face.length() > 7)        face=face.substr(0,7);    if (face.length() % 2 == 0)         face=face.substr(0,face.length()/2)+" "+face.substr(face.length()/2);    string space;    for (int i=0;i<(7-face.length())/2;i++) {        space+=' ';    }    face="|"+space+face+space+"|\n";    return face;}card::card(int value, string face, char suit) {    this->value=value;    this->face=face;    this->suit=suit;;}class deck {    card *cards;    unsigned short int _size;    public:        static bool use_jokers;        static unsigned short int size;        deck(unsigned short int);        // prints entire content of deck        void debug();};// Static Variablesbool deck::use_jokers=false;deck::deck(unsigned short int size=65535) {    if (deck::use_jokers) deck::size=54;    if (size != 65535) deck::size=size;    cards=new card[deck::size];    for(int i=0;i<deck::size;i++)        cards[i]=0;    _size=deck::size;}void deck::debug() {    cout << " { "<< cards[0];    for (int i=1;i<_size;i++)        cout << " , " << cards[i];    cout << " } ";}int main () {    card ace(24,"King");    cout << ace.value << ace.face << ace.suit << endl;    cout << ace.display_card() << endl;    cout << ace.display_card(2) << endl;    deck dealer;}/*and the errors....main.cpp: In constructor 'deck::deck(short unsigned int)':main.cpp:102: error: no matching function for call to 'card::card()'main.cpp:75: note: candidates are: card::card(int, std::string, char)main.cpp:11: note:                 card::card(const card&)main.cpp:104: error: no match for 'operator=' in '*(((deck*)this)->deck::cards + ((card*)(((unsigned int)i) * 12u))) = 0'main.cpp:11: note: candidates are: card& card::operator=(const card&)main.cpp: In member function 'void deck::debug()':*/