|
ex3-11d.cpp - Example 3-11 Multi-file application - deck source file |
// File: ex3-11d.cpp - deck class member function definitions
#include <iostream>
#include <cstdlib> // needed for rand() function
using namespace std;
#include "ex3_11d.h"
void deck::create_deck(void)
{
for (int i = 0; i < 52; i++) d[i].assign(i);
next_card = 0;
return;
}
void deck::shuffle(void)
{
int i, k;
card temp;
cout << "I am shuffling the deck\n";
for (i = 0; i < 52; i++)
{
k = rand() % 52;
temp = d[i];
d[i] = d[k];
d[k] = temp;
}
return;
}
void deck::print(void) const
{
cout << "\nHere's the deck:\n";
for (int i = 0; i < 52; i++) d[i].print();
return;
}
void deck::deal(int no_of_cards)
{
cout <<"\nOk, I will deal you "<<no_of_cards<<" cards:\n";
for (int i = 0;i<no_of_cards; i++) d[next_card++].print();
return;
}
CIS27: Programming in C++ Instructor: Joe Bentley