Related questions
Main.cpp
#include <iostream>
#include "Deck.h"
int main() {
Deck deck;
deck.shuffle();
std::cout << "WAR Card Game\n\n";
std::cout << "Dealing cards...\n\n";
Card player1Card = deck.Deal();
Card player2Card = deck.Deal();
std::cout << "Player 1's card: ";
player1Card.showCard();
std::cout << std::endl;
std::cout << "Player 2's card: ";
player2Card.showCard();
std::cout << std::endl;
int player1Value = player1Card.getValue();
int player2Value = player2Card.getValue();
if (player1Value > player2Value) {
std::cout << "Player 1 wins!" << std::endl;
} else if (player1Value < player2Value) {
std::cout << "Player 2 wins!" << std::endl;
} else {
std::cout << "It's a tie!" << std::endl;
}
return 0;
}
Card.h
#ifndef CARD_H
#define CARD_H
class Card {
public:
Card();
Card(char r, char s);
int getValue();
void showCard();
private:
char rank;
char suit;
};
#endif
Card.cpp
#include "Card.h"
#include <iostream>
Card::Card() {}
Card::Card(char r, char s) {
rank = r;
suit = s;
}
int Card::getValue() {
// Implement the logic to assign values to each rank of the card
// and return the corresponding value
return 0;
}
void Card::showCard() {
// Display the rank and suit of the card
std::cout << rank << suit;
}
Deck.h
#ifndef DECK_H
#define DECK_H
#include "Card.h"
class Deck {
public:
Deck();
void refreshDeck();
Card Deal();
void shuffle();
int cardsLeft();
void showDeck();
private:
Card cards[52];
int numCards;
};
#endif
Deck.cpp
#include "Deck.h"
#include <iostream>
#include <cstdlib>
#include <ctime>
Deck::Deck() {
numCards = 52;
refreshDeck();
}
void Deck::refreshDeck() {
char ranks[] = {'A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K'};
char suits[] = {'H', 'D', 'C', 'S'};
int index = 0;
for (int suit = 0; suit < 4; suit++) {
for (int rank = 0; rank < 13; rank++) {
cards[index] = Card(ranks[rank], suits[suit]);
index++;
}
}
}
Card Deck::Deal() {
if (numCards > 0) {
numCards--;
return cards[numCards];
}
return Card();
}
void Deck::shuffle() {
std::srand(static_cast<unsigned int>(std::time(0)));
for (int i = numCards - 1; i > 0; i--) {
int j = std::rand() % (i + 1);
std::swap(cards[i], cards[j]);
}
}
int Deck::cardsLeft() {
return numCards;
}
void Deck::showDeck() {
for (int i = 0; i < numCards; i++) {
cards[i].showCard();
std::cout << " ";
}
std::cout << std::endl;
}
UML Class Diagrams: A class diagram for each class with appropriate symbols for composition/aggregation and inheritance.
Step by stepSolved in 3 steps
- C++main.cc file #include <iostream>#include <map>#include <vector> #include "bank.h" int main() { // =================== YOUR CODE HERE =================== // 1. Create a Bank object, name it anything you'd like :) // ======================================================= // =================== YOUR CODE HERE =================== // 2. Create 3 new accounts in your bank. // * The 1st account should belong to "Tuffy", with // a balance of 121ドル.00 // * The 2nd account should belong to "Frank", with // a balance of 1234ドル.56 // * The 3nd account should belong to "Oreo", with // a balance of 140ドル.12 // ======================================================= // =================== YOUR CODE HERE =================== // 3. Deactivate Tuffy's account. // ======================================================= // =================== YOUR CODE HERE =================== // 4. Call DisplayBalances to print out all *active* // account...arrow_forward#include <iostream> #include <iomanip> double double showMenu(); double takePurchase(double); double takePayment(); double takePayment(); void displayInfo(double, double); double showMenu() {} double takePayment() { double takePurchase() { } double takePurchase (double) { } double takePurchase(double price) { } double takePayment() {} displayInfo (double purchase, double payment) void displayInfo (double purchase, double payment){} int quantity; return (price * quantity);arrow_forwardc++ data structurearrow_forward
- Write a function getNeighbors which will accept an integer array, size of the array and an index as parameters. This function will return a new array of size 2 which stores the neighbors of the value at index in the original array. If this function would result in returning garbage values the new array should be set to values {0,0} instead of values from the array.arrow_forwardmain.cc file #include <iostream>#include <memory> #include "customer.h" int main() { // Creates a line of customers with Adele at the front. // LinkedList diagram: // Adele -> Kehlani -> Giveon -> Drake -> Ruel std::shared_ptr<Customer> ruel = std::make_shared<Customer>("Ruel", 5, nullptr); std::shared_ptr<Customer> drake = std::make_shared<Customer>("Drake", 8, ruel); std::shared_ptr<Customer> giveon = std::make_shared<Customer>("Giveon", 2, drake); std::shared_ptr<Customer> kehlani = std::make_shared<Customer>("Kehlani", 15, giveon); std::shared_ptr<Customer> adele = std::make_shared<Customer>("Adele", 4, kehlani); std::cout << "Total customers waiting: "; // =================== YOUR CODE HERE =================== // 1. Print out the total number of customers waiting // in line by invoking TotalCustomersInLine. //...arrow_forwardDice_Game.cpp #include <iostream>#include "Die.h" using namespace std; // a struct for game variablesstruct GameState { int turn = 1; int score = 0; int score_this_turn = 0; bool turn_over = false; bool game_over = false; Die die;}; // declare functionsvoid display_rules();void play_game(GameState&);void take_turn(GameState&);void roll_die(GameState&);void hold_turn(GameState&); int main() { display_rules(); GameState game; play_game(game);} // define functionsvoid display_rules() { cout << "Dice Game Rules:\n" << "\n" << "* See how many turns it takes you to get to 20.\n" << "* Turn ends when you hold or roll a 1.\n" << "* If you roll a 1, you lose all points for the turn.\n" << "* If you hold, you save all points for the turn.\n\n";} void play_game(GameState& game) { while (!game.game_over) { take_turn(game); } cout << "Game...arrow_forward
- struct gameType { string title; int numPlayers; bool online; }; gameType Awesome[50]; Write the C++ statement that sets the first [0] title of Awesome to Best.arrow_forwardMain.cpp #include <iostream>#include "Deck.h" int main() { Deck deck; deck.shuffle(); std::cout << "WAR Card Game\n\n"; std::cout << "Dealing cards...\n\n"; Card player1Card = deck.Deal(); Card player2Card = deck.Deal(); std::cout << "Player 1's card: "; player1Card.showCard(); std::cout << std::endl; std::cout << "Player 2's card: "; player2Card.showCard(); std::cout << std::endl; int player1Value = player1Card.getValue(); int player2Value = player2Card.getValue(); if (player1Value > player2Value) { std::cout << "Player 1 wins!" << std::endl; } else if (player1Value < player2Value) { std::cout << "Player 2 wins!" << std::endl; } else { std::cout << "It's a tie!" << std::endl; } return 0;} Card.h #ifndef CARD_H#define CARD_H class Card {public: Card(); Card(char r, char s); int getValue(); void showCard();...arrow_forward>> IN C PROGRAMMING LANGUAGE ONLY << COPY OF DEFAULT CODE, ADD SOLUTION INTO CODE IN C #include <stdio.h>#include <stdlib.h>#include <string.h> #include "GVDie.h" int RollSpecificNumber(GVDie die, int num, int goal) {/* Type your code here. */} int main() {GVDie die = InitGVDie(); // Create a GVDie variabledie = SetSeed(15, die); // Set the GVDie variable with seed value 15int num;int goal;int rolls; scanf("%d", &num);scanf("%d", &goal);rolls = RollSpecificNumber(die, num, goal); // Should return the number of rolls to reach total.printf("It took %d rolls to get a \"%d\" %d times.\n", rolls, num, goal); return 0;}arrow_forward
- C++ complete magic Square #include <iostream> using namespace std; /*int f( int x, int y, int* p, int* q ){if ( y == 0 ){p = 0, q = 0;return 404; // status: Error 404}*p = x * y; // product*q = x / y; // quotient return 200; // status: OK 200} int main(){int p, q;int status = f(10, 2, &p, &q);if ( status == 404 ){cout << "[ERR] / by zero!" << endl;return 0;}cout << p << endl;cout << q << endl; return 0;}*/ /*struct F_Return{int p;int q;int status;}; F_Return f( int x, int y ){F_Return r;if ( y == 0 ){r.p = 0, r.q = 0;r.status = 404;return r;}r.p = x * y;r.q = x / y;r.status = 200;return r;} int main(){F_Return r = f(10, 0);if ( r.status == 404 ){cout << "[ERR] / by zero" << endl;return 0;}cout << r.p << endl;cout << r.q << endl;return 0;}*/ int sumByRow(int *m, int nrow, int ncol, int row){ int total = 0;for ( int j = 0; j < ncol; j++ ){total += m[row * ncol + j]; //m[row][j];}return total; } /*...arrow_forward#include <iostream> #include <string> using namespace std; int main() { // Declare and initialize variables. string employeeFirstName; string employeeLastName; double employeeSalary; int employeeRating; double employeeBonus; const double BONUS_1 = .25; const double BONUS_2 = .15; const double BONUS_3 = .10; const double NO_BONUS = 0.00; const int RATING_1 = 1; const int RATING_2 = 2; const int RATING_3 = 3; // This is the work done in the housekeeping() function // Get user input cout << "Enter employee's first name: "; cin >> employeeFirstName; cout << "Enter employee's last name: "; cin >> employeeLastName; cout << "Enter employee's yearly salary: "; cin >> employeeSalary; cout << "Enter employee's performance rating: "; cin >> employeeRating; // This is the work done in the detailLoop() function // Use switch statement to...arrow_forwardOpengl Help Programming Language: c++ I need help setting coordinate boundries for this program so the shape can't leave the Opengl window. The shape needs to stay visiable.arrow_forward
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education