Please provide full answer with comments me to better understand this is beginni
ID: 3845674 • Letter: P
Question
Please provide full answer with comments me to better understand this is beginning of c++ so don't use advanced techniques thank you
main.cpp
#include <iostream>
#include "card.h"
#include "deck.h"
#include "hand.h"
#include <ctime>
using namespace std;
int main() {
card c1(13,'D');
cout << c1.read() << endl;
deck d1;
//d1.shuffle();
d1.print_deck();
cout << d1.deal().read() << endl;
cout << d1.deal().read() << endl;
cout << d1.deal().read() << endl;
cout << d1.deal().read() << endl;
hand h1;
h1.c1 = card(13,'D');
h1.c2 = card(11, 'D');
hand h2;
h2.c1 = card(13, 'S');
h2.c2 = card(11, 'S');
cout << (h1 < h2) << endl;
cout << (h1 > h2) << endl;
cout << (h1 == h2) << endl;
}
card.h
#pragma once
#include <string>
using namespace std;
class card {
int num;
char suit; //there are 4 suits: C D H S
public:
void setNum(int n);
void setSuit(char s);
int getNum();
char getSuit();
string read();
card();
card(int n, char s);
};
deck.h
#pragma once
#include "card.h"
class deck {
private:
card stack[52];
int deal_count;
public:
deck();
void print_deck();
void shuffle();
card deal();
int stack_size();
void gather_and_shuffle();
};
hand.h
#pragma once
#include "card.h"
class hand {
public:
card c1, c2;
bool operator<(hand rhs);
bool operator>(hand rhs);
bool operator<=(hand rhs);
bool operator>=(hand rhs);
bool operator==(hand rhs);
};
shuffle.h
#include <chrono>
#define SEED_MACRO chrono::system_clock::now().time_since_epoch().count()
deck.cpp
#include <iostream>
#include <algorithm>
#include <random>
#include <cassert>
#include "deck.h"
#include "shuffle.h"
using namespace std;
//Do not change this function
void deck::shuffle() {
assert(deal_count == 0);
std::default_random_engine eng(SEED_MACRO);
std::shuffle(stack, stack + 52, eng);
}
void deck::print_deck() {
for (int i = 0; i < 52; i++)
cout << stack[i].read() << endl;
}
Explanation / Answer
main.cpp
#include <iostream>
#include "card.h"
#include "deck.h"
#include "hand.h"
#include <ctime>
using namespace std;
int main() {
card c1(13,'D');
cout << c1.read() << endl;
deck d1;
//d1.shuffle();
d1.print_deck();
cout << d1.deal().read() << endl;
cout << d1.deal().read() << endl;
cout << d1.deal().read() << endl;
cout << d1.deal().read() << endl;
hand h1;
h1.c1 = card(13,'D');
h1.c2 = card(11, 'D');
hand h2;
h2.c1 = card(13, 'S');
h2.c2 = card(11, 'S');
cout << (h1 < h2) << endl;
cout << (h1 > h2) << endl;
cout << (h1 == h2) << endl;
}
card.h
#pragma once
#include <string>
using namespace std;
class card {
int num;
char suit; //there are 4 suits: C D H S
public:
void setNum(int n);
void setSuit(char s);
int getNum();
char getSuit();
string read();
card();
card(int n, char s);
};
deck.h
#pragma once
#include "card.h"
class deck {
private:
card stack[52];
int deal_count;
public:
deck();
void print_deck();
void shuffle();
card deal();
int stack_size();
void gather_and_shuffle();
};
hand.h
#pragma once
#include "card.h"
class hand {
public:
card c1, c2;
bool operator<(hand rhs);
bool operator>(hand rhs);
bool operator<=(hand rhs);
bool operator>=(hand rhs);
bool operator==(hand rhs);
};
shuffle.h
#include <chrono>
#define SEED_MACRO chrono::system_clock::now().time_since_epoch().count()
deck.cpp
#include <iostream>
#include <algorithm>
#include <random>
#include <cassert>
#include "deck.h"
#include "shuffle.h"
using namespace std;
//Do not change this function
void deck::shuffle() {
assert(deal_count == 0);
std::default_random_engine eng(SEED_MACRO);
std::shuffle(stack, stack + 52, eng);
}
void deck::print_deck() {
for (int i = 0; i < 52; i++)
cout << stack[i].read() << endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.