I\'ve finished up with the Card.h i believe. :-). im having trouble with the res
ID: 3634188 • Letter: I
Question
I've finished up with the Card.h i believe. :-). im having trouble with the rest. Below are rest of the instructions i wasn't able to finish up.1. Create a deck of cards. you can use one of the container class to model the deck. eg. vector<card>deck1.
ive create the deck already but im not sure if its correct.
2. Initialize the deck. add all the possible cards into the deck. this can be done by exhaustion or by using nested loop to set the suit, value, and points for the cards. Hint: the character values for the various card suits are 3,4,5, and 6
3. shuffle your deck. use the random shuffle function from the algorithms library to randomize the deck
4. create two hands of cards. use different container class to make two hands of cards. one for the player and one for the computer
4. print out the hands. declaring an iterator for the set and use it to print out the cards in each hand.
________________Card.h_________
//Card Class
#include
#include
using namespace std;
#ifndef CARD_H
#define CARD_H
class Card
{
public:
//accessor
int get_value(){return value;}
char get_type(){return type;}
char get_suit(){return suit;}
//mutator
void set_value(char v){value = v;}
void set_type(char t){type = t;}
void set_suit(char s){suit = s;}
Card(char t, char s, int v); //overloaded constructor
Card(); //default constructor
friend ostream operator << (ostream& outs, Card& what); //friend function
private:
int value;
char type;
char suit;
};
Card::Card()
{
value = '13';
type = 'T';
suit = 'S';
}
Card::Card(char t, char s, int v)
{
t = type;
s = suit;
v = value;
}
#endif
_____Main.cpp_____
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<ctime>
#include"Card.h"
using namespace std;
int main()
{
//creates deck
vector <string> deck;
add(deck, "Hearts");
add(deck, "Clubs");
add(deck, "Spades");
add(deck, "Diamonds");
Explanation / Answer
main.cpp // cardplay-1/main.cpp -- Very simple program to deal cards. // Fred Swartz 2004-11-22 // Summary: Reads a number and then "deals" that many cards. // Illustrates: Random methods (strand and rand). #include #include #include #include using namespace std; #include "card.h" #include "deck.h" int main() { int numOfCards; // Input number for how many cards to deal. srand(time(0)); // Initializes random "seed". Deck deck; while (cin >> numOfCards) { deck.shuffle(); coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.