Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help with this program here is the problem: Write a C++ program which wil

ID: 3623659 • Letter: I

Question

I need help with this program here is the problem:
Write a C++ program which will play a card game called “Hearts”. Hearts is a trick taking game
in which the objective is to avoid winning tricks containing hearts; the queen of spades is even
more to be avoided.
The program plays “Hearts” with four players: computer 1, computer 2, computer 3, and the user.
The winner of the game is the person who has the lowest number of points after the game is over.
Points in the game are calculated as follows: each card of suit HEART has points: those with
face value less than 10 is worth 5 points, and the rest of the HEART cards worth 10 points. In
addition, the Queen of Spades worth 100 points, the Club of Jack worth -100 points.
Each player is dealt 13 cards at the beginning of the game. The person who holds the 2 of CLUB
must lead it to the first trick. The suit on the first card played on each hand is called the leading
suit for that hand. Then, the remaining three players must each play a card of the same suit if they
have one. If not, they can play a card from any other suit. For each hand, the player with the
highest valued card of the leading suit must collect the points. Then, this player must begin the
next round in a similar fashion with a new leading suit. Therefore, 13 different “hands” will be
played. The game is over after all 13 hands have been played.
Your program simulates this game by showing the user’s cards at the beginning of each round (in
a nice form such that the user can view all his or her remaining cards easily). At each round, your
program must display the cards played by each player, and show points accumulated for each
player, and indicate who will lead the next hand.
The strategy for card selection can be different between the user and the three computers. The
user may select any card to start a new round of game when it is his or her turn, or select an
appropriate card of the required suit from his remaining cards. For the three computers, when it is
their turn to start the hand, they will always select the card at the top of the remaining card list.
When they are not leading a hand, they always select the first available card that meets the suit
requirement.
Your program must create a class called "CardClass". The data member of this class will be the
deck of cards implemented in terms of an array of structs of size 52. The class should at least
include the following member functions:
1. Default constructor -- which creates the deck of cards by assigning appropriate suit, value,
and points for each card. A deck of cards contains four suits: Hearts, Diamonds, Spades, and
Clubs. The cards are listed in order of their rankings: Ace, King, Queen, Jack, 10, 9, 8, 7, 6,
5, 4, 3, 2. This corresponds to the FormCards function in OLA2.
2. ShuffleCard. This corresponds to the ShuffleCards function in OLA2.
3. DealCard. This method deals out (returns) one card only, it should also decrement the
number of cards remaining in the deck by one.
2
Part 1 (100 points)
Implement a CardClass, including the header file and the implementation file for the class. Make
sure to include detailed description (description, pre-condition, post-condition) of each
method in the class in the header file.
Your CardClass should include:
(i) number of cards remaining in deck. (This variable keeps track of how many cards
remain in the deck).
(ii) the deck of cards, i.e., an array of card struct type.
Your CardClass methods should include:
(i) default constructor that creates the deck of cards – assign values to each card in
the deck;
(ii) shuffle the cards,
(iii) deal card.
Write a client program, heartsA.cc, that :
(i) creates an object of CardClass;
(ii) deals cards to 4 players (2-D array of cardType, same as in OLA 2)
(iii) sort each player’s cards
(iv) displays the cards for each of the 4 players.
This program should be very similar to the main function in the program you have in OLA2.


I have completed the program before this this program is a little bit different we can use couple of these function from the provious program I'm attaching to this assignment.

#include <iostream>
#include <string>
#include <ctime>
#include<stdlib.h>

using namespace std;
// enum declaration for cardsuit.
enum CardSuit{
DIAMOND, //suits decleration
CLUB,
HEART,
SPADE
};
//struct declaration
struct card{
CardSuit suit; //suit declaration of cardSuit type.
int value; //holds value of card.
int point; //holds point's value for selected cards
};

//prototyp declarations

//pre-condition:deck of cards[52]
//post-condition:face<10=5
// HEART of 10= 10
// SPADE=100
// CLUB= -100
// REST OF CARDS= 0
void formCards(card deck[]);


//pre-condition:deck of card array[52]
//Post-condition:shuffles the cards randomely
void shuffleCards(card deck[]);


//pre-condition:2-D array of struct ,ShuffleCards function
// size: rows==4, columns==13
//post-condition: deals out shuffled cards to 4 players
void dealCards(card deck[], card player[][13]);


//pre-condition:player's cards
//post-condition: sorting each player's card by suit
void sortCards(card player[][13]);


//pre-condition: functions:formcard,shufflecards,dealcards,sortcards
//post-condition: diplay cards of one player in sorted order,
// value and points for each player.
void printCards(card player[][13]);

int main ()
{

card deck[52]; //deck
card player[4][13]; //player's cards

formCards(deck); //function call
shuffleCards(deck); //function call
dealCards(deck, player); //function call
sortCards(player); //function call
printCards(player); //function call

getchar();

return 0;
}

//function definition
//pre-condition:deck of cards[52]
//post-condition:face<10=5
// HEART of 10= 10
// SPADE=100
// CLUB= -100
// REST OF CARDS= 0
void formCards(card deck[]){

//form deck loop
for(int i = 0; i < 52; i++){
switch(i / 13){
case 0: deck[i].suit = DIAMOND; break;
case 1: deck[i].suit = CLUB; break;
case 2: deck[i].suit = HEART; break;
case 3: deck[i].suit = SPADE; break;
}
deck[i].value = i % 13;
}

//evaluate points loop
for(int i = 0; i < 52; i++){
switch(deck[i].suit){
case DIAMOND:
deck[i].point = 0;
break;
case CLUB:
if(deck[i].value == 10) //equals jack
deck[i].point = -100;
else
deck[i].point = 0;
break;
case HEART:
if(deck[i].value < 9) //less then 10
deck[i].point = 5;
else
deck[i].point = 10;
break;
case SPADE:
if(deck[i].value == 11) //equals queen
deck[i].point = 100;
else
deck[i].point = 0;
break;
}
}

return;
}
//function definition
//pre-condition:deck of card array[52]
//Post-condition:shuffles the cards randomely
void shuffleCards(card deck[]){
int j;

srand(time(NULL)); //initilize to 0,NULL

//loop for random select
for(int i = 0; i < 52; i++){
j = i + rand()%(52 - i);

card temp = deck[i];
deck[i] = deck[j];
deck[j] = temp;

}
}
//function definition
//pre-condition:2-D array of struct ,ShuffleCards function
// size: rows==4, columns==13
//post-condition: deals out shuffled cards to 4 players
void dealCards(card deck[], card player[][13]){
int i, j, k = 0;

//for loop to store shuffled cards in 2-D array
for(i = 0; i < 4; i++)
for(j = 0; j < 13; j++)
player[i][j]=deck[k++];

return;
}
//function definition
//pre-condition: functions:formcard,shufflecards,dealcards,sortcards
//post-condition: diplay cards of one player in sorted order,
// value and points for each player.
void sortCards(card player[][13]){
int c, d; //declearing rows and columns variables
card t;

//for loop for sorting cards for the 4 players.
for(int n = 0; n < 4; n++)
for(c=0;c<12;c++)
for(d=c;d<13;d++)
if(player[n][c].suit>player[n][d].suit){
t=player[n][c];
player[n][c]=player[n][d];
player[n][d]=t;
}
}
//function definition
//pre-condition: functions:formcard,shufflecards,dealcards,sortcards
//post-condition: diplay cards of one player in sorted order,
// value and points for each player.
void printCards(card player[][13]){
string suit[4]={"diamonds","clubs","hearts","spades"};
string card[13]={"ace","2","3","4","5","6","7","8","9","10","jack","queen","king"};

//to display each of the 4 players hands
for(int n = 0; n < 4; n++){
cout<<"***********************"<<endl<<endl;
cout<<"-----------------------"<<endl;
cout<<"Player "<< n+1 <<" hand " << endl;
cout<<"-----------------------"<<endl;

cout<<"Card Points Suit" << endl;

//diplaying cards points and suits
for(int i = 0; i < 13; i++)
cout << card[player[n][i].value] << " "
<< player[n][i].point << " "
<< suit[player[n][i].suit] << endl;
}

cout<<endl<<endl;
}

Explanation / Answer

please rate - thanks

#include <iostream>
#include <string>
#include <ctime>
#include<stdlib.h>

using namespace std;

// enum declaration for cardsuit.
enum CardSuit{
DIAMOND, //suits decleration
CLUB,
HEART,
SPADE
};
//struct declaration
struct card{
CardSuit suit; //suit declaration of cardSuit type.
int value; //holds value of card.
int point; //holds point's value for selected cards
};
class CardClass{
      private: int cards;
               card deck[52]; //deck
public:
       CardClass();
       int score(card player[][13] );
       void computer(card player[][13],int,int,int[],bool);
       void user(card player[][13],int,int,int[],bool);
       int findStart(card player[][13],int&);
       void movecards(card[][13],int,int);
       int getCards();
        //prototyp declarations

        //pre-condition:deck of cards[52]
        //post-condition:face<10=5
        // HEART of 10= 10
        // SPADE=100
        // CLUB= -100
        // REST OF CARDS= 0
        void formCards( );


        //pre-condition:deck of card array[52]
        //Post-condition:shuffles the cards randomely
        void shuffleCards( );


        //pre-condition:2-D array of struct ,ShuffleCards function
        // size: rows==4, columns==13
        //post-condition: deals out shuffled cards to 4 players
        void dealCards( card player[][13]);
       
        card dealCard( );

        //pre-condition:player's cards
        //post-condition: sorting each player's card by suit
        void sortCards(card player[][13]);


        //pre-condition: functions:formcard,shufflecards,dealcards,sortcards
        //post-condition: diplay cards of one player in sorted order,
        // value and points for each player.
        void printCards(card player[][13],int[]);

               
                };

int main ()
{string name[4]={"Computer 1","Computer 2","Computer 3","User"};
int score[4]={0,0,0,0};
int cardsInHand[4]={13,13,13,13};
int winner ,i,num;
CardClass game;
card player[4][13]; //player's cards
game.dealCards( player); //function call
game.sortCards(player); //function call
game.printCards(player,cardsInHand); //function call
i=game.findStart(player,num);
if(i<3)
    game.computer(player,i,num,score,true);
else
    game.user(player,i,num,score,true);
while(game.getCards()<52)
    {i=(i+1)%4;
     if(i<3)
        game.computer(player,i,0,score,false);
     else
        game.user(player,i,0,score,false);
      game.printCards(player,cardsInHand); //function call
     }
winner=game.score(player);
cout<<"The winner is "<<name[winner]<<endl;
getchar();

return 0;
}
void CardClass::movecards(card player[][13],int pos,int s)
{
}
int CardClass::score(card player [][13] )
{
}
int CardClass::findStart(card player [][13],int &j )
{int i ;
for(i=0;i<4;i++)
     for(j=0;j<13;j++)
          if(player[i][j].suit==CLUB)
                if(player[i][j].value==2)
                       return i;
}

void CardClass::computer(card player [][13],int n,int pos,int s[],bool first)
{
}
void CardClass::user(card player [][13],int n,int pos,int s[],bool first)
{int num;
if(first)
      {cout<<"You have the 2 of Club so that is what you will play ";
       movecards(player,pos,s[n]);
       }
else
    {cout<<"Enter the card number to play: ";
     cin>>num;
     if(s[n]>1)
         movecards(player,num-1,s[n]);
      }   
s[n]--;          

}
//function definition
//pre-condition:deck of cards[52]
//post-condition:face<10=5
// HEART of 10= 10
// SPADE=100
// CLUB= -100
// REST OF CARDS= 0
void CardClass::formCards(){

//form deck loop
for(int i = 0; i < 52; i++){
switch(i / 13){
case 0: deck[i].suit = DIAMOND; break;
case 1: deck[i].suit = CLUB; break;
case 2: deck[i].suit = HEART; break;
case 3: deck[i].suit = SPADE; break;
}
deck[i].value = i % 13;
}

//evaluate points loop
for(int i = 0; i < 52; i++){
switch(deck[i].suit){
case DIAMOND:
deck[i].point = 0;
break;
case CLUB:
if(deck[i].value == 10) //equals jack
deck[i].point = -100;
else
deck[i].point = 0;
break;
case HEART:
if(deck[i].value < 9) //less then 10
deck[i].point = 5;
else
deck[i].point = 10;
break;
case SPADE:
if(deck[i].value == 11) //equals queen
deck[i].point = 100;
else
deck[i].point = 0;
break;
}
}

return;
}
//function definition
CardClass::CardClass()
{formCards( );
shuffleCards();
cards=52;
}
//pre-condition:deck of card array[52]
//Post-condition:shuffles the cards randomely
void CardClass::shuffleCards( ){
int j;

srand(time(NULL)); //initilize to 0,NULL

//loop for random select
for(int i = 0; i < 52; i++){
j = i + rand()%(52 - i);

card temp = deck[i];
deck[i] = deck[j];
deck[j] = temp;


}
}
//function definition
//pre-condition:2-D array of struct ,ShuffleCards function
// size: rows==4, columns==13
//post-condition: deals out shuffled cards to 4 players
void CardClass::dealCards( card player[][13]){
int i, j, k=0 ;

//for loop to store shuffled cards in 2-D array
for(i = 0; i < 4; i++)
for(j = 0; j < 13; j++)
     {//player[i][j]=deck[k++];
        player[i][j]=dealCard();
     }

return;
}

int CardClass::getCards()
{return cards;
}
card CardClass::dealCard( ){
card one;
> cards--;
return one;
}

//function definition
//pre-condition: functions:formcard,shufflecards,dealcards,sortcards
//post-condition: diplay cards of one player in sorted order,
// value and points for each player.
void CardClass::sortCards(card player[][13]){
int c, d; //declearing rows and columns variables
card t;

//for loop for sorting cards for the 4 players.
for(int n = 0; n < 4; n++)
for(c=0;c<12;c++)
for(d=c;d<13;d++)
if(player[n][c].suit>player[n][d].suit){
t=player[n][c];
player[n][c]=player[n][d];
player[n][d]=t;
}
}
//function definition
//pre-condition: functions:formcard,shufflecards,dealcards,sortcards
//post-condition: diplay cards of one player in sorted order,
// value and points for each player.
void CardClass::printCards(card player[][13],int c[]){
string suit[4]={"diamonds","clubs","hearts","spades"};
string card[13]={"ace","2","3","4","5","6","7","8","9","10","jack","queen","king"};

//to display each of the 4 players hands
for(int n = 0; n < 4; n++){
cout<<"***********************"<<endl<<endl;
cout<<"-----------------------"<<endl;
cout<<"Player "<< n+1 <<" hand " << endl;
cout<<"-----------------------"<<endl;

cout<<" Card Points Suit" << endl;

//diplaying cards points and suits
for(int i = 0; i < c[n]; i++)
cout <<i+1<<". "<< card[player[n][i].value] << " "
<< player[n][i].point << " "
<< suit[player[n][i].suit] << endl;
}

cout<<endl<<endl;
}