#include <iostream>
#include <cstdlib>
#include <vector>
#include <ctime> // Include <ctime> for srand() and rand() functions

using namespace std;

// Define a Card class
class Card {
public:
    Card(string val, string su) : value(val), suit(su) {} // Constructor to initialize value and suit
    string getValue() const { return value; } // Getter for value
    string getSuit() const { return suit; } // Getter for suit
private:
    string value;
    string suit;
};

int main() {
    // Seed the random number generator
    srand(static_cast<unsigned int>(time(nullptr)));

    // Create a vector of Card objects
    vector<Card> deck;
    deck.push_back(Card("Ace", "Spades"));
    deck.push_back(Card("9", "Hearts"));
    deck.push_back(Card("Queen", "Diamonds"));
    deck.push_back(Card("6", "Clubs"));

    // Shuffle the deck
    const int SHUFFLES = 10;
    for (int i = 0; i < SHUFFLES; i++) {
        int from = rand() % deck.size();
        int to = rand() % deck.size();

        // Swap two Card objects
        swap(deck[from], deck[to]);
    }

    // Print the shuffled deck
    for (const auto& card : deck) {
        // Print a Card object using its member functions
        cout << card.getValue() << " of " << card.getSuit() << endl;
    }

    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: