Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7533421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:43:13+00:00 2026-05-30T05:43:13+00:00

#include <iostream> #include <string.h> #include <iomanip> #include <cstring> #include <cassert> using namespace std; #ifndef

  • 0
#include <iostream>
#include <string.h>
#include <iomanip>
#include <cstring>
#include <cassert>
using namespace std;

#ifndef _TYPE_H
#define _TYPE_H

enum CardSuitType {DIAMOND,HEART,CLUB,SPADE};//enum for the suit type

struct card // creates the structure for cards
{
    CardSuitType suit; //declares suit type
    int numValue; // numerical value of the card
    int pointValue; // point value of the card
};

const int DECK_SIZE = 52;//constant for the max size of the deck
const int HAND_SIZE = 13;//constant for the max size of hand


#endif  /* _TYPE_H */

#include “type.h”

#ifndef _CARDCLASS_H
#define _CARDCLASS_H

class CardClass {
public:
    CardClass();//default constructor

    void ShuffleCards();//shuffles the deck
    card DealCards();//deals one card to whoever calls the function
    void Print();//Prints the deck of cards


private:
    card deck[DECK_SIZE]; //initial deck
    int cardsLeft; //cards left in deck

};

#endif  /* _CARDCLASS_H */

//////start CardClass.cpp


#include "CardClass.h"
#include <stdio.h>
#include <stdlib.h>


//Default Constructor for the Card Class
//Creates a deck of 52 cards 13 of each suit
CardClass::CardClass()
{
    cardsLeft = 52;
   for(int i = 0; i <= 12; i++)//sets all the diamond cards
    {
        deck[i].numValue = i+1;
        deck[i].pointValue = 0;
        deck[i].suit = DIAMOND;
    }
    for(int i = 13; i <=25; i++)//sets the club cards
    {
        deck[i].numValue = i-12;
        if(i-12 == 10)//checks for jack of clubs
            deck[i].pointValue = -100;
        else//for all other cards
            deck[i].pointValue = 0;
        deck[i].suit = CLUB;
    }
    for(int i = 26; i <= 38; i++)//sets all the heart cards
    {
        deck[i].numValue = i-25;
        if(i-25 < 10)//checks for card value less than 10
            deck[i].pointValue = 5;
        else//checks for 10, jack, queen, king
            deck[i].pointValue = 10;
        deck[i].suit = HEART;
    }
    for(int i = 39; i <= 51; i++)//sets the spade cards
    {
        deck[i].numValue = i-38;
        if(i-38 == 11)//checks for jack of spades
            deck[i].pointValue = 100;
        else//for all other cards
            deck[i].pointValue = 0;
        deck[i].suit = SPADE;
    }


}

/*
 * ShuffleCards: Shuffles the deck of cards in a random order.
 * Precondition: An object of CardClass has been constructed
 * Postcondition: The deck of cards is shuffled.
 *
 */
void CardClass::ShuffleCards()
{

    card temp;
    for(int i = 0; i < DECK_SIZE; i++)//goes through the deck and swaps with a random card
    {
        int random = rand() %DECK_SIZE;
        temp = deck[i];
        deck[i] = deck[random];
        deck[random] = temp;
    }
}

/*
 * DealCards: Deals a card to a user
 * Precondition: deck has been initialized
 * Postcondition: a card is "dealt" (returned) to the caller
 */
card CardClass::DealCards()
{
    cardsLeft--;
    return deck[cardsLeft];
}

/*
 * Print: Prints the deck in a tabled format
 * Precondition: deck has been initialized
 * Postcondition: the contents of the deck are outputted
 *                  on the screen
 */

void CardClass::Print()
{

    //output the table head
    cout << setw(20) << left << "Suit Type"
         << setw(20) << right << "Number Value"
         << setw(20) << right << "Point Value"
         << endl;

    //output the cards
    for(int i = 0; i < DECK_SIZE; i++)//moves through the hand
    {
      string value = " ";//string for Face cards
      string suit[4] = {"Diamond", "Heart","Club", "Spades"};//String for suit values
      string num[13] = {"A","2","3","4","5","6","7","8","9", "10", "Jack","Queen","King"};

        //output deck in tabular format.
         cout << setw(20) << fixed << left << suit[deck[i].suit]
             << setw(20) << fixed << right << num[deck[i].numValue]
             << setw(20) << fixed << right << deck[i].pointValue
                << endl;





    }
}
///////start main.cpp



#include <stdlib.h>
#include <cassert>
#include <fstream>
#include <cstring>
#include <time.h>
#include "CardClass.h"
#include "PlayerClass.h"
using namespace std;

/*
 *
 */
int main(int argc, char** argv)
{

    srand(time(0));//primes random

    CardClass deck;//local deck of cards
    PlayerClass player[4];//array or players to be dealt

    deck.ShuffleCards();//shuffles the deck
    deck.Print();//prints the deck
    for(int i = 0; i < DECK_SIZE; i++)//goes through deck
    {
        player[i%4].AddACard(deck.DealCards());//adds cards to a player's hand
    }
    for(int i = 0; i < 4; i++)//goes through array of players
    {

        player[i].SortCard();//sorts the hand of the player
    }
    for(int i = 0; i < 4; i++)//goes through array of players
    {
       cout << endl << endl//prints player hand information.
            << "Player "<< i+1 << endl
             << player[i];
    }



    return (0);
}

It compiles and outputs completely fine in both Windows and the Debian client I am required to use for school, but I much prefer to develop in ubuntu.

It outputs

Suit Type                   Number Value         Point Value
Heart                                  6                   5
Spades                              King                   0
Spades                                 7                   0

> Club                                   2                   0 Heart    
> 8                   5 Spades                                 6        
> 0 Spades                                10                   0 Diamond
> Jack                   0 Club                                   5     
> 0 Club                                King                   0 Diamond
> King                   0 Club                                   6     
> 0 Heart                               Jack                  10 Diamond
> 5                   0 Spades                             Queen        
> 100 Diamond                            Queen                   0
> Spades                                 8                   0 Heart    
> 10                   5 Club                                   7       
> 0 Diamond                                6                   0 Diamond
> 10                   0 Spades                              Jack       
> 0 Spades                                 2                   0 Club   
> 8                   0 ��5���d             �=; 6t�� ��5��HcD$
>          H���H�=��5H�����:
>                            H��4���H�=j�5H���;
>                                               H��G���H�=K�5H�����:
>                                                                    H��g���H�=,�5H�����: �5H�����:������H�=
>          H������H�=��5H�����:
>                               H������H�=��5H����C:
>                                                    H������H�=��5H����T:
>                                                                         H�Ā�����zLc҅�H�O�VF�D�F��D�FD�V
> t/�?����A����)�Hc�H��H�B�����A��Hc�H��H�Mc�H�NJ��H�F(1�DH�H)�H������V���H���5d�������fff.�H��t{H��tv�WH�O��tKH�L�L�O(�A�H����I9щI�@vI9�H�HF�H�1��H��H�1�H��i�mN�A90%�����1��H�A�5d�������fff.�USH��H��H����V���������L�F���E�1���A���nHc�H��~M�A�_
>                                                                             N���A���������)�i�����i��)�iɧAȍ�����I�A�
>                                             �H��H9�|�HcC �l�L��l-�I��H�1���x@H�t$
>       H�߃���������u�1�H��[]ø�����H�\$�H�l$�H��L�d$�H��(H��!H�AH��t�q����@

When I use the debugger it is all put onto the screen during deck.Print();

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T05:43:14+00:00Added an answer on May 30, 2026 at 5:43 am

    Your deck numbers start from 1 and you’re referencing the num array from 0. So an i of 12 in

    for(int i = 0; i <= 12; i++)//sets all the diamond cards
    {
        deck[i].numValue = i+1;
        deck[i].pointValue = 0;
        deck[i].suit = DIAMOND;
    }
    

    Gives a numValue of 13 and your num array only goes to index 12. num[deck[i].numValue] should be num[deck[i].numValue - 1].

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include <iostream> #include <string> #include <fstream> using namespace std ; string strWord( int index
#include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; int main(void) {
Here's my code so far: #include<iostream> #include<string> #include<fstream> using namespace std; int main() {
New code.... #include <cstdlib> #include <iostream> #include <fstream> #include <iomanip> using namespace std; void
#include <iostream> using namespace std; template<class T> void toBinary(T num) { char * numi
Please take a look at this example: #include <iostream> #include <vector> #include <string> using
I have the following code: #include <iostream> #include <string> #include <iomanip> #include <locale> #include
// Huffman Tree.cpp #include stdafx.h #include <iostream> #include <string>//Necessary to do any string comparisons
How print format string passed as argument ? example.cpp: #include <iostream> int main(int ac,
I'm working this source code: #include <string> #include <vector> #include <iostream> #include <istream> #include

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.